1. Kayako Download customers: we will continue to develop and support Kayako Download beyond July 2017, alongside the new Kayako for existing customers.

    Find out more.

  2. The forum you are viewing relates to Kayako Classic. If you signed up or upgraded to the new Kayako (after the 4th July 2016), the information in this thread may not apply to you. You can visit the forums for the new Kayako here.

[Help] Adding email content to AutoResponder

Discussion in 'Developing, APIs and extending' started by Amitm, Mar 15, 2013.

  1. Amitm

    Amitm New Member

    Hi all,

    We would like to add the customer's email body/content to the AutoResponder (instead of just a simple thank you message).

    After reading the forum and also asking the live support, it seems that there's no resolution to this issue yet.
    We started looking in the php files in order to try and add this functionality ourselves but we could use the community help here.

    In file: class.SWIFT_TicketEmailParser.php the following code seems to call an Email Dispatch function:
    PHP:
    $_SWIFT_TicketObject->DispatchAutoresponder();
    In file: class.SWIFT_TicketEmailDispatch.php when looking at the end of function DispatchAutoresponder, there's the following line which seems to be sending the Auto Responder:
    PHP:
            $this->Dispatch(SWIFT_Ticket::MAIL_CLIENT$_htmlEmailContents$_textEmailContents$this->Ticket->GetMailFromName(),
                    
    $this->Ticket->RetrieveFromEmailWithSuffix($this->Ticket->GetMailFromEmail(), SWIFT_Ticket::MAIL_CLIENT), $_destinationEmailAddress''$_ccEmailList$_bccEmailList'''');
    Now here's what we tried to do:
    1. In class.SWIFT_TicketEmailParser.php we sent to DispatchAutoresponder() a parameter called $_myTicketContent. This parameter is declared as follows:
    PHP:
    $_myTicketContent $this->MailParserEmail->GetProperty('originalfinalcontent');



    2. In class.SWIFT_TicketEmailDispatch.php we changed the function DispatchAutoresponder() to allow it to have an extra parameter (as mentioned in point 1) and we set the parameter $_htmlEmailContents to be equal to $_myTicketContent.

    Unfortunately this does not seem to work. It looks like variable $_myTicketContent which we declared in class.SWIFT_TicketEmailParser.php equals to null instead of the ticket content.

    Can you please help us figure this one out?

    Thanks,
    Amit
     
  2. Gary McGrath

    Gary McGrath Staff Member

    Hi Amit,

    You were close, you were on the right track, this is the best way to do it.

    File: class.SWIFT_TicketEmailDispatch.php
    location: __apps\tickets\library\Ticket
    Near line: 379

    Change the function to accept a new variable:

    Code:
     
    public function DispatchAutoresponder($_overrideEmailAddress = '', $_ccEmailList = array(),$_lastpostcontents = '')
     
    
    Then look down and find the template calls:

    Code:
     
      $_textEmailContents = $this->Template->Get('email_ticketautorespondertext', SWIFT_TemplateEngine::TYPE_DB);
      $_htmlEmailContents = $this->Template->Get('email_ticketautoresponderhtml', SWIFT_TemplateEngine::TYPE_DB);
     
    
    Then just before those, add this:

    Code:
     
    $this->Template->Assign('_lastpostcontents', $_lastpostcontents);
     
    
    File: class.SWIFT_Ticket.php
    Location: __apps\tickets\models\Ticket
    near line 4696

    Find this code:

    Code:
     
      $_ccEmailList = $this->GetCCUserEmails();
      $this->Load->Library('Ticket:TicketEmailDispatch', array($this));
      $this->TicketEmailDispatch->DispatchAutoresponder('', $_ccEmailList);
     
    
    And change it to this:

    Code:
     
      $_ccEmailList = $this->GetCCUserEmails();
      $_SWIFT_TicketPostObject = new SWIFT_TicketPost(new SWIFT_DataID($this->GetProperty('lastpostid')));
      $this->Load->Library('Ticket:TicketEmailDispatch', array($this));
      $this->TicketEmailDispatch->DispatchAutoresponder('', $_ccEmailList,nl2br(htmlspecialchars($_SWIFT_TicketPostObject->GetProperty('contents'))));
    
    Now you can edit your email_ticketautoresponderhtml and email_ticketautorespondertext templates and use the line <{$_lastpostcontents}> where you want the contents of the email to be located.

    Gary
     
    Amitm likes this.
  3. Amitm

    Amitm New Member

    Hi Gary,

    Wow! Many thanks for the code you provided!
    I've implemented this, however I'm facing an issue regarding the content.
    The content is not formatted, i.e., it's a plain text instead of "html" style (for example: no breaklines / colors / bold / font ...)
    I've implemented this in the email_ticketautoresponderhtml temtplate.

    Any idea on how to improve the code so it will return the text in a "beautiful" way? :)
    I really appreciate your response.

    Thanks,
    Amit
     
  4. Gary McGrath

    Gary McGrath Staff Member

    Hi Amit,

    This bit here: $_SWIFT_TicketPostObject->GetProperty('contents') is what gets the contents. It sounds like this needs to be processed in some way to make it formatted.

    This should get it being slightly more readable:

    nl2br(htmlspecialchars($_SWIFT_TicketPostObject->GetProperty('contents')))

    The only issue might be that you need to treat text and html differently, so you might have to "process" it in the other file and assign one text version and one html version to the template instead.

    Gary
     
    Amitm likes this.
  5. Amitm

    Amitm New Member

    Gary, you rock!
    I can confirm it's working. many many thanks!

    Last question if you don't mind :) : Is it possible also to include the attachments in the Autoresponse ?

    I really appreciate your help on this matter.
    Amit
     
  6. Gary McGrath

    Gary McGrath Staff Member

    Hi Amit,

    That is certainly possible, but I would highly recommend against doing that. I can think of several issues it can cause, like for example if your client submits a 20mb email, you are going to send it right back to them, then they have to spend time downloading it, I can see that being quite frustrating

    Gary
     
  7. Amitm

    Amitm New Member

    Thanks Gary!
    Regarding the original question, when I tested the auto responder, I user gmail as my Kayako Email Parser.
    When I use outlook for the Kayako Email Parser (we assigned a mailbox in outlook instead of gmail for Kayako), the 'contents' in the autoresponder includes all the email headers.
    Please see example below:

    Code:
    <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
    <meta name="Generator" content="Microsoft Word 14 (filtered medium)">
     
    <style>
    p.MsoNormal, li.MsoNormal, div.MsoNormal { margin:0cm; margin-bottom:.0001pt; text-align:right; direction:rtl; unicode-bidi:embed; font-size:11.0pt; font-family:"Calibri","sans-serif"; }
    span.MsoHyperlink { mso-style-priority:99; color:blue; text-decoration:underline; }
    span.MsoHyperlinkFollowed { mso-style-priority:99; color:purple; text-decoration:underline; }
    span.EmailStyle17 { mso-style-type:personal-compose; font-family:"Calibri","sans-serif"; color:windowtext; }
    .MsoChpDefault { mso-style-type:export-only; font-family:"Calibri","sans-serif"; }
    @page WordSection1 { size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; }
    div.WordSection1 { page:WordSection1; }
     
    </style>
    <!--[if gte mso 9]><xml>
    <o:shapedefaults v:ext="edit" spidmax="1026" />
    </xml><![endif]--><!--[if gte mso 9]><xml>
    <o:shapelayout v:ext="edit">
    <o:idmap v:ext="edit" data="1" />
    </o:shapelayout></xml><![endif]-->
    </head>
    <body lang="EN-US" link="blue" vlink="purple">
    <div class="WordSection1">
    <p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">Hello,<o:p></o:p></p>
    
    Do you have any insight on how to make it work again? :)

    Thanks for all your time and effort!

    Amit
     
  8. bartek Dirycz

    bartek Dirycz Member

    I tried adding the code, but now I get the following errors when creating a ticket
    Notice
    Undefined index: _lastpostcontents (C:/xampp/htdocs/Support/__swift/cache/25f181ff21fbd80f8f2869956fed8e55.php:24)
    Notice
    Undefined index: _lastpostcontents (C:/xampp/htdocs/Support/__swift/cache/25f181ff21fbd80f8f2869956fed8e55.php:24)
    =================================================================================================================================

    Warning
    Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Support\__swift\library\Exception\class.SWIFT_Exception.php:382) (C:/xampp/htdocs/Support/__apps/tickets/client/class.Controller_Submit.php:482)

    Warning
    Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Support\__swift\library\Exception\class.SWIFT_Exception.php:382) (C:/xampp/htdocs/Support/__apps/tickets/client/class.Controller_Submit.php:482)
    =================================================================================================================================



    Any ideas?
     
  9. Gary McGrath

    Gary McGrath Staff Member

    Hi there,

    That error to me would suggest that you have not edited all the code correctly, did you make sure to edit the function name and add in the new variable to be accepted ( as the error you are getting would suggest that's what is missing )

    Gary
     
  10. bartek Dirycz

    bartek Dirycz Member

    You were right. i went through them again, and instead of the part where you wrote "Then just before those, add this:" I added it after. :)

    Thanks for your help Gary
     
  11. Gary McGrath

    Gary McGrath Staff Member

    Your welcome :)

    Gary
     
  12. Priyanka Trivedi

    Priyanka Trivedi Established Member

    hello AmitM,

    I have tried to do the same thing, but it is not reflecting in autoresponder.
    Moreover if i am removing anything from templates.xml , its still sending me proper responder.
    Could you plz tell me how u implemented the template?
    Please reply as soon as possible.

    Best Regards
    Priyanka
     
  13. Priyanka Trivedi

    Priyanka Trivedi Established Member

    And i am implementing this for the first time autoresponder tha comes when the ticket is parsed.

    Thanks
     
  14. Gary McGrath

    Gary McGrath Staff Member

    Hi there,

    What are you editing within templates.xml? none of the code above listed that?

    You are meant to goto the admin CP, templates section, then open the email_ticketautoresponderhtml template, and add the line <{$_lastpostcontents}> somewhere within it

    Gary
     
  15. Priyanka Trivedi

    Priyanka Trivedi Established Member

    Thanks Gary.
    I tried but i guess there is no data coming in lastpostid.
    And as it is autoresponder, i am not able to print the values of variables.
    Could you plz suggest something?

    Best Regards
    Priyanka
     
  16. Priyanka Trivedi

    Priyanka Trivedi Established Member

    Hey Gary,

    I am attaching snags of code i have implemented.
    Please check and let me know , what might be the issue.
    Thanks alot.

    Best Regards
    Priyanka
     

    Attached Files:

  17. Gary McGrath

    Gary McGrath Staff Member

    Hi there,

    In your SWIFT_Ticket, you have not added one of the lines ( its edited rather than all new )

    $this->TicketEmailDispatch->DispatchAutoresponder('', $_ccEmailList,nl2br(htmlspecialchars($_SWIFT_TicketPostObject->GetProperty('contents'))));
    Gary
     
  18. Priyanka Trivedi

    Priyanka Trivedi Established Member

    Thanks alot Gary.
    It worked.
    :)

    Regards
    Priyanka
     
  19. Priyanka Trivedi

    Priyanka Trivedi Established Member

    Hello Gary,

    I want to apply similar kind of thing for staff reply too.
    In AdminCP , the option to attach history is off.
    As i don't want to attach the whole mail chain for clients.
    But i want to check it for internal mails and attach the history in the body.
    I have tried implementing it but not getting results.
    Please help.

    Best Regards
    Priyanka
     
  20. Priyanka Trivedi

    Priyanka Trivedi Established Member

    Hello All,

    I have made following changes.
    And in template.xml, again there is check for t_enhistory
    Now should pass my values to this file , to attach the email historywith the staff reply.
    Please help.
    Thank you.

    Best Regards
    PRiyanka
     

    Attached Files:

Share This Page