Skip to content

Commit

Permalink
fix callback functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
copelco committed Jun 10, 2013
1 parent 4ac2006 commit 8272f9e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
57 changes: 53 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rapidsms-twilio
`Twilio <http://www.twilio.com>`_ backend for the `RapidSMS
<http://www.rapidsms.org/>`_ project.


Requirements
------------

Expand Down Expand Up @@ -32,10 +33,10 @@ Add the following to your existing ``INSTALLED_BACKENDS`` configuration in your
"twilio-backend": {
"ENGINE": "rtwilio.outgoing.TwilioBackend",
'config': {
'account_sid': 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', # (required)
'auth_token': 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY', # (required)
'number': '(###) ###-####', # your Twilio phone number (required)
# 'callback': 'http://<public-django-instance>/twilio/status-callback/', # optional callback URL
'account_sid': 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', # (required)
'auth_token': 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY', # (required)
'number': '(###) ###-####', # your Twilio phone number (required)
# 'callback': 'http://<public-django-instance>/twilio/status-callback/', # optional callback URL
}
},
}
Expand All @@ -55,4 +56,52 @@ backend. You can do this like so::
Now inbound Twilio messages can be received at ``<your-server>/backend/twilio/``
and outbound messages will be sent via the Twilio backend.


Callback URL
------------

Delivery Report
===============

RapidSMS can take advantage of Twilio's callback URL functionality. This is
useful if you'd like to track the status of a message after it's been passed to
Twilio for processing. Twilio will use a callback URL to notify us. Enabling
this feature will allow you to view delivery reports, for each message, in the
Django admin.

1. Make sure ``rtwilio`` is in ``INSTALLED_APPS``::

INSTALLED_APPS = (
# other apps
'rtwilio',
)

2. Add the callback view to your urlconf::

urlpatterns = patterns('',
# ...
url(r'^backend/twilio/status-callback/$', status_callback,
name='twilio-status-callback'),
)

3. Add the necessary database tables (omit ``--migrate`` if you're not using South)::

python manage.py syncdb --migrate

4. Add the full callback URL to your settings::

INSTALLED_BACKENDS = {
# ...
# other backends, if any
"twilio-backend": {
"ENGINE": "rtwilio.outgoing.TwilioBackend",
'config': {
# same as before..
'callback': 'http://<public-django-instance>/backend/twilio/status-callback/',
}
},
}

You can view delivery reports in the Django admin.

Development by `Caktus Consulting Group <http://www.caktusgroup.com/>`_.
2 changes: 2 additions & 0 deletions rtwilio/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

from rapidsms.backends.http.views import GenericHttpBackendView

Expand All @@ -16,6 +17,7 @@ class TwilioBackendView(GenericHttpBackendView):
form_class = TwilioForm


@csrf_exempt
def status_callback(request):
form = StatusCallbackForm(request.POST or None)
if form.is_valid():
Expand Down

0 comments on commit 8272f9e

Please sign in to comment.