Users can communicate with RapidPro chatbots in IoGT v2.
RapidPro needs a service account within IoGT to be able to authenticate itself to IoGT and establish communication. The service account is set up within IoGT as an unprivileged user account within a specific user group. Any Wagtail Admin should be able to set up the service account manually.
- Create a new group (Settings > Groups, Add a group)
- The name must be exactly 'rapidpro_chatbot'
- No permissions are required
- Create the service account (Settings > Users, Add a user)
- The username just has to be unique
- Use a long and varied password (no need to remember it)
- It is recommended to give the user a descriptive first and last name, e.g. 'RapidPro Bot'
- Add the user to the 'rapidpro_chatbot' group (in the Roles section)
- Verify everything is set up correctly, by checking that the authorization header to be used by RapidPro when authenticating to IoGT now appears in Chatbot > Chatbot Channels.
You can now set up a channel in RapidPro, and add this channel to IoGT so you can start communicating with it.
- Find the Chatbot Authentiation Header for the chatbot in the IoGT admin panel at Chatbot > Chatbot Channels - displayed at the top of the page.
- In your workspace in RapidPro, go to Settings > Add Channel.
- Select External Api.
- Fill in the following form fields
- URN Type: External identifier
- Address: Enter a name identifying your RapidPro server, e.g. my_rapidpro_server
- Method: HTTP POST
- Encoding: Default Encoding (TODO: Confirm this)
- Content type: JSON - application/json
- Max length: 6400 (see notes: 1, 2)
- Authorization Header Value: Enter the Chatbot Authentiation Header from the IoGT admin panel Chatbot > Chatbot Channels, mentioned earlier (include the word 'Bearer' as well as the code)
- Send URL:
https://[URL of the IoGT site]/messaging/api/rapidpro-webhook/
where[URL of the IoGT site]
is the URL of your IoGT site, e.g.rw.goodinternet.org
. - Request Body:
{"id":{{id}}, "text":{{text}}, "to":{{to}}, "to_no_plus":{{to_no_plus}}, "from":{{from}}, "from_no_plus":{{from_no_plus}}, "channel":{{channel}}, "quick_replies":{{quick_replies}}}
(TODO: Check whether we can omit theto_no_plus
andfrom_no_plus
) - MT Response check: ok
- Click Submit
- You will land on the External API Configuration page
- Copy the Received URL that is displayed on the page. This URL should look roughly like this:
https://[your RapidPro server]/c/ex/some-uuid-here-7afd839d7123-a95d/receive
- Go back to the IoGT admin panel, Chatbot > Chatbot Channels, Create a new channel.
- DISPLAY NAME: This is the name that users will see when interacting with the bot.
- REQUEST URL: Enter the Received URL from step 7, immediately above.
1 On older RapidPro installations the upper limit might only be up to 640.
2 Messages longer than the limit will be split up into multiple parts and will have to be re-joined on the IoGT side, which can cause spaces between words to be lost. Thus, larger limits are better, so we can avoid messages being split as much as possible.
As part of an article's content, you can now add a Chatbot button. It has the following form fields:
- Subject: The title identifiying the conversation with the chatbot in the user's inbox.
- Button text: The text to be displayed on the button
- Trigger string: The initial message that will be sent to the chatbot, starting the conversation
- Channel: Select the channel you just created.
Upon clicking the button, the user will be directed to a conversation view with the chatbot.
The inbox view can be accessed via the URL https://[URL of the IoGT site]/messaging/inbox/
. To allow users to resume conversations later, you can e.g. create a flat menu entry (Settings > Flat Menus) linking to this inbox view, or to an article explaining about the chatbot that also has a link to the inbox.
This is only an option for those who are operating an instance of IoGT (system administrator, ops team). The management commmand performs the manual steps for creating a service account in IoGT (detailed above) and is provided to automate the process (e.g. when an IoGT site is first created).
The setup command.
python manage.py sync_rapidpro_bot_user
There is another command that will print the authorization header to be used by RapidPro when authenticating to IoGT.
python manage.py get_rapidpro_authentication_header_value
This is the same value that appears in the IoGT admin panel under Chatbot > Chatbot channels.