Webhooks can be used to get notified about events happening in other applications inside Cliq. All bots in Cliq have their own incoming webhook endpoint. This makes it simple to post messages to the bot from external applications. Unlike the
send message (/message) REST API, here any data can be posted to the endpoint which is further processed in the incoming handler before notifying in Cliq.
The incoming webhook allows third-party applications to send notifications/alerts using the incoming webhook URL. These responses mostly received as a JSON can be then customized using Cliq's message card templates. The incoming webhook URL of the bot should be configured with the application's outgoing webhook.
Incoming webhook handler workflow
The bot's incoming webhook URL will receive the request response from the third party application's URL. The response of the request will be obtained in the body attribute. Take a look at all the attributes passed when a bot's incoming webhook handler is executed in our
help page .
A pictorial comparison between how Rest APIs and incoming webhooks work is shown below!
Now that we've got the concept of webhooks cleared, let's start off by creating a simple bot's webhook handler. Take a look at the sample scenario given below.
Sample Scenario
Your support team uses Zendesk to take care of customer queries and keep track of tickets. The team also uses Cliq for internal team communication. So how can you make sure all support reps are notified in Cliq when a new ticket with a high priority has been created? Here's what you can do - create a Support Bot!
Before we start, this is an integration by parts. Which means that you have to configure the webhook in Zendesk and format your response in Cliq.
Cliq's part in the integration:
Creating a bot in Cliq is just a three-step process. All you've to do is,
- Click ' Settings ' in Cliq's top nav bar.
- Select ' Integrations '.
- Once you're on the Integrations page, click ' Create Bot ' and give your bot a name, description, status, access level and image!
Now, to set up the incoming webhook handler of your bot :
- Saving the bot will take you to the ' Edit Handlers ' page. Or you can navigate to the edit handlers page from the bot's preview.
- Click ' Edit Code ' under the bot incoming webhook handler.
- Write your code in the deluge editor (once you set up the JSON body in Zendesk), click save and done! Take a look at the sample code snippet given below:
- // Incoming Webhook Handler Code Snippet
- response = Map();
- title = body.get("title");
- priority = body.get("priority");
- description = body.get("description");
- url = body.get("url");
- id = body.get("id");
- status = body.get("status");
- assignee = body.get("assigned_to");
- response = {"text": "A new ticket has been created. The ticket details are given below: \n Ticket Name: " + title + " \n Description:" +description+ "\n Priority: `" + priority+ "` \n Ticket ID:" +id+ "\n [Ticket URL](https://" +url+ ") \n Status: " +status+ " \n Assigned To: " +assignee };
- return response;
To be done in Zendesk
Create a Target:
- Create an extension. To do so, click 'Extensions' under 'Settings'
- Click 'Add Target' under the targets tab.
- Click 'HTTP target' and give a name, URL, method.
- Give your bot's incoming webhook URL along with the zapikey parameter. Take a look at how to create a zapikey here .
-
Set your HTTP method as POST.
-
Select 'Create Target' and click Submit.
Sample Bot Incoming Webhook URL:
That's it! Your extension has been created.
Create a Trigger:
The next action is to create a trigger. Triggers are automated rules that work based on predefined conditions.
- Navigate to the Triggers tab and click ' Add Trigger '
- Give the trigger a name, description and set a condition. Take a look at the sample condition used for the example shown below.
- Under Actions, select ' Notify Target ' and select your target name.
- The JSON body will contain the ticket details. Modify this to suit your team's requirements. Here's a sample code snippet for the JSON body.
- Click Save!
Sample Trigger Code Snippet:
- {"title":"{{ticket.title}}",
- "description" : "{{ticket.description}}",
- "priority":"{{ticket.priority}}",
- "url": "{{ticket.url}}",
- "id":"{{ticket.id}}",
- "status":"{{ticket.status}}",
- "assigned_to":"{{ticket.assignee.name}}"
- }
Now creating a ticket with a priority set as
Urgent will notify all the support reps in Cliq via the Support Bot!
Take a look at how the Zendesk Ticket will be notified in Cliq via the Support Bot :
Ticket in Zendesk
Support Bot notifying in Cliq
And that's how easy it is to configure a bot's incoming webhook handler. Comments and suggestions are welcome.
Few useful links:
Best,
Manasa
Cliq