-
Notifications
You must be signed in to change notification settings - Fork 7
Experiment Channels
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.
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.
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.
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.
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:
You need to add these environment variables for this integration to work:
- TWILIO_ACCOUNT_SID
- TWILIO_AUTH_TOKEN
In the ExperimentChannel creation form, choose the whatsapp
platform and change the value of the extra_data
field to look like
{"number": "+12345678910"}
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.