Loader

Update Chat History API

In this short tutorial, we provide information on the Update Chat History API and how to utilize it.

 

Why use this API?

The Update Chat History API enables you to post an event for a WhatsApp message template (previously known as a Highly Structured Message or HSM) that was sent from a third-party app to the chat history of an end-user in Chat Desk. Without this API, Chat Desk has no visibility on message templates sent via third-party applications and these message template responses will not form part of an end-user’s chat history in Chat Desk.

 

When to use this API

If you are sending WhatsApp message templates via a third-party application (i.e., not directly from within Chat Desk itself), you have to call this Update Chat History API after sending the template to see and record template responses in Chat Desk as part of the conversation history. 

If you are sending message templates directly from Chat Desk, you do not have to use this API – template responses are automatically recorded in the Chat Desk conversation history.

 

Getting started with the Update Chat History API

The following steps should be executed to post an event for a WhatsApp message template sent via a third-party application to the chat history of an end-user on Chat Desk via an API call. 

Base production URL:

https://prod-chatdesk-platform-app-alpha.int-eks-prod.shared-prod.eu-west-1.aws.clickatell.com


Step 1: Create Chat Desk API Token (if it doesn’t exist yet) 

Create an authorization token using a value contained in the cookies of Chat Desk. This token is generated only once per client. If already generated, you can skip this step and go to Step 2 below.

POST: /external-api/token

Headers:

Authorization: mc2Token or ChatDeskToken

Response 
{
  "apiToken""string"
}


Step 2: Get Chat Desk API Token

Retrieve your Chat Desk API token if it has already been created.

GET: /external-api/token

Headers:

Authorization: mc2Token or ChatDeskToken

Response 
{
  "apiToken""string"
}


Step 3: Get list of channels by token

Provides you with a list of the channels you have set up with Clickatell. You will be required to use the channel ID in the body of your API call when posting a previously sent message template to the chat history.

GET: /external-api/channels

Headers: 

Authorization: apiToken from Step 2

Response 
[
  {
    "id""string",
    "type""WEBCHAT"
  }
]


Step 4: Update Chat History

The Update Chat History API enables you to post an event (WhatsApp message template sent) to the chat history of your end-user via an API call. This will ensure that after sending a WhatsApp message template to an end-user from a third-party application, you can store it in the chat history of Chat Desk for future visibility when engaging with the end-user.

POST: /external-api/chats/messages/history

Headers:

Authorization: apiToken from Step 2

Request 
{
  "externalUserId""14379999898",
  "channelId""string",
  "messages": [
    {
      "type""HSM",
      "dateTime""2022-05-04T18:08:24.903Z",
      "templateId" "templateId",
      "templateName""string",
      "params": {
        "1""param value 1",
        "2""param value 2"
      }
    }
  ]
}
  • externalUserId – User phone number or another external ID. This depends on the channel – for the WhatsApp channel, it will always be a phone number.
  • channelId – channelId from Step 3
  • messages – List of messages 
    • type – Type of message. (supported: HSM)
    • dateTime: Time of message

                    Additional params for specific types of message: HSM

    • templateId – MC2 template ID
    • templateName – Name of WhatsApp message template
    • params – Parameters for the template
Response 
{
  "message""History is added"
}

Did you find this information informative?

Other Resources

Ask the Community

Visit Stack Overflow to join our community of developers and find the answer you need

Contact Support

Contact our support team and one of our agents will be in touch with you to answer any questions you have