Search code examples
smooch

Get Smooch Whatsapp user number


I'm testing Smooch Javascript SDK (https://docs.smooch.io/rest/#introduction) integrated to Whatsapp. I want to know if its possible to get user's phone number when I recieve a webhook request, the phone number is not in the request body.

// This is the request body I get

{
  "trigger": "message:appUser",
  "app": { "_id": "5d308957198c1f00104a3b88" },
  "version": "v1.1",
  "messages": [
    {
      "type": "text",
      "text": "Hello",
      "role": "appUser",
      "received": 1563472958.747,
      "name": "Kevin Arias",
      "authorId": "2d4628bcb45b234a1ff",
      "_id": "5d30b43ee223faa28f",
      "source": {
        "type": "whatsapp",
        "integrationId": "5d308964a75fd5a457f",
        "originalMessageId": "ABEGVzElE6JZEN_vQ92XFBiIrb4S",
        "originalMessageTimestamp": 1563472958
      }
    }
  ],
  "appUser": {
    "_id": "2d4628b5cb45b234a1ff",
    "conversationStarted": true,
    "surname": "Arias",
    "givenName": "Kevin",
    "signedUpAt": "2019-07-18T15:00:45.883Z",
    "properties": {}
  },
  "conversation": { "_id": "84860727bddac962a8b" }
}

Thanks,


Solution

  • If you enable the includeClient option on your Smooch webhook, there will be a client object included in the webhook payload, representing the source of the message. The WhatsApp username (typically the user's phone number) will be available under client.externalId