All Collections
Features
Flows
How to start a WhatsApp flow with a Webhook
How to start a WhatsApp flow with a Webhook

You can start a flow in 2Chat invoking a webhook from a webapp

Updated over a week ago

You can start a flow in 2Chat from your own apps or integrations invoking a webhook. For this purpose the webhook flow trigger will generate a URL where you can send a POST request with a dynamic JSON request, so you can send message to a defined phone number and sending custom variables to personalize messages.

  1. Go to Flows section in 2Chat and click on New flow

  2. Select the source WhatsApp channel and click on Trigger

  3. Select Webhook Invoked as the trigger

  4. Enter the flow name and save it

  5. You must save the flow to get the URL where you can send the request

  6. Set the flow live to be able test it or use it

  7. Click the test trigger to define the destination phone number and add the variables you will send to create custom messages

  8. The post request must have this structure:

    • to_number: Is the destination phone number where the flow will send the message

    • variables: In this section you can define the variables that you will use to embed in the custom WhatsApp messages. In de following example we use the name and discount but you can add as many variables you need.

  9. Add the Message component and connect it to the trigger

  10. You can embed the custom variables adding the name in double brackets {{variable_name}}

  11. Save the flow and you can test it by clicking on Trigger this flow and then you must enter a test phone number in international format, add the variables and values for the message and click on Trigger Flow

  12. This way you will receive the test message in the destination phone number.

  13. Now that you check that the message is ok, you can use your own applications or integrations to trigger the flow sending a POST request with the body, replacing the phone number and the desired values for every variable:

    {
    "variables": {
    "name": "Jhon",
    "discount": "10%"
    },
    "to_number": "+17137157533"
    }

Did this answer your question?