Customer Support via SMS with Zendesk

ZendeskA few weeks ago, I was given a challenge:

Replace email with SMS for customer support using Zendesk.

If you’re not familiar with Zendesk, it’s a flexible helpdesk system that allows customers to send email and create a ticket. The support people can respond to the customer and apply workflows. And the whole thing is documented and logged so everyone can see what happened when.

Since I know the Twilio API, the only challenge was the Zendesk side of things. I was pleasantly surprised to find that it was also simple and easy to use, especially with the Zendesk PHP Library. The resulting code with the full instructions is available on Github but these are the key aspects:

Once you have a Zendesk account and create the field for the phone number, simply set your credentials here. (The steps to create the field are in the readme file.)

[php]
define("ZD_SITE", ‘yourzendesksite’);
define("ZD_USER", ‘youruser@test.com’);
define("ZD_PASS", ‘yourpassword’);
define("ZD_FIELD",’fieldid’);
define("PLACEHOLDEREMAIL", ZD_USER);
[/php]

Within Twilio, we set the SMS URL for one of our phone numbers to the URL where our inbound.php lives. Then we can use the incoming From phone number to look up any active tickets from this user.

[php]
$result = $zd->get(ZENDESK_SEARCH, array(
‘query’ => "query=type:ticket+status:new+status:open+" .
"status:pending+order_by:updated_at+sort:desc+" .
"ticket_field_".ZD_FIELD.":$from"
)
);
$xml = simplexml_load_string($result);
$attr = $xml->attributes();
[/php]

Next, if we don’t have an Open ticket from that phone number, we create one using the SMS Body as the body of the ticket and the From in a special field we’ve created.

[php]
$result = $zd->create(ZENDESK_TICKETS, array(
‘details’ => array(
‘description’ => $body,
‘subject’ => substr($body, 0, 80),
‘requester_email’ => PLACEHOLDEREMAIL,
‘ticket-field-entries’ => array (
array(
‘ticket-field-id’ => ZD_FIELD,
‘value’ => $from
)
))));
[/php]

If we do have an existing Open from that phone number, we simply append the new message to the ticket using the nice-id. This keeps the support thread complete.

[php]
$ticket_id = $xml->xpath(‘/records/record/nice-id’);
$ticket_id = (string) $ticket_id[0][0];
$result = $zd->update(ZENDESK_TICKETS, array(
‘details’ => array(
‘is-public’ => true,
‘value’ => $body
),
‘id’ => $ticket_id,
));
[/php]

That wraps the inbound (SMS to support) side of the process, but we still have to configure the outbound (support to SMS) processing. Within Zendesk, we have to configure what is called a Target and a Trigger:

To create the Target, visit Settings->Extensions->Targets and click “add target”:

  1. Give the Target a useful name such as “Twilio Notification”;
  2. Use your Twilio Account SID & Phone Number with your Zendesk Custom field ID to fill in the AC1234, NNNN, and CCCC fields respectively in this URL: https://api.twilio.com/2010-04-01/Accounts/AC1234/SMS/Messages?From=+NNNN&To={{ticket.ticket_field_CCCC}}&Body={{ticket.latest_public_comment}}
  3. Enter the completed URL in the URL box;
  4. Enter your Account SID and Auth Token in the Username and Password fields;
  5. Click save;

To create the Trigger, visit Manage->Triggers & mail notifications and click “add trigger”:

  1. Edit “Notify requestor of comment update”;
  2. Change the “Perform these actions” dropdown to the Target name specified above.

Voila. Simple SMS-based customer support.

Whenever someone sends an SMS to your Twilio number, a new ticket will be created. Your customer service team can respond as needed (remember, there’s still a 160 character limit!) which is delivered to the person via SMS. Then they can respond and the support thread stays connected throughout. The best part is that the customer service team doesn’t have to do anything differently.

Two ideas for improvement:

  1. First, I would like the Target/Trigger configuration steps easier. A programmatic process that could run as an initialization step would be useful but their API doesn’t support it.
  2. Second, this should use the From to look up the customer information from a CRM to create a complete record. It could be a useful option to send a final recap to their email.

You can download the full code from Github.