Scheduled messages

Scheduled messages are not sent to recipients.

How To Reproduce The Issue

  1. Add schedules key in app_settings.json file
    “schedules”: [
    {
    “name”: “ANC Visit Reminders”,
    “messages”: [
    {
    “translation_key”: “messages.schedule.registration.followup_anc_pnc”,
    “group”: 1,
    “offset”: “2 minutes”,
    “recipient”: “parent”
    }
    ]
    },

  2. Add translation key to messages-en.properties
    messages.schedule.registration.followup_anc_pnc = Test message here. ANC follow up message

  3. Add registrations key to app_settings.json
    “registrations”: [
    {
    “form”: “pregnancy”,
    “events”: [
    {
    “name”: “on_create”,
    “trigger”: “assign_schedule”,
    “params”: “ANC Visit Reminders”
    }
    ],
    “validations”: {},
    “messages”: []
    }
    ],

  4. Run cht command to update settings
    cht --url=https://:@localhost --accept-self-signed-certs compile-app-settings backup-app-settings upload-app-settings

Expected Behavior
I expected to receive message in parents phone number and have scheduled message on app management section>outgoing message. But nothing happens after I register a pregnancy

Hi @Julius_Karanja

Thanks a lot for reporting.
I’m linking the relevant documentation here, that I will be referring to: .schedules | Community Health Toolkit

It appears that there’s an inconsistency between our documentation and our code, where the code requires that the start_from is defined and does not have a default value.
I’m leaning to think that the documentation is correct, so I’ll file this as a bug.
In the meantime, can you try updating your schedule configuration to include start_from and try again?

"schedules": [
      {
        "name": "ANC Visit Reminders",
        "start_from": "reported_date",
        "messages": [
          {
            "translation_key": "messages.schedule.registration.followup_anc_pnc",
            "group": 1,
            "offset": "2 minutes",
            "recipient": "parent"
          }
        ]
      },
]

You should be able to see your scheduled message both on the report detail page an in the app management → outgoing message → scheduled (or due, in case enough time has passed that it becomes due).

Added the issue: Schedules don't have a default value for `start_from` · Issue #7425 · medic/cht-core · GitHub

Thank you @diana for your response. It works when I add start_from value reported_date. However, when I change it to lmp_date, no scheduled message appear after registering a pregnancy.

Here is the config:

“registrations”: [
{
“form”: “pregnancy”,
“events”: [
{
“name”: “on_create”,
“trigger”: “assign_schedule”,
“params”: “Scheduled messages”
}
],

“schedules”: [
{
“name”: “Scheduled messages”,
“start_from”: “lmp_date”,
“messages”: [

    {
      "translation_key": "messages.schedule.lmp.monday.week_5",
      "group": 1,
      "offset": "5 weeks",
      "send_day": "monday",
      "send_time": "09:00",
      "recipient": "patient.phone"
    },{
      "translation_key": "messages.schedule.lmp.thursday.week_5",
      "group": 1,
      "offset": "5 weeks",
      "send_day": "thursday",
      "send_time": "09:00",
      "recipient": "patient.phone"
    },
   .......

Please not I have messages offset upto 42 weeks

Are you sure lmp_date field exists on your report?

This is the form am using for pregnancy registration.

And lmp_date is calculated automatically regardless of the option user picks. Correct me if am wrong

I can’t tell what the field is called or how it gets calculated from a form screenshot :slight_smile:
Can you please share the form XML or XLS? Or confirm that you’re using default config.

Thanks :slight_smile:

I am using default config

Then the default config pregnancy form doesn’t have a field name lmp_date. You need to use the exact field path to get the schedule to work.
Can you please try using lmp_date_8601?

lmp_date_8601 doesn’t work either. No scheduled messages created.

Happy new year @diana
Were you able to find a solution for this issue?

Hi

It should work with fields.lmp_date_8601.
One thing to note is that scheduled messages with a due date in the past will not get created.
When creating a pregnancy, your last menstrual period will be in the past, so you need to increase the offset in your config to generate a message. For example, I set mine to 5 months.

 "schedules": [
      {
        "name": "Message Contact",
        "start_from": "fields.lmp_date_8601",
        "messages": [
          {
            "translation_key": "messages.place.msg",
            "group": 1,
            "offset": "5 months",
            "send_day": "",
            "send_time": "",
            "recipient": "place.contact.phone"
          }
        ]
      }
    ],
    "registrations": [
      {
        "form": "pregnancy",
        "events": [
          {
            "name": "on_create",
            "trigger": "assign_schedule",
            "params": "Message Contact",
            "bool_expr": "true"
          }
        ]
      }
    ],

Please make sure you test the config against a new report. Transitions only run once per every document.

Also, Happy new year @Julius_Karanja !

Thank you this one works.

What should be the field name for delivery registrations form. I tried delivery_date it didn’t add records to scheduled messages

You can check the contents of the report document in CouchDB to get a better idea of which fields to pick.