Working with webhooks from bots

When creating or editing a bot, you can add a webhook by clicking the "+" to add an action as you normally would. From the action selection panel, click on "Trigger a webhook."trigger-a-webhook

Next, give your action a nickname and input the endpoint URL for the webhook. If your webhook will be sending data to HubSpot in response to the request, check the "Wait for webhook feedback" box. (Read more on this below.) Save your action. trigger-a-webhook-editorWhen this action has been reached in a conversation, HubSpot will send a JSON payload to the Webhook URL you’ve defined. The payload will contain information relevant to the chat session, including the visitors' responses to any questions asked, their contact ID, and information about the bot.

Example request payload:
JSON
//sample payload
{
  "userMessage": {
  // Details for the last message sent to your bot
    "message": "100-500",
    // The last message received by your bot, sent by the visitor
    "quickReply": {
    // If the visitor selected any quick reply options, this will be a list of the selected options.
    // Will be 'null' if no options were selected.
      "quickReplies":[
      // A list of quick reply options selected by the visitor
         {
            "value":"100-500",
            "label":"100-500"
         }
      ],
  },
  "session": {
    "vid": 12345,
    // The contact VID of the visitor, if known.
    "properties": {
    // A list of properties collected by the bot in the current session.
      "CONTACT": {
        "firstname": {
          "value": "John",
          "syncedAt": 1534362540592
        },
        "email": {
          "value": "testing@domain.com",
          "syncedAt": 1534362541764
        },
        "lastname": {
          "value": "Smith",
          "syncedAt": 1534362540592
        }
      }
    }
  }
}

Advanced users also have the option of including JSON in your webhook's response. By doing this, you can impact the flow of conversation or send a custom message.

Example response payload:
JSON
//sample payload
{
  "botMessage": null,
   // This is the message your bot will display to the visitor.
  "nextModuleNickname": "PromptForCollectUserInput",
   // If defined, this will be the next module your bot will go to. If undefined, the default configured behavior will be observed.
  "responseExpected": false
  // If true, the webhook will be triggered again with the visitor's next reply. If false, the default configured behavior will be observed.
}