Contains scripts for fetching runs from Rapid Pro, and for inserting messages into a Rapid Pro development server.
Follow the instructions on RapidPro's developer web page.
The commit of RapidPro these instructions were tested against is f988b82ed962c6bc3532393fa4f68cf301df6ebc
.
After starting the server, as described by the developer instructions referenced in the previous step, open localhost:8000 in a web browser.
Enter an email address and click “Create Account”.
Follow the on-screen instructions to configure your user account and organisation.
There are two options here - build your own flow from scratch or use the one provided with this repository.
To build your own flow:
In RapidPro, select Flows -> Create Flow
. This opens the visual flow editor.
Building a flow is fairly straightforward, but documentation for the editor is
available here if needed.
To use the sample flow provided:
In RapidPro, go to your organisation page (click the button in the top-right).
Then choose Settings Gear -> Import
and select camelid-flow.json
from this repository. Finally, click Import
.
This will upload the flow and enable the 'camelid' trigger. This trigger will start the flow whenever a user transmits
the word "camelid" to one of your channels. Including this trigger is non-optional. If you wish to remove it, go to
Triggers
then tick the checkbox next to the camelid trigger. Finally, click the Archive button which appeared.
To export a Flow for sharing, Flows -> flow-to-be-shared -> settings gear -> Export -> Export
.
The Flow editor includes an in-built simulator for testing (accessible by clicking the mobile phone icon).
Interactions with a flow via the simulator are not persisted to the RapidPro database. For a run to persist, it must be run on a "channel". To add a channel:
Settings Gear -> Add Channel
This repository includes a simple channel which can be used via the command line. To set-up this channel:
Settings Gear -> Add Channel -> External API
URN Type
: Phone number
Number
: Any phone number of your choosing.
Messages sent to the API will look like they have come from this number.Country
: Can be anyMethod
: HTTP POST
Content Type
: URL-Encoded
Max Length
: These instructions only tested with messages < max lengthSend URL
: The endpoint at which the CLI channel will be available. If running locally, this will be:
http://localhost:8082/messages?from={{from}}&text={{text}}&to={{to}}&to_no_plus={{to_no_plus}}
.
This URL cannot be changed. You will need to delete the channel and create a new one to correct mistakes.Request Body
: Leave unchanged.Submit
. RapidPro now takes you to an External API Configuration page.http://localhost:8000/c/ex/<UUID>
.cli_channel.py
, included in this repository, in an editor.SERVER_ADDR
constant to the RapidPro base URL you determined earlier.
You may optionally change the PHONE_NUMBER
of the client you're simulating.$ pipenv sync
.$ pipenv run python cli_channel.py
.You may now type a message to send to the channel. If you send a flow trigger, the response from RapidPro will be printed to the console, and you will be given the opportunity to send another message in response. If using the provided sample flow, start by sending "camelid".
$ pipenv sync
$ pipenv run python poll_flow_runs.py <API-Token>
The tool will output summary data on all runs, then poll for all runs again every few seconds. Change to incremental fetching by uncommenting the last line.
To export TracedData, use $ pipenv run python fetch_runs.py
.
This script does not poll - it performs a single download and write to disk.
To automatically run the camelids flow many times, use the provided camelid_runner.py
script.
The structure of this script is very similar to that of the command line channel, so follow
the instructions for the command line channel, adapting to assign variables in, then to run
the script, camelid_runner.py
. There is no need to create a new channel, provided you terminate cli_channel.py
before running camelid_runner.py
Flow messages consume credits. By default, RapidPro only issues you with 1,000 "free" credits. You can view your current credit balance on your organisation page.
To top up your credit balance on the dev server, insert a top-up entry into the orgs_topup table. Achieve this with the following command sequence:
$ psql --user temba postgres
=# \c temba
=# SELECT * FROM orgs_org;
id
and the created_by_id
.=# INSERT INTO orgs_topup (org_id, is_active, created_on, modified_on, price, credits, expires_on, created_by_id, modified_by_id) VALUES (<org_id>, True, current_timestamp, current_timestamp, 0, 1000000, '2050-01-01', <user_id>, <user_id>);
.
Set <org_id>
to the id
you noted in the previous step.
Set <user_id>
to the created_by_id
you noted in the previous step.Check if your new credits have been correctly added to your organisation by going to your organisation page and viewing your credit balance. This does not always update immediately - if this is still showing the old balance then click on this old balance to view your Top Ups history, and look for the new entry here. The preview credit balance on the organisation page will update to reflect the new balance once the current preview balance has been consumed.
RapidPro can export all runs of a particular flow as a .xlsx file. To do this:
Flows
Download Results
button (Excel logo), then Ok
.If you don't care about receiving messages or triggering flows, RapidPro has a command line tool for easily inputting messages into the system.
To use it, run this command from the RapidPro server directory:
$ python manage.py msg_console --org <your-organisation-name>
.
The tool prints instructions for sending texts/changing the client phone number when it starts.