The HTTP Router app replaces most of the functionality provided by these packages. Specifically all messages passing through the HTTP router will be logged automatically and it provides a web interface for viewing and submitting new messages.

Installation From Cheese Shop

You can install the latest version of the rapidsms-httprouter library straight from the cheese shop:

% pip install rapidsms-httprouter

Installation From Github

You can always get the latest version of rapidsms-httprouter from github. Note that the tip of the repo is not guaranteed to be stable. You should use the verison available via pip unless you have a specific reason not to.

You can install the requirements using the pip-requires.txt file:

% pip install -r pip-requires.txt

Configuration

Put rapidsms_httprouter in your path, then add it to your INSTALLED_APPS setting:

rapidsms-httprouter also only pulls in the applications you specify for SMS handling. This lets you use the models from an existing SMS application. So you’ll need to add an SMS_APPS list to your settings.py:

SMS_APPS = [
"mysms.coolapp",
]

Finally, if you want to have the router push messages to a specific URL when they are sent, you need to specify that in the settings.py as well:

The following fields will be substituted into that string and the resulting URL will then be called via an HTTP GET:

'backend': the backend that is sending this message
'recipient': the phone number to send to
'text': the text to send
'id': the internal rapidsms id for this message

If you want to use the included console and http tester, add it as a tab:

RAPIDSMS_TABS = [
..
("httprouter-console", "Console"),
]

Usage

If you installed the tab, you should be able to click on the Console tab and immediately begin sending messages. Note that you do not need to run the router process for this to work, instead the HTTP backend detects that there is no router and queues the messages for sending later. (the ‘Q’ status represents this)

In your app.py, httprouter-aware applications can make use of an extra attribute that will be added to the IncomingMessage object, ‘db_message’. This is a reference to the actual database-persisted message:

def handle (self, message):
if hasattr(message, 'db_message'):
# do something cool, like add the message as a foreign key
# to one of your app's models, so you know where the model
# originated

Endpoints

The HTTP router provides the following endpoints:

Receive

Messages can be handled and put through the router process using the URL, the result is json:

Note that you must either have one entry per backend, or include a ‘default’ element, which will be used whenever there is not a specific match.

Security

It is a good idea to have some security on who can deliver messages to your system, who can see the outbox and who can can mark messages as delivered. You can lock these down in a rudimentary fashion by settings the ROUTER_PASSWORD attribute in your settings.py:

ROUTER_PASSWORD = "landshark"

Any incoming requests to those endpoints will fail if it is not included.

Celery & Redis

HttpRouter has two dependencies if you plan on using a ROUTER_URL and not just have message queue up, Redis and Celery. (note you can use Redis as a backend for Celery) You’ll need something like the following your settings.py in order to get things working: