Skip to content

Experiment Channels

Farid Rener edited this page Jul 3, 2024 · 22 revisions

Overview

Experiment Channels allow users to interact with experiments through an external channel like Telegram or WhatsApp. Simply creating the channel should active it and allow forwarded messages to reach the configured experiment (see the section below on specific actions that happens when a channel is created or updated). External channel messages are forwarded to the server on the <your-domain>/channels/<your-channel> path.

Supported Channels

Web

This refers to the chat view in the web UI. Web channels are created automatically for new experiments and hidden from the admin dashboard, since no user interaction is required to maintain these.

Telegram

Integrating Telegram requires that you add the TELEGRAM_SECRET_TOKEN environment variable with a secret value. This value can be anything. You'll also need a Telegram bot and its token. In the channel's creation form, you'll need to add your bot token in the extra_data field. Note that this is a JSON field, so the final value of this field should look like

{"bot_token": "your token here"}

When the channel is saved, this token is used to register a webhook at Telegram so that new messages to this bot will be forward to the server.

Note to developers

To expose your dev server to the public, you can use the invoke runserver command with the --public flag. For this to work, you need to have ngrok installed on your machine.

WhatsApp

Adding a WhatsApp channel requires you to have a Twilio account and WhatsApp number. Once you have this, you need to complete these three steps:

1. Add the environment variables

You need to add these environment variables for this integration to work:

  • TWILIO_ACCOUNT_SID
  • TWILIO_AUTH_TOKEN

2. Add the channel on OpenChatStudio

In the ExperimentChannel creation form, choose the whatsapp platform and change the value of the extra_data field to look like

{"number": "+12345678910"}

3. Configure Twilio to forward messages to this number

Go to the Develop tab in your Twilio account, then go to Messaging -> Senders -> WhatsApp Sender. From here you can configure it to forward messages to your server via webhooks. The final webhook URL should look like

https:///channels/whatsapp/incoming_message

and make sure to configure it as a POST request.

This should conclude the integration.