This repo contains a flask about for forwarding messages we get via the websocket handler to rapid pro, and vice versa
- Create a discord bot in the developer portal
- Add it to a server
- Visit the OAuth2 side-nav for your discord application
- Select "URL Generator"
- Check the "bot" scope
- Copy the generated URL at the bottom and paste it into a new tab
- Add the bot to the relevant server
If you are also in that server, you should be able to DM the bot!
cp .env.example .env
- Fill in the
.env
file with:DISCORD_TOKEN
(your Discord application's bot's token)DISCORD_APP_ID
(you Discord application's ID)RP_NETLOCK
(the 'netloc' of RapiPro e.g. rapidpro.com)RP_BASEPATH
: The base path for the RapidPro channel, e.g. /c/ds/bac782c2-1234-5678-9012-97887744f573/RP_SCHEME
: https | http
docker compose up
Once things are up and running, you can then hit the flask application on localhost:5555
To test out sending messages to Discord, I've been loading the root page, opening the dev console, and then using JS fetch:
// The example body is from the rapid pro test cases
const rapidProChannel = 'whatevs';
const toChannel = CHANNEL_ID_OF_YOUR_DM_WITH_THE_BOT;
fetch('/rp-response', {
method: 'POST',
body: JSON.stringify({"id":"10","text":"Hello World","to": toChannel,"channel":rapidProChannel,"attachments":["https://foo.bar/image.jpg"],"quick_replies":["hello","world"]}),
headers: {
'Content-Type': 'application/json'
}
})