Messaging

This integration involves using RapidPro for messaging reminders to clients either through campaigns or direct messages from OpenSRP.  e.g When a pregnancy surveillance form is submitted and the woman involved has a phonenumber, a new contact is created in RapidPro for the woman and the woman enrolled in the Pregant Women group. Once the woman is added to the pregnant women group, she's enrolled into an ANC campaign whereby she receives SMS reminders through her mobile phone to remind her about ANC visits when due. This integration is supported by the functionality at org.opensrp.connector.rapidpro.RapidProService in the opensrp-connector module. The table below highlights the main methods in the class.

MethodNotes
sendMessage

This method sends messages through RapidPro to the specified contacts. The method has the following params:

  • urns- This is a list of URNS to send messages to e.g ["tel:+250788123123","tel:+250788123124"] for telephone numbers or ["telegram:207355745"]
    for telegram accounts
  • contacts- This is a list of the contact uuids from RapidPro
  • groups- A list of group uuids to send message to
  • text- The text message to the user. Should be less than 480 characters
  • channel- The id of the RapidPro channel to use

Either of urns, contacts or groups is required since they contain the message recipient(s). This method makes a POST request against  Rapidpro /api/v1/broadcasts.json end point and returns a JSON

string with the sent message details e.g

{
    "id": 1234,
    "urns": ["tel:+250788123123", "tel:+250788123124"],
    "contacts": ["09d23a05-47fe-11e4-bfe9-b8f6b119e9ab"]
    "groups": [],
    "text": "hello world",
    "created_on": "2013-03-02T17:28:12",
    "status": "Q"
}






createContact

This method creates a contact in RapidPro and accepts a java.util.Map param. In the map the following keys can be added:

  • groups- A list (java.util.List) of group names the contact being created should be added to
  • urns- A list (java.util.List) of urns that should be associated with the user e.g phoneNo, telegram id
  • fields-A hashmap of contact fields to be set or updated on for the contact. The fields are automatically created in RapidPro if they don't already exists through the addField method.
  • name- the name of the contact being added
  • uuid- the Rapidpro id of the contact being updated. Note: specifying this value automatically makes the request an update otherwise a new contact is created
  • language- the preferred language for the contact
  • group_uuids- A list (java.util.List) of uuids of any groups this contact is part of

Other than the urns, all the other values are optional. This method makes a POST request against  Rapidpro /api/v1/contacts.json end point and returns a JSON string contains the details of the contact just added e.g


{
    "uuid": "4686bf60-a241-4b42-8102-27d9221aad5b",
    "name": "Xcv",
    "language": null,
    "group_uuids": [
        "bc5ef0d0-ce9d-4b52-adee-649a99927c8b"
    ],
    "urns": [
        "tel:+254727000000"
    ],
    "fields": {
        "anc1": "2016-10-27",
        "anc2": "2017-02-16",
        "anc3": "2017-04-13",
        "anc4": "2017-05-11",
      
    },
    "blocked": false,
    "failed": false,
    "modified_on": "2016-11-03T07:36:41.494Z",
    "phone": "+254727812024",
    "groups": [
        "Pregnant Women"
    ]
}


addField

This method adds a field to RapidPro and has the following params:

  • valuetype : This is the field data type and is a required field in RapidPro so if empty the default is set to "T" -text other acceptable fieldtypes are: "N" - Decimal Number "D" - Datetime "S" - State "I" - District
  • label- is the field name as it would appear in RapidPro and it's used to generate the field key e.g a field label like woman name translates to woman_name key

This method makes a POST request against  Rapidpro /api/v1/contacts.json end point and returns a JSON string contains the details of the contact just added e.g

{
    "key": "anc3",
    "label": "anc3",
    "value_type": "T"
}

.

deleteContactThis method deletes an existing contact given the UUID. This method makes a POST request against  Rapidpro /api/v1/contacts.json end point .



NB: To be able to use RapidPro within OpenSRP update opensrp.properties  the property rapidpro.url with your RapidPro server installation url, rapidpro.token with the your RapidPro REST API authentication token