Sunteți pe pagina 1din 7

vtiger CRM Auto Ticketing with MailScanner

Your INBOX Mails

Test Trouble Ticket 1 TT15 [Ticket Id : 1483] Test Trouble Ticket RE: TT15 [Ticket
Test Trouble Ticket
1 TT15 [Ticket Id : 1483] Test Trouble Ticket
RE: TT15 [Ticket Id : 1483] Test Trouble Ticket
Reply with Ticket Id
Mail Scanner 4
Mail Scanner
4
Test Trouble Ticket Reply with Ticket Id Mail Scanner 4 Any Condition Create Ticket Regex Ticket

Any Condition

Create Ticket

Any Condition Create Ticket
Any Condition Create Ticket
Ticket Id Mail Scanner 4 Any Condition Create Ticket Regex Ticket Id : ([0-9]+) All Condition

Regex Ticket Id : ([0-9]+) All Condition Update Ticket

Regex Ticket Id : ([0-9]+) All Condition Update Ticket
Regex Ticket Id : ([0-9]+) All Condition Update Ticket Update ticket with id 1483 Captured by
Regex Ticket Id : ([0-9]+) All Condition Update Ticket Update ticket with id 1483 Captured by
Regex Ticket Id : ([0-9]+) All Condition Update Ticket Update ticket with id 1483 Captured by
Regex Ticket Id : ([0-9]+) All Condition Update Ticket Update ticket with id 1483 Captured by
Regex Ticket Id : ([0-9]+) All Condition Update Ticket Update ticket with id 1483 Captured by
Update ticket with id 1483 Captured by Regex group ([0-9]+)

Update ticket with id 1483 Captured by Regex group ([0-9]+)

Regex Ticket Id : ([0-9]+) All Condition Update Ticket Update ticket with id 1483 Captured by
3
3
ticket with id 1483 Captured by Regex group ([0-9]+) 3 Comment From vtiger CRM Trouble Tickets
Comment From vtiger CRM Trouble Tickets Create Ticket Ticket Owner
Comment From
vtiger CRM Trouble Tickets
Create Ticket
Ticket Owner

HelpDeskHandler

2
2

The above picture depicts the basic process involved in automating ticketing with MailScanner.

Let us consider support@company.com is the mailbox that needs to scanned.

Step 1:

Customer (having a Contact/Account record) sends email to support@company.com, with subject “Test Trouble Ticket”

Step 2:

Mail Scanner creates ticket, links it to matching contact/account record filtered by emailid lookup.

HelpDeskHandler will send a acknowledgment email with more information on how to respond further to Customer. The email subject looks like “TT15 [Ticket Id: 1483] Test Trouble Ticket”

Step 3:

Customer replies to the acknowledgment email keeping part of the subject intact to support@company.com. As mail scanner is configured with Regex rule on subject and finds a matching Trouble Ticket linked to Customer, it updates the comments with the email body.

Step 4:

When support team update their comment, an email is sent to Customer again.

Table of Contents

MailScanner Setup

3

MailScanner Folder Selection

3

MailScanner Rules Setup

3

Changes In config.inc.php

4

Automating Acknowledgment Email

4

Create Email Template

6

Register HelpDeskHandler as Event Handler:

6

Appendix – I

6

Update Ticket Bug Fix

6

FAQ

7

Further references:

7

MailScanner Setup

Configure MailScanner with credentials of support@company.com IMAP server and enable it for scanning.

MailScanner Folder Selection

Select the folders to be looked up during the process of scanning.

This is required to eliminate IMAP folders like SPAM, Thrash, Sent Items etc

MailScanner Rules Setup

Following rules should be created in order for auto-ticketing purpose.

Subject

Regex

Ticket Id[^:]?: ([0-9]+)

All Condition

Update Ticket

     

Any Condition

Create Ticket

The order (or priority) of the rules also is important, please refer to the screenshot below:

Create Ticket The order (or priority) of the rules also is important, please refer to the

Changes In config.inc.php

You will need to update the following variables in your config.inc.php

$HELPDESK_SUPPORT_EMAIL_ID

FROM address information to be used when sending mails Example: automated-reply@company.com

$HELPDESK_SUPPORT_NAME

FROM name to be used for purpose of display for emails sentout. Example: Automated Reply

$HELPDESK_SUPPORT_EMAIL_REPLY_ID

REPLY-TO address to be set in the email sent. Example: support@company.com

Setting this information is one of the important step for auto- ticketing. When user tries to Reply for the automated emails the TO address will be set by the mail-client and reaches the MailBox for which we have setup the scanning.

Automating Acknowledgment Email

To complete the auto-ticketing process, an acknowledgment email needs to be sent to the user after the ticket is created as part of mail scanning.

This mail could also contain directions for the user on he/she can respond for updating the comments on the ticket. Generally, you will need to request for specific subject format for which Update Ticket Rule is configured in the MailScanner.

To achieve this, we are going to take advantage of Eventing Framework that is part of vtiger CRM

5.1.0

File: modules/HelpDesk/HelpDeskHandler.php

<?php

/*+*******************************************************************************

* The contents of this file are subject to the vtiger CRM Public License Version 1.0

* ("License"); You may not use this file except in compliance with the License

* The Original Code is: vtiger CRM Open Source

* The Initial Developer of the Original Code is vtiger.

* Portions created by vtiger are Copyright (C) vtiger.

* All Rights Reserved. ********************************************************************************/

class HelpDeskHandler extends VTEventHandler {

function

getSendToEmail($crmid) {

if(empty($crmid)) return false;

$sendtoemail = false;

global $adb;

$metaresult = $adb->pquery("SELECT setype FROM vtiger_crmentity WHERE crmid=? AND deleted = 0", array($crmid));

if($metaresult && $adb->num_rows($metaresult)) {

$metaresultrow = $adb->fetch_array($metaresult);

$emailres = false;

if($metaresultrow['setype'] == 'Contacts') {

$emailres = $adb->pquery("SELECT email,yahooid FROM vtiger_contactdetails WHERE contactid = ?", array($crmid));

} else if($metaresultrow['setype'] == 'Accounts') {

$emailres = $adb->pquery("SELECT email1,email2 FROM vtiger_account WHERE accountid = ?", array($crmid));

}

if($emailres && $adb->num_rows($emailres)) {

$emailresrow = $adb->fetch_array($emailres);

if(!empty($emailresrow[0])) $sendtoemail = $emailresrow[0]; if(!empty($emailresrow[1])) $sendtoemail = $emailresrow[1];

}

}

return $sendtoemail;

}

function handleEvent($eventName, $entityData) { global $log, $adb;

if($eventName == 'vtiger.entity.aftersave') {

$moduleName = $entityData->getModuleName();

// Event not related to HelpDesk - IGNORE if($moduleName != 'HelpDesk') { return;

}

// Take action if the service running is MailScanner (either via Cron/Scan Now) if(isset($_REQUEST) && $_REQUEST['service'] == 'MailScanner' ) {

$focus = $entityData->focus;

$sendToEmail = $this-> getSendToEmail($focus->column_fields['parent_id']);

// If the entity is create new and we know whom to send the mail proceed. if($entityData->isNew() && $sendToEmail) {

global $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_REPLY_ID;

include_once 'vtlib/Vtiger/Mailer.php'; $mailer = new Vtiger_Mailer(); $mailer->ConfigSenderInfo($HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME); $mailer->AddReplyTo($HELPDESK_SUPPORT_EMAIL_REPLY_ID);

$mailer->initFromTemplate('

// Update the email subject $mailer->Subject = sprintf("%s [ Ticket Id : %s ] Re : %s", $focus->column_fields['ticket_no'],

Auto Ticket First Response Template

');

$focus->id,

$focus->column_fields['ticket_title']

);

$mailer->SendTo( $sendToEmail, '', false, false, true );

}

?>

}

}

}

}

Create Email Template

As highlighted above, HelpDeskHandler is initializing the email contents from the Email Template named ( Auto Ticket First Response Template ). This allows greater flexibility in changing the contents of initial response and formatting it.

Please make sure to create under Settings » Email Templates

Register HelpDeskHandler as Event Handler:

You will need to execute the following script to register HelpDeskHandler

<?php $Vtiger_Utils_Log = true;

include_once 'vtlib/Vtiger/Module.php'; include_once 'vtlib/Vtiger/Event.php';

$moduleInstance = Vtiger_Module::getInstance('HelpDesk'); Vtiger_Event::register( $moduleInstance, 'vtiger.entity.aftersave', 'HelpDeskHandler', 'modules/HelpDesk/HelpDeskHandler.php'

);

?>

Appendix – I

Update Ticket Bug Fix

For vtiger CRM 5.1.0 you will need to add the fix suggested at http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/6391

FAQ

Automated email is not sent but Ticket is getting created.

Check if you have registered HelpDeskHandler

Verify if the Ticket created has been related to existing Contact/Account.

This happens based on the FROM email address look-up against existing Contact/Account when creating the email during scanning.

New tickets is getting created instead of updating!

Check if you applied the update ticket bug fix

Verify if the email is being sent from customer which matches the Linked Contact/Account email of the ticket.

Further references: