gerard-bisama / sms2sparrow

Middleware to emulate a communication channel between Sparrow SMS and rapidPro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sms2sparrow

Allows RapidPro to connect to Sparrow SMS, an SMS aggregator in Nepal for sending flow SMS on client mobile phone.

Installation

Ubuntu

This solution is deployed on ubuntu 14.04 or 16.04.

RapidPro

Based on some issues on the compatibility of RapidPro API, it is advised to use the rapidpro source of the version committed by june 2017. This is the rapidPro used during the developpement of this solution. If your rapidPro server has been installed during or before this period you may not need to install a new instance. But if you are facing challenges during the channel configuration step, you could consider to install a new instance and checkout the source to the specific sha-1 commit. Follow step on install rapidPro, after cloning rapidpro from github, checkout the specific version of source by running the command below to get the version of june 2017.

git checkout 49522433c62000ad9ee82f8b06d9e5732b4c2e6

Continue with the rapidpro installation steps as explained on install rapidPro

ngrok

ngrok is used to establish secure tunnels to localhost, for some channel procedure rapidPro require secure tunnel. Download ngrok for ubuntu, unzip the file and run ngrok with

./ngrok http 8080 #rapidpro port. replace with the real port

you will see tunnels info such as.

Web Interface                 http://127.0.0.1:4040
Forwarding                    http://b73b695d.ngrok.io -> localhost:8080#tunnel created
Forwarding                    https://b73b695d.ngrok.io -> localhost:8080

Add the b73b695d.ngrok.io to the rapidPro ALLOWED_HOSTS params in the temba/settings.py file, and to TEMBA_HOST and HOSTNAME

MongoDB

sudo service mongod start

Clone the app on your Host

git clone https://github.com/gerard-bisama/sms2sparrow.git

Then configure parameters of the manisfest.webapp file based on the explanation below

{
  "launch_path": "/src/app.js",
  "default_locale": "en",
  "activities": {
    "SMSAPI": {
      "url": "http://api.sparrowsms.com/v2/sms", #the sparrow URL
      "token": "xxxxTokenxxxxxx", #The token generated on sparrow
      "shortcode": "xxxxx" # the short phone number provided by sparrow
    },
    "rapidpro": {
      "url": "http://localhost:8080/api/v2",
      "secureUrl": "https://temba.ngrok.io/handlers/external", #your secure rapidpro tunnels, replaced with the one generated by ngrok
      "uid": "xxxxxxxxxxxUuidxxxxxxxxxxxxxx", #uuid generated when creating the cha
      "token": "xxxxxxxxxxxxxTokenxxxxxxxxxxx" #RapidPro token
    }
  },
  "appType": "APP",
  "smsKeyword": "keyword", #can be changed,always in lower case
  "simulationMode": "on",
"supportSpecialCharset": "on",
...

if the configuration are done, Install the dependencies, node packages

cd sms2sparrow
npm install
npm start

The service is exposed on the port 8084 (this could be changed)

Service configuration

Create the rapidPro channel

Go to create channel and choose "External API", then provide information to the following fields

URN Type:Phone number
Number:<your short number or any format>
Country:<Contry> 
Send URL: http://serverIP:port/send/from={{from}}&text={{text}}&to={{to}}&id={{id}}
Method:HTTP GET
Request Body:from={{from}}&text={{text}}&to={{to}}&id={{id}}

Then save. After saving rapidPro shows channel config info for additional configuration. You will see something similar Received URL https://temba.ngrok.io/handlers/external/received/axxxxe-9db4-4e47-aa653-yyyyyyyyyyyy/. !!!When you see the url with following information: "temba.ngrok.io/handlers/external", it means that you have the required source version

Add callback url to sparrow

To be able to access incoming messages, ones should create a campaign in sparrow and add the this "http://serverIP:8084/getsms".

Task to Synch info between rapidPro and Sparrow SMS

Sending SMS, receiving SMS are async task. The app store need to notify rapidPro when the message sent is delivered or if there is new incoming message in the queue. so there is 2 script file create for that purpose and they just perform curl on specifics URI on time basis (5-9 seconds) Add this entries to you crontab

* * * * * /pathtorepo/sms2apps/sms2sparrow/pushsms2rp > /dev/null &
* * * * * /pathtorepo/sms2apps/sms2sparrow/reportsent > /dev/null &

Taratataaa

About

Middleware to emulate a communication channel between Sparrow SMS and rapidPro


Languages

Language:JavaScript 100.0%