Thumbnail
WhatsApp Business API | Integration with Freshdesk

Hi there!

Would you like to notify your customers via WhatsApp and respond to their questions in your Freshdesk?

In this tutorial, you will learn to integrate WhatsApp conversations with Freshdesk tickets. This integration will allow your system to trigger sending of a WhatsApp notification, open a ticket for it in Freshdesk and your agents to respond to customers from Freshdesk directly by adding Public Notes to the ticket.

logo_freshdesk_ct2x

You will need

Step One: Get your integration app ready

For your quick start with integrations, we’ve prepared a sample integration app. Look at what the code does. The app contains a webhook module. Notice the code in the src/webhooks directory:

  • webhooks.controller.ts handles the webhooks callbacks.
  • webhooks.service.ts handles the API calls to tyntec and Freshdesk.

Let’s just quickly get your app running in the development style:

1. Clone the api-samples repository and go to the wa-integrations/freshdesk folder.

2. Install dependencies:

yarn install

3. Copy the file .env-example to .env and set environment variables in .env:

  • WABA_NUMBER -- your WABA number in the international format without the leading +/00
  • TYNTEC_API_KEY -- your API key from tyntec
  • FRESHDESK_API_KEY -- your API key from Freshdesk
  • FRESHDESK_DOMAIN -- yourcompany.freshdesk.com
  • REQUESTER_EMAIL -- the email of the requester for these tickets

4. Run ngrok in a terminal:

ngrok http 3000

5. And finally, start the app in another terminal:

yarn start

You now have all the API endpoints in your app ready and running!

Step Two: Subscribe your webhook in tyntec

Let tyntec know where to deliver WhatsApp messages from customers. You’re going to subscribe your webhook via an API call in Postman.

1. Download our Postman collection, unpack and import it in Postman.

2. Right-click the collection and select Edit.

3. Go to Variables and set the apikey value to your tyntec API key.

4. Go back to your collection and in the folder Application Management open the patch Update default application (see the reference for details).

5. Edit the Body to update the callbackUrl with your webhook for the MoMessage event. The request body should look like this:

{
  "webhooks": [{
    "events": [
      "MoMessage"
    ],
    "callbackUrl": "https://<YOUR_SERVER>/webhooks/receiveResponse"
  }]
}

6. Now hit Send and you should get the 204 status if everything was okay.

Cool! Now tyntec knows where to deliver WhatsApp messages from your customers.

Step Three: Subscribe your webhook to Freshdesk

Let Freshdesk know where to forward Public Notes from tickets. You’re going to set an automation rule as follows (or see Using webhooks in automation rules for details):

  1. Go to Freshdesk > Admin > [Helpdesk Productivity] Automations, switch to Ticket Updates and click the button New rule.
  2. Define the rule.
  • Name the rule, for example: Send Public Note as WA message
  • When an action performed by… Agent: Any (leave empty)
  • Involves any of these events... Note is added -- Public note
  • Perform these actions: Trigger webhook
  • Request type: POST
  • URL such as: https://<YOUR_SERVER>/webhooks/sendResponse
  • Encoding: JSON
  • Content: Simple and add properties: Ticket ID, Last Public Comment, and Contact Phone.

And hit the button Preview and save.

Congrats! Now Freshdesk knows where to forward new Public Notes.

Note: The trigger will fire only if the account, which adds the Note, has the Agent role.

Step Four: Try it out!

And guess what, it’s testing time!

Let’s simulate the trigger from your system to send an initial notification to your testing customer.

1. Create a new collection in Postman and add a new request:

POST https://<YOUR_SERVER>/webhooks/initConversation
{
  "customerPhone": "123456789",
  "customerName": "John Doe",
  "templateParams": ["April 1", "2 PM"]
}

A name and phone are needed by Freshdesk to create a new contact along with a ticket, if the contact is not in Freshdesk yet. A phone and template parameters will be used to send a template message to WhatsApp. In our sample app, we’re using a template that notifies the customer of an appointment, which takes two parameters (date and time of the appointment).

Hit the Send button. You should get the 201 status if everything was okay.

2. Now login to your Freshdesk under the Agent account and voila! You've got a new ticket.

3. Check your testing customer WhatsApp, you should also have the notification there. Respond to it.

And the response got added to your ticket!

4. Now reply to your customer as the agent (add a note and set it to Public).

And watch the reply arrive to the customer’s WhatsApp!

More?

To use your own template to notify the customer, you’re going to need to update the function sendWhatsAppTemplate() in webhooks.service.ts and eventually, the number of parameters accepted by the template in dto\initConversation.dto.ts, which validates the trigger from your system. Also subscribe your webhook in your system to trigger the notifications automatically.

Tip: Freshworks provide further integrations as part of their services, for example you may install Freshdesk in Freshsales to allow your sales people to see the tickets from Freshdesk!