Receiving Messages via Webhook

Webhooks is a mechanism which enables applications to communicate with each other programmatically. It allows you to send real-time data from one application to another whenever a given event occurs.

Whenever a specific event occurs, the Qikchat sees the event, collects the data, and immediately sends a notification (user-defined HTTP callbacks) to the webhook URL specified.

There are 2 main objects you can receive via webhooks:

  • message: Used to notify you when you get a new message and what is in the new message.

  • statuses: Used to notify you when there's a status change in a message you sent.

Only use asynchronous handling of webhooks

Do not process incoming messages and notifications in the webhook handler. Acknowledge immediately after receiving the webhook (with status 200), then you can process the data.

Recommendations

For stable functioning of webhook it is recommended to make the webhook perform as fast as possible. That means:

  • Respond with status 200 immediately after receiving a notification (the callbacks payload should NOT be processed before responding, but ack first then process).

  • Sending one message as opposed to getting one causes up to three callback notifications (sent, delivered and read). It means that the speed of processing concurrent requests should increase in accordance with the load of the number. In addition to a direct increase in the speed of processing notifications, we recommend making your webhook process as many parallel requests as possible. Otherwise, this can lead to the occurrence and overflow of the message queue.

Webhook URL

The webhook URL is a resource address to which the Qikchat Server sends notifications, which are triggered by specific events. The maximum tolerable time for webhook response is 2 seconds.

Set Webhook URL

You can update it or remove it at any time in settings.

Example setting webhook with Basic Auth

If the webhook URL needs to be authorized by user, USER and PASS should be provided in the header Authorization that contains Basic base64(USER:PASS).

Request body example for USER=testuser and PASS=testpass

{  
   "headers": {    
      "Authorization": "Basic dGVzdHVzZXI6dGVzdHBhc3M=" 
   },
   "url": "https://www.example.com/webhook"
}

Receiving notifications for incoming messages

When a customer sends you a message, the Qikchat server will send an HTTP POST request notification to the webhook URL with the details that are described below:

Received Incoming Text Message

{
    "event": "whatsapp:message:in",
    "payload": {
        "id": "52JH6WmuSruAVyXvBBYemd0Ia",
        "name": "whatsapp",
        "contacts": [
            {
                "profile": {
                    "name": "Siva"
                },
                "to": "+91790XXXXXXX"
            }
        ],
        "message": {
            "from": "9184XXXXXXX",
            "timestamp": "2022-02-15T11:30:35.000Z",
            "text": {
                "body": "I want this product"
            },
            "type": "text"
        }
    }
}

Received Incoming Media Message

{
    "event": "whatsapp:message:in",
    "payload": {
        "id": "52JH6WmuSruAVyXvBBYemd0Ia",
        "name": "whatsapp",
        "contacts": [
            {
                "profile": {
                    "name": "Siva"
                },
                "to": "+91790XXXXXXX"
            }
        ],
        "message": {
            "from": "9184XXXXXXX",
            "timestamp": "2022-02-15T11:30:35.000Z",
            "image": {
                "id": "id",
                "mime_type": "image/jpeg",
                "sha256": "sha256",
                "url": "media-url"
            },
            "type": "image"
        }
    }
}

Receiving notifications for statuses

{
    "event": "whatsapp:message:status",
    "payload": {
      "id": "52JH6WmuSruAVyXvBBYemd0Ia",
      "name": "whatsapp",
      "from": "918080808080",
      "to": "+91790XXXXXXX",
      "status": "read",
      "timestamp": "2022-02-15T11:30:35.000Z",
    },
  }

Last updated