Skip to main content

Connect your bot to third-party services

You can use Aimylogic bots not only in the channels that are available in your bot settings but also in other services.

For example, you can connect Aimylogic to an integration service that is convenient for you and use it as a “hub” to any number of third-party services, for example, Google Analytics. Such integration services are connected using webhooks.

Once you created an integration in the third-party service, you need to connect an event in Aimylogic. To do this, go to Aimylogic and open the script you want to further transfer the data from.

Write data to a variable

To transfer data, you need to write it to a variable. For example, you want to send a user’s message to an integration tool. Add the text to $var block and assign it a $message variable. Everything that the user writes at this stage will be placed in this variable.

Add text to $var block

Create an HTTP request block

  1. Connect the Transition after entering a $message option to a new HTTP request block.

  2. In the HTTP request block, select the POST method.

  3. In the URL field, paste the webhook address received in the third-party service.

  4. The RESPONSE tab is not required. The Body tab’s content may vary depending on what request content you want to have.

  5. On the Headers tab, add a Content-Type header with the application/json value.

    caution
    If you leave the HEADERS tab blank, the request will fail.

    HTTP response

  6. Click Save.

Add response blocks

  1. From the Completed with an error option, make a connection to the block with the text: Sending error: $httpStatus.

  2. From the Completed successfully option, make a connection to the block with the text: Your data has been sent!.

    Add response blocks

    Now, when the chatbot reaches the HTTP request block, it will send the values you need to the integration service. The service will process the data and send it further depending on its settings.

  3. Click Test and see if the data transfer works correctly.

Enable webhook in your script

Once you specified your webhook URL, you can enable/disable screen events in your bot’s script. To do this, specify the event name in the screen header. You can choose any header color and then click on the webhook icon to enable it.

Add event name

If the screen event is enabled, then the bot will send the variables and the selected event to the server, and then copy the variables from the server’s response. Only after that, the bot will execute the blocks on the screen.

Something went wrong

Don’t worry, if something went wrong.

  1. Make sure you set POST as the HTTP request method and the HEADERS tab contains a Content-Type line with a value of application/json.

  2. The bot returns an error message.

    • The -1 error means that there are extra characters in the HTTP request URL. Make sure there are no spaces, and there are no curly braces or quotation marks in the event name.
    • The 404 error means that the HTTP request was not well-formed.
    • The 400 error indicates a malformed HTTP request. Pay attention to the BODY field: there should not be single or double quotes, ' or ".

If you still get no data after you edit the script, stop the test widget and start it again.

tip
We don’t recommend testing scripts in different browser tabs or windows simultaneously.