Skip to content

Experiment Channels

Chris Smit edited this page Oct 11, 2023 · 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). Extenal 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 forward Telegram messages to your local environment you can use a tool like ngrok. Be sure to update this line to point to the provided ngrok address.Example:

webhook_url = f"https://332c-102-182-68-203.ngrok-free.app/channels/telegram/{experiment_channel.external_id}"

Once you've harcoded the webhook_url, you can continue to create your telegram channel, or if you already created it, just save it again. This will register the working webhook at Telegram's side. Note that if Telegram tried to send a message to your server and failed, it will back off for a bit after retrying.

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.

Clone this wiki locally