Is there a way to disable SMS recipient redirection?

According to the documentation on SMS recipient resolution:

* if recipient resolution does not yield a phone number, it will default to submitter’s phone number

Can we disable this SMS redirection?

In my project, a patient can be registered with or without a phone number.

If the patient is registered with a phone number, I want to send a message to the patient at the time of registration, and every time a new form is submitted for the patient. It is working fine using the configurations for registrations and patient_reports.

However, if the patient does not have a phone number, it sends the same message to the submitter. I don’t want it. The message shouldn’t go out if the patient doesn’t have a phone number. How can I achieve this?

Sample configuration:


"registrations": [
    {
      "form": "A",
      "events": [...],
      "validations": {...},
      "messages": [
        {
          "translation_key": "messages.registration.a.clinic",
          "event_type": "report_accepted",
          "recipient": "clinic"
        },
        {
          "translation_key": "messages.registration.a.patient",
          "event_type": "report_accepted",
          "recipient": "patient.phone"
        }
      ]
    }

Here, the message intended for the patient (messages.registration.a.patient) should only go to the patient, provided that patient.phone is available. Otherwise, this message should be skipped.

I have found a workaround for this.

In the message translation, I can use Mustache templating to conditionally set the message:

messages.registration.a.patient = {{#patient.phone}} Hi {{patient_name}}! You have been registered to our system with ID: ({{patient_id}}). {{/patient.phone}}{{^patient.phone}}{{/patient.phone}}

If patient.phone is unavailable, it gives an empty message, which results in an error: messages.errors.message.empty.

{
...
  "messages": [
    {
      "uuid": "...",
      "to": "...",
      "error": "messages.errors.message.empty"
    }
  ],
  "state_history": [
    {
      "state": "pending",
      "timestamp": "2024-08-30T10:49:46.208Z"
    }
  ],
  "state": "pending"
}
1 Like

If used with scheduled messages, this can result in error and other scheduled messages can also get stuck.

I no longer suggest this workaround. We need a way to configure it from CHT so that if a recipient is not found, that message will not be sent.

Thanks @yuv for investigating this and letting me know.

1 Like

Hi @binod , given so many instances are using this already and there are messages still in scheduled state past their due date, I’ve opened a ticket to work on sending schedules to clear if they can not be sent to pending state. Hope that will be helpful and not require you to change existing configs in deployments.

1 Like

I have added a feature request here: