Auto-message responses

Hello @diana @mrjones

i have configured SMS Person Registration Form for an sms report like N 1234 m 25 Harry MIke which works fine…

My query is on hiw to automate a response when the report passes all validations and is received, i did define the form and its registration in the app_settings.json as seen below.

"registrations": [
    {
      "form": "N",
      "events": [
        {
          "name": "on_create",
          "trigger": "add_patient",
          "params": "{ \"parent_id\": \"place_id\" }",
          "bool_expr": ""
        }
      ],
      "validations": {
        "join_responses": true,
        "list": [
          {
            "property": "place_id",
            "rule": "regex('^[0-9]{5,13}$')",
            "translation_key": "messages.n.validation.place_id"
          },
          {
            "property": "gender",
            "rule": "iEquals('m') || iEquals('f')",
            "translation_key": "messages.n.validation.gender"
          },
          {
            "property": "age",
            "rule": "between(5,130)",
            "translation_key": "messages.n.validation.age"
          }
        ]
      },
      "messages": [
        {
          "event": "report_accepted",
          "translation_key": "messages.n.report_accepted",
          "recipient": "reporting_unit"
        }
      ]
    }
  ],

  "forms": {

    "N": {
    "meta": {
      "code": "N",
      "label": {
        "en": "New Person Registration"
      }
    },
    "fields": {
      "place_id": {
        "labels": {
          "tiny": {
            "en": "place_id"
          },
          "description": {
            "en": "Household ID"
          },
          "short": {
            "en": "HH ID"
          }
        },
        "position": 0,
        "type": "string",
        "length": [
          1,
          13
        ],
        "required": true
      },
      "gender": {
        "labels": {
          "tiny": {
            "en": "gender"
          },
          "description": {
            "en": "Gender"
          },
          "short": {
            "en": "Gender"
          }
        },
        "position": 1,
        "type": "string",
        "length": [
          1,
          6
        ],
        "required": true
      },
      "age": {
        "labels": {
          "tiny": {
            "en": "age"
          },
          "description": {
            "en": "Age"
          },
          "short": {
            "en": "Age"
          }
        },
        "position": 2,
        "type": "integer",
        "length": [
          1,
          2
        ],
        "required": true
      },
      "patient_name": {
        "labels": {
          "tiny": {
            "en": "patient_name"
          },
          "description": {
            "en": "Patient name"
          },
          "short": {
            "en": "Patient name"
          }
        },
        "position": 3,
        "type": "string",
        "length": [
          3,
          30
        ],
        "required": true
      }
    }
  }
  },

Added the translation in the messages.en.properties file

messages.n.report_accepted = Thank you for registering the patient with CHT.
messages.validation.place_id = House hold ID is not right 
messages.n.validation.gender = Gender is wrong
messages.n.validation.age = Age selected is not in range

But when i send a report through the getway for some reason i dont get back the auto message when the sms report is received by the server.
Thanks

Hi @cliff

which works fine…

To clarify, does this mean the person gets successfully registered on the web app? If the person is registered successfully, do you see any queued messages and are you able to see the state on the message or messages? The message state could help you troubleshoot the issue.

1 Like

thanks @samuel ,am able to see the person in the webbapp under reports tab

i am not seeing any messages in the messages tab

I can only see the mesages to the webbappp in the cht-gateway

1 Like

Hi @cliff

The messages should be attached to the report, not in the messages tab. In the report tab, open the report that created the person and scroll down and check if there are messages to be sent.

thanks @diana
i see the message report sent by the submitter

Hi @cliff

I think that transitions aren’t working at all for you.
Can you please:

  1. Create a person manually in the webapp and assign them the phone number you are using to send these messages. Only known contacts can register new people (by default, this can be changed with configuration, but trying to keep things simple here).
  2. Enable “update_clinics”, “registrations” and “generate_patient_id_on_people” transitions.
  3. Make sure that the place associated with your place_id exists!

What should happen when you send another one of these messages:

  1. when opening the report, you should see the sender’s name in the header (the contact that you created)
  2. you should see links to the new person contact that was created
  3. you should see the new person in the people’s tab, when you open the details page for the parent. You can also search for this person using their name.
  4. you should see the messages attached to the report, when opening the report

For example:

2 Likes

hello @diana

I followed the steps above though getting * messages.generic.parent_not_found

This means that the place that has a place_id with the value 12345 (Step 3 from above) does not exist.

1 Like

@diana is the place_id the External ID when creating a New Health Facility ?

@cliff no, it’s a unique 5 digit code that gets assigned to a place by generate_patient_id_on_people transition. The field property is place_id when looking at the contact doc.

1 Like

@diana would like inquire on how to list only the contact docs …
i have used curl https://medic:password@192-168-115-70.my.local-ip.co/medic/_all_docs

 
{"total_rows":58,"offset":0,"rows":[
{"id":"2db9922e-1df2-5e30-abbb-8bfc1a662192","key":"2db9922e-1df2-5e30-abbb-8bfc1a662192","value":{"rev":"2-9fe30fa6af3eb0f42a7994c83fa2e6c4"}},
{"id":"58cda4c9-7af5-5b45-9be3-316d5dfb3fce","key":"58cda4c9-7af5-5b45-9be3-316d5dfb3fce","value":{"rev":"2-684dcb2125bd9430c5c2d591dedba373"}},
{"id":"680ffae0-7b72-4366-a16f-f7712a896cc3","key":"680ffae0-7b72-4366-a16f-f7712a896cc3","value":{"rev":"1-e6930155ef7c620791f9e26645f38730"}},
{"id":"90863e70-c27e-41ef-9749-d15620b0fcad","key":"90863e70-c27e-41ef-9749-d15620b0fcad","value":{"rev":"1-b936ac8148075a1ed29973159e7a726f"}},
{"id":"9b145fe2d3c13bbb16ce5b7a8200051a","key":"9b145fe2d3c13bbb16ce5b7a8200051a","value":{"rev":"3-c1c7392d555542ed161782d7ff1e4d2a"}},
{"id":"9b145fe2d3c13bbb16ce5b7a820007e9","key":"9b145fe2d3c13bbb16ce5b7a820007e9","value":{"rev":"2-26a3804f7acfc35287c2a47f6d48d11f"}},
{"id":"9b145fe2d3c13bbb16ce5b7a82001740","key":"9b145fe2d3c13bbb16ce5b7a82001740","value":{"rev":"3-4a713b3d024249a8737d921616dc4d26"}},
{"id":"9b145fe2d3c13bbb16ce5b7a820021a9","key":"9b145fe2d3c13bbb16ce5b7a820021a9","value":{"rev":"2-5a7fd44e20f215c92d0240b86b5ba744"}},
{"id":"_design/medic","key":"_design/medic","value":{"rev":"1-38d25efb208477ba7b347f88218476d7"}},
{"id":"_design/medic-admin","key":"_design/medic-admin","value":{"rev":"1-38489089baa73a423aedef67b95b9b7f"}},
{"id":"_design/medic-client","key":"_design/medic-client","value":{"rev":"2-3e2ad25bb09015bcb90db59f9dc3c492"}},
{"id":"_design/medic-conflicts","key":"_design/medic-conflicts","value":{"rev":"1-1b58225c3445e1d231744709a8da4beb"}},
{"id":"_design/medic-scripts","key":"_design/medic-scripts","value":{"rev":"1-acaab43b66da75cd754508d36a9530b4"}},
{"id":"_design/medic-sms","key":"_design/medic-sms","value":{"rev":"1-a3bc44079a73015423ca52325107ceac"}},
{"id":"a561dbfe-f5a2-5b39-9936-a7eaff2270c9","key":"a561dbfe-f5a2-5b39-9936-a7eaff2270c9","value":{"rev":"2-7b3b1f72999a3ed747e81c2101dce963"}},
{"id":"branding","key":"branding","value":{"rev":"1-db13aa8a83fca924eb5793ab5d01d74b"}},
{"id":"d2cf214c-f20d-4170-a619-510f426cf0e8","key":"d2cf214c-f20d-4170-a619-510f426cf0e8","value":{"rev":"3-ed0e4c977fe886be157225994dd6c1e8"}},
{"id":"form:contact:clinic:create____6-9fed59aaa538d5060d63232764f1ca86____tombstone","key":"form:contact:clinic:create____6-9fed59aaa538d5060d63232764f1ca86____tombstone","value":{"rev":"1-bff7d4a3d7fd04e86987909d253605e8"}},
{"id":"form:contact:clinic:edit____3-fb053fa2134269b64119a3f8a9a64698____tombstone","key":"form:contact:clinic:edit____3-fb053fa2134269b64119a3f8a9a64698____tombstone","value":{"rev":"1-d81b1a5068544d4cac8e12015e4c463c"}},
{"id":"form:contact:district_hospital:create____3-060757f48fa01f2bae17e3961ab076a6____tombstone","key":"form:contact:district_hospital:create____3-060757f48fa01f2bae17e3961ab076a6____tombstone","value":{"rev":"1-842a2b948e1b23f7da8c7783de13f6cc"}},
{"id":"form:contact:district_hospital:edit____3-df39253dfea3a3e6df1522db913c148d____tombstone","key":"form:contact:district_hospital:edit____3-df39253dfea3a3e6df1522db913c148d____tombstone","value":{"rev":"1-b005bc49da0dd6cf167db78003b40fda"}},
{"id":"form:contact:health_center:create____3-890abb53194599f9aa173a36bb9c4ff3____tombstone","key":"form:contact:health_center:create____3-890abb53194599f9aa173a36bb9c4ff3____tombstone","value":{"rev":"1-64a0363272b37e6980b80cff02777e93"}},
{"id":"form:contact:health_center:edit____3-712a77c443c64e98755c340ae954faed____tombstone","key":"form:contact:health_center:edit____3-712a77c443c64e98755c340ae954faed____tombstone","value":{"rev":"1-ce7f5d5cf71a803b0a942cea4b796cd7"}},
{"id":"form:contact:person:create____3-4dc0163a7ef78b2e79055e04ca13bf01____tombstone","key":"form:contact:person:create____3-4dc0163a7ef78b2e79055e04ca13bf01____tombstone","value":{"rev":"1-60d19669d8bf8b1eaffe1d4137bc02eb"}},
{"id":"form:contact:person:edit____3-547daa94632f706ed246cfeb3784f1cb____tombstone","key":"form:contact:person:edit____3-547daa94632f706ed246cfeb3784f1cb____tombstone","value":{"rev":"1-4b1bb70a3da6e371a5c66255da05c95e"}},
{"id":"form:death_report____3-7429dc59673e73ec1dbe6aa02385d027____tombstone","key":"form:death_report____3-7429dc59673e73ec1dbe6aa02385d027____tombstone","value":{"rev":"1-331baf9e8ec580d25874fadf97fbd1bb"}},
{"id":"form:delivery____3-92c20dbbb7fba8a2b8338f20e47b670e____tombstone","key":"form:delivery____3-92c20dbbb7fba8a2b8338f20e47b670e____tombstone","value":{"rev":"1-6407fb291e4e47fd137b439acf5507a6"}},
{"id":"form:pnc_danger_sign_follow_up_baby____3-805f455f1192aeedf556892b03c6c411____tombstone","key":"form:pnc_danger_sign_follow_up_baby____3-805f455f1192aeedf556892b03c6c411____tombstone","value":{"rev":"1-1245d74c81e29bac8ce5eeae24a9bd1a"}},
{"id":"form:pnc_danger_sign_follow_up_mother____3-336f91959e14966f9baec1c3dd1c7fa2____tombstone","key":"form:pnc_danger_sign_follow_up_mother____3-336f91959e14966f9baec1c3dd1c7fa2____tombstone","value":{"rev":"1-80954cd950cc7fcb9ba2eba2e09e3ec5"}},
{"id":"form:pregnancy____3-2b7cb3d9fef73e8a4157610e418a8883____tombstone","key":"form:pregnancy____3-2b7cb3d9fef73e8a4157610e418a8883____tombstone","value":{"rev":"1-133520f6e20f4edc1a12310619292785"}},
{"id":"form:pregnancy_danger_sign____3-45553c82564e63fb7c693af717be629a____tombstone","key":"form:pregnancy_danger_sign____3-45553c82564e63fb7c693af717be629a____tombstone","value":{"rev":"1-4eb83007468c35946fe832d2a758ebb2"}},
{"id":"form:pregnancy_danger_sign_follow_up____3-5bf4c88424c57a997bf222317fdb206b____tombstone","key":"form:pregnancy_danger_sign_follow_up____3-5bf4c88424c57a997bf222317fdb206b____tombstone","value":{"rev":"1-45dbf0f6582dc20e0a4124fb7c4d6750"}},
{"id":"form:pregnancy_facility_visit_reminder____3-124d9feaa263439592a7a40ca3a38010____tombstone","key":"form:pregnancy_facility_visit_reminder____3-124d9feaa263439592a7a40ca3a38010____tombstone","value":{"rev":"1-7206b88e854afc1a4b32a98cafff0271"}},
{"id":"form:pregnancy_home_visit____3-b90a4aded44cc71f7b0025f811aa6b12____tombstone","key":"form:pregnancy_home_visit____3-b90a4aded44cc71f7b0025f811aa6b12____tombstone","value":{"rev":"1-ae3bdec557e97d962b584f634382e48f"}},
{"id":"form:undo_death_report____3-f79c4cd8d62c1a84eb4fa2fb38800382____tombstone","key":"form:undo_death_report____3-f79c4cd8d62c1a84eb4fa2fb38800382____tombstone","value":{"rev":"1-9816f6b5856c367f9b203ee95aee9e2f"}},
{"id":"horti-upgrade____13-c9971054f8d29238a313b9232d4f56f5____tombstone","key":"horti-upgrade____13-c9971054f8d29238a313b9232d4f56f5____tombstone","value":{"rev":"1-461ed81cc9c979bf8921ea5d24bc15e3"}},
{"id":"messages-bm","key":"messages-bm","value":{"rev":"1-b4b1e121ddf4bbacb09f9ae245fd7d96"}},
{"id":"messages-en","key":"messages-en","value":{"rev":"3-75d2aa6dfbdc2dfb0f358f285bcbed31"}},
{"id":"messages-es","key":"messages-es","value":{"rev":"1-d38e8afcdd95903d99ad826d59f34c24"}},
{"id":"messages-ex","key":"messages-ex","value":{"rev":"1-382da3ed1f130e75e127d0b056b555f6"}},
{"id":"messages-fr","key":"messages-fr","value":{"rev":"1-d92c7c6b5e939034b1da3f2a9eaa3f27"}},
{"id":"messages-hi","key":"messages-hi","value":{"rev":"2-dbfa1f12359ea4aa3dedb617690df5ec"}},
{"id":"messages-id","key":"messages-id","value":{"rev":"2-4535d6e77640d6af6b56eccc45847e04"}},
{"id":"messages-ne","key":"messages-ne","value":{"rev":"1-075e81ec5813354e6d0448a0b075b442"}},
{"id":"messages-sw","key":"messages-sw","value":{"rev":"2-abf6ea21fd1a8cc43d940c9949980521"}},
{"id":"migration-log","key":"migration-log","value":{"rev":"29-d4032350bd407b839dffd9ccf9aeda7c"}},
{"id":"org.couchdb.user:admin","key":"org.couchdb.user:admin","value":{"rev":"2-6fbe8767752ef71e1c4322c5996588b4"}},
{"id":"org.couchdb.user:clif","key":"org.couchdb.user:clif","value":{"rev":"1-d4a307c825add1fc0e6bd5aded5a346c"}},
{"id":"org.couchdb.user:gcliff","key":"org.couchdb.user:gcliff","value":{"rev":"1-6842edbb1322f0ac9ba1a87f580d0f8d"}},
{"id":"org.couchdb.user:horticulturalist","key":"org.couchdb.user:horticulturalist","value":{"rev":"2-a992c018de24ad98e04b137760cddab6"}},
{"id":"org.couchdb.user:medic","key":"org.couchdb.user:medic","value":{"rev":"4-05b9a43c9721e4ed069676d9bff9d3c0"}},
{"id":"org.couchdb.user:medic-api","key":"org.couchdb.user:medic-api","value":{"rev":"2-c00baed13bb97410d5005685bd92899b"}},
{"id":"org.couchdb.user:medic-couch2pg","key":"org.couchdb.user:medic-couch2pg","value":{"rev":"2-45f4075bce134d0d66083126d82c5c6e"}},
{"id":"org.couchdb.user:medic-sentinel","key":"org.couchdb.user:medic-sentinel","value":{"rev":"2-10f3cae3adec3a71e74c8cf69d6a1b30"}},
{"id":"privacy-policies","key":"privacy-policies","value":{"rev":"1-3c88431a93c8905d5eec41ce68d8868a"}},
{"id":"resources","key":"resources","value":{"rev":"3-e1b7e8de7c90d6b95e2ef8846890b90e"}},
{"id":"service-worker-meta","key":"service-worker-meta","value":{"rev":"1-d79fee6b9d89d2000d95b92e094fa495"}},
{"id":"settings","key":"settings","value":{"rev":"3-41cf2fa0376aff71651a7d96e6f1086e"}}
]}

hello @diana
i did create the report but the message state is in forwarded-by-gateway i have selected the message in the getway and retried sending it to the recipient but its not being recieved

Hi @cliff

To get contacts, there are a variety of views that can be used. For getting the shortcodes (place_ids and patient_ids), I suggest using the contacts_by_reference view:
https://medic:password@192-168-115-70.my.local-ip.co/medic/_design/medic-client/_view/contacts_by_reference

Does the gateway phone have enough credit to be able to send SMS? Do you see any logs in the gateway app?
Some helpful documentation explaining what these statuses mean:

thanks @diana for the url …

i had used curl https://medic:password@192-168-115-70.my.local-ip.co/medic/_design/medic-client/_view/contacts_by_parent?include_docs=true to get the details

yes i do have SMS bundles loaded

i only see FAILED( generis: no errorCode supplied) in the FROM WEBAPP section of the getway

Thanks for the docs

my bad @diana ,my SMS had expired ,

its working fine now

Thanks for your technical support in this community

2 Likes

hello @diana @samuel

I would like the locally implement an sms messaging where a user sends an sms to the server through the gate and then the server has an automatic response the gives back depending on what message the user sends like for SMS forms forexample a user sends Hi and the server automatically responds with Hi
Is there a way this is configured in the app-settings file?,been looking into the docs but havent landed on something that can best guide on this

Thanks

Hi @cliff

This was a fun idea that I never actually tried before.
What I did:

  1. I enabled default_responses transition
  2. Configured default_responses to add an automatic response to every unstructured sms (an sms that doesn’t match a configured form):
"default_responses": {
   "start_date": "2018-01-01"
},
  1. Changed the translation for sms_received (the translation key that the transition uses) to echo the message of the original SMS, and add three dots at the end:
{{sms_message.message}}...

image

And now my server responds with “Hi…” :slight_smile:

Please beware that the server will respond to any unstructured SMS, echoing the original message, if you enable this.

1 Like

If you would like a specific response, depending on the original message, you would have to somehow match a form and add a registration transition with a report_accepted message for that form.

1 Like

This sounds like interactive messaging, which is a key feature of RapidPro. RapidPro integrates with the CHT and you could use it for your interactive messaging workflows while maintaining registration and reporting workflows in the CHT core framework.

2 Likes

Hello @diana ,does “start_date”: “2018-01-01” mean ? according to the transitions docs it looks not to be clearly explained …
I did leave it as it is and added sms_received = {{sms_message.message}}... in my en translation file, uploaded the app settings but not getting back the auto sms
I have tried editing default_responses with "translation_key": "sms_received" with sms_received = {{sms_message.message}}... in my en translation file but still no auto sms yet …