Webhook

1. Configure the REVE Chat Webhook API

Your website team needs to call the REVE Chat Webhook API to transmit user information to the chatbot. It is recommended that your team needs call the API from server side. Follow the below steps to configure Webhook.

a. Accessing the Webhook for a Bot

  • Navigate to the Bot: Login to your REVE Chat Dashboard. Click on Chatbot from the vertical nav bar, then select your bot that your team is working on.

  • Access Webhook Settings: Once you land into your chatbot, in the top navigation bar click on Settings > select Webhook in the left navigation menu of the chatbot settings page.

b. Create your Webhook and Endpoint

  • Find or Create a Webhook: You need to generate a webhook link for your chatbot. Please note that each bot will have separate webhook link.

Create your webhook URL
  • Create an Endpoint: You can also create specific endpoints to send data to the webhook. These endpoints are appended to the main webhook link.

    Create an API Endpoint

  • Save your response: You can create your endpoint from here and define which attribute to save the webhook response. Also, you can define in the chatbot which flow will be triggered if you send data to this webhook. For e.g. customer logged in the website and you want to send data in the chatbot.

    Create an Endpoint and Redirect the

c. Sending Data to the Webhook

To send data to the webhook, include the following in the API header:

  • Authorization: Bearer <token from webhook configuration>

    • Each bot has a unique authorization token, which can be refreshed as needed. Refreshing invalidates any previous token, so avoid updating the token unless necessary.

    • The authorization token can be found on the webhook settings page.

Note: Authorization tokens can be refreshed at any time. However, doing so invalidates the previous token. Only refresh when necessary to maintain security and access continuity.

Example Curl:

curl -X POST "https://chatbot-uat.stc.com.kw/chat-websocket/api/webhook/v1/chatbot/bcad140a-4bd3-4976-9913-5c00e6987ece/login" \
-H "Authorization: Bearer <token from webhook configuration>" \
-H "Content-Type: application/json" \
-d '{
  "sessionId": "<sessionId>",
  "botId": "<botId>",
  "data": {
    // pass your data here
  }
}'

2. How to call webhook inside chatbot

a. Create an script to Call Brower Script

To send the data to the website team needs to send user data in the webhook along with the sessionId and botId parameter. The ongoing session sessionId and botId can be found with below approach.

  • Your team should create a custom JavaScript function such as- `chatbot.someFunctionName(param)`.

  • You can get the sessionId and botId in the param object and your team can use that param object to access the sessionId and botId like param.session_id and param.chatbot_id in their function. Here's an example script:

return new Promise(resolve => {
    let jsonObject = {
        chatbot_id: data.chatbot_id,
        session_id: data.session_id
    }

    let obj = {
        type: "run_script",
        script: `ChatbotFunction(${JSON.stringify(jsonObject)});`
    }
    resolve(obj);
});

Here's how to use script.

b. Create an script to Save your response

You need to use another script to process the data you're sending in the webhook. For e.g. you are sending user login information Name, Phone etc. You can process this data with Script.

return new Promise(resolve => {
    const loginDetails = JSON.parse(data.employee_login_details);

    let returnObj = {
        type: "set_variables",
        variables: {
            login_status: loginDetails.isLoggedIn
        }
    };

    if (loginDetails.name) {
        returnObj.variables.name = loginDetails.name;
    }

    if (loginDetails.isLoggedIn && loginDetails.phone) {
        returnObj.variables.phone = loginDetails.phone;
    } else {
        returnObj.variables.phone = "";
    }

    resolve(returnObj);
});

This will allow you to further save your response and take user to different flow with Condition action. Learn how to use condition action.

c. Configure your chatbot

  • First you need to check from chatbot when to call the browser script. It will trigger the script and fetch information in the beginning. If it is not needed in the beginning, you can define when it can be called. This script will allow the REVE Chat widget to call a browser script to get data.

  • Then, in the webhook settings, you need to define which node it will trigger if an endpoint receives data. From there, you can process the user response and take user to separate flow with condition action.

Last updated

Was this helpful?