top of page

Mail interface to small external service providers 2

automator-logo

Prerequisites if you like to try it:

  1. You already have an ITPR demo account. If not, you can easily request one with demo data.

  2. You already signed up for a techwork automator demo account. If not, goto the registration blog post.

Business case:

Please find the full description of the business case in blog post “Mail interface to small external provider 1“.

In this post we provide an automator package to read the mail the service provider sends back and stores the information in the note field. What needs to be done?

Minimal requirements:

  1. We need to look for the ITRP Request Number in the subject (Request # …)

  2. We need to fetch the request in ITRP

  3. If the request is there we need to look for custom data to apply the internal Service Instance, Team and Member, so that the request is back in the correct inbox.


log('******* Mail back from the external provider ********')

$subjectMatch = mail.subject~'Request #(\\d+)';
$itrpRequestNr = $subjectMatch[1];

if ($itrpRequestNr) {
  $request = fetch('requests', $itrpRequestNr);

  if ($request) {
    $teamID = $request.custom_data.wdc_team_id ? $request.custom_data.wdc_team_id : $WDC_Default_Team;
    $memberId = $request.custom_data.wdc_member_id ? $request.custom_data.wdc_member_id : '';
		$serviceInstanceID = $request.custom_data.wdc_si_id ? $request.custom_data.wdc_si_id : '';
    
    $bodyMatch = mail.text~'([^]*)Your original request description:';
    $providerText = $bodyMatch ? $bodyMatch[1] : mail.text;

    $date = date();
    $m = moment($date);
    $tz = $m.tz("Europe/Vienna");
    $tzDate = $tz.format("DD.MM.YYYY, HH:mm");

    update('requests', $itrpRequestNr, {
      team_id: $teamID,
      member_id: $memberId,
      service_instance_id: $serviceInstanceID,
      status: 'assigned',
      note: '```' + $tzDate + ' -- Email back from external provider```:\n\n' + $providerText;
    });
  }
}

log('******* Mail back from the external provider END ********')


What it does in human language:

Line 3 and 4: Looks into the subject line of the Email for “Request #” and stores all numbers (digits) after the # in variable “$itrpRequestNr”.

Line 6 and 7: If there is a number stored in $itrpRequestNr then it fetches the request into variable “$request”.

Line 9 to 12: If there is a request stored in “$request” we look in the custom data field for the team id, member id and service instance id and store them into variables.

Line 14 and 15: In the mail body everything above “Your original request description:” is stored in variable “$providerText”. The assumption is that the provider sends the original description at the end of the email. If the line can not be found the whole body content is stored in variable “$providerText”.

Line 17 to 22: Like I described in the last post is to get a valid timestamp for the note. Therefore it will be easy to read when the email came in from the external provider.

Line 24 to 30: It just updates the request with all the data mentioned.

Wrap up

This post and the last post explain how to build a cheap email based interface between ITRP and another Service Management tool. The whole interface takes 2 hours to set up in a live environment.

k.konwalin@techwork.at

Share this:

  1. Twitter

  2. Facebook

8 views0 comments

Recent Posts

See All
bottom of page