Integrating Zendesk into Qiscus

Qiscus Multichannel Platform can be easily extended. One way that can be used is to use Webhooks. There are several Webhooks that can be used on the Qiscus platform, namely:

  • Bot
  • Custom Agent Allocation
  • Custom Button
  • Mark as Resolve

In this article we will use `Custom Button Webhook` to integrate Zendesk on Qiscus. This webhook helps you to get information about a room chat into your third party systems, such as CRM, Ticketing, Analytics, and many more. This webhook is triggered when admin or supervisor or agent clicks custom button. Here's the sample response for this webhook.

{
"additional_info": [
{
"anykey": "any value"
}
],
"agent": {
"email": "qixxxxti@gmail.com",
"name": "Agent",
"type": "admin"
},
"channel_id": 0004,
"channel_name": "Channel 1",
"channel_type": "Qiscus Widget",
"customer": {
"avatar": "https://dxxx/xxxxxx-xxlient.png",
"name": "Customer Name",
"user_id": "email_customer@gmail.com"
},
"customer_properties": [
{
"id": 1,
"label": "WEBSITE",
"value": ""
},
{
"id": 2,
"label": "ADDRESS",
"value": ""
},
{
"id": 3,
"label": "COMPANY",
"value": ""
}
],
"notes": null,
"room_id": 0000002,
"tag": []
}

To integrate Zendesk into Qiscus we need to follow this steps:

  1. Setup Custom Button Webhook
  2. Setup Development Environment
  3. Install Zendesk PHP Library
  4. Create New Ticket to Zendesk Code

Setup Custom Button Webhook

To setup the custom button webhook you can refer to this document.

Setup Development Environment

We will use PHP for this article, and to help us test our webhook easier, we'll use 3rd party service called Ultrahook. So, we can later setup the webhook URL to our Ultrahook namespace. To setup ultrahook you can refer to this page.

Install Zendesk PHP Library

To receive the webhook we'll need the help of Zendesk PHP Library which you can get here. Basically we'll install this library using composer by running `composer require zendesk/zendesk_api_client_php`.

After the library has been installed, we need to configure the library so we can work with it.

// load Composerrequire 'vendor/autoload.php';use ZendeskAPIHttpClient as ZendeskAPI;$subdomain = "subdomain";$username  = "email@example.com"; // replace this with your registered email$token     = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your token$client = new ZendeskAPI($subdomain);$client->setAuth('basic', ['username' => $username, 'token' => $token]);

You'll need your Zendesk token which you can get from Admin Center as shown in the screenshot below.

mceclip3.png

Create New Ticket to Zendesk Code

Let's create a new PHP file, we're going to name it `index.php`.

We'll activate the ultrahook service to test our webhook by using `ultrahook -k <your key> zendesk 5000` it will start your server at http://localhost:5000 and can be accessed by `namespace-subdomain.ultrahook.com`. Don't forget to activate your localhost:5000. 

Your index.php file should be like this more or less.

<?php// load Composerrequire 'vendor/autoload.php';use ZendeskAPIHttpClient as ZendeskAPI;$subdomain = "xxxxx";$username  = "xxx@xxxxxxxx.com"; // replace this with your registered email$token     = "xxxxxxxxxxxxxxxxxxx"; // replace this with your token// $client = new ZendeskAPI($subdomain);// $client->setAuth('basic', ['username' => $username, 'token' => $token]);if ($_SERVER['REQUEST_METHOD'] == 'POST') {    // fetch RAW input    $json = file_get_contents('php://input');    // decode json    $object = json_decode($json);    // expecting valid json    if (json_last_error() !== JSON_ERROR_NONE) {        die(header('HTTP/1.0 415 Unsupported Media Type'));    }    /**     * Do something with object, structure will be like:     * $object->accountId     * $object->details->items[0]['contactName']     */    try {        // get data first        $data = array_reduce($object->additional_info, function ($result, $item) {            $result->{$item->key} = $item->value;            return $result;        }, new stdClass());        // die(file_put_contents('log.txt', print_r($data, true)));        // Create a new ticket        $newTicket = $client->tickets()->create([            'type' => $data->ticket_type ? $data->ticket_type : 'problem',            'tags'  => array('demo', 'testing', 'api', 'zendesk'),            'subject'  => $data->subject,            'comment'  => array(                'body' => $data->body            ),            'requester' => array(                'locale_id' => '1',                'name' => $data->nama,                'email' => $data->email,            ),            'priority' => $data->priority ? $data->priority : 'normal',        ]);     } catch (ZendeskAPIExceptionsApiResponseException $e) { 
echo $e->getMessage().'';
}
// dump to file so you can see
// file_put_contents('log.txt', print_r($object, true)); }

Need further assistance?

Our helpful customer support team is available to help you with any inquiries you may have

Contact Us