Page 1 of 1

Populating fields from piped emails

Posted: Sat Aug 27, 2022 5:06 am
by modifried
Script URL: https://academade.com/hesk/
Version of script: 3.3.0
Hosting company: WHC
URL of phpinfo.php: https://academade.com/hesk/phpinfo.php
URL of session_test.php: https://academade.com/hesk/session_test.php
What terms did you try when SEARCHING for a solution: email splitting, piping, staff-only fields, populating ticket email

Write your message below:

I am wondering if there is any way to populate the different fields of the ticket, such as the ticket category and staff-only fields from a piped email. I have email piping configured and working, but there is not much documentation. I am sure that with time I could figure out how to implement this myself, and I will be working on this, however if there is an easier way or something already built in but not documented, it would be great to know. Thanks for any help that anybody can provide.

Re: Populating fields from piped emails

Posted: Sat Aug 27, 2022 8:31 am
by Klemen
There is no built-in way to do that because there is no standard way of how email messages are structured.

You will need to create this for your specific message structure, and for example use regular expressions to get the correct data from the message.

Re: Populating fields from piped emails

Posted: Sat Aug 27, 2022 4:49 pm
by modifried
Alright sounds good! I am sending my data as a stringified JSON so this should be easy.

EDIT: I have made the changes necessary. I will be expanding this more in the future but for now this does the job perfectly for splitting a plaintext or HTML email containing basic stringified JSON. If anybody else is ever interested in doing this it's pretty easy. I inserted this at line 105 of pipe_functions.inc.php

$tmpvar['message'] = hesk_stripQuotedText($tmpvar['message']); //existing line 103
...
$plain_message = preg_replace('/\s+/', ' ', trim(html_entity_decode($tmpvar['message'])));
$message_array = json_decode($plain_message);

if ( $message_array != null ) {
$tmpvar['message'] = $message_array->message;
$custom_message = $message_array->custom;
} else {
$custom_message = "No JSON data provided";
}

And added this below the foreach loop for custom fields (around line 375 once the other bit is added):

$tmpvar['custom1'] = $custom_message;

Works like a charm. Thanks for your help!