Sending templated messages

Use a template to send a message


Once you have successfully created a message template, you can use it to send messages through the Dashboard or Messaging API.

Sending templated messages through the Dashboard

Follow these steps to send a message using a predefined template:

  1. Navigate to _Messaging >> Messages >> Create Message _ on your dashboard.
  2. Provide the appropriate details in the next window.

images-docs-messages-templates-send-templated-message-dashboard

  • Include the recipient's phone number.
  • Select the messaging stream you wish to use to send the message. Visit Using message streams for more information on the different Falu message streams.
  • Select the message template you wish to use to compose your message. For example, we use the otp-docs-test template in the above picture.
  • Input the template's model values. For example, the otp-docs-test template requires an otp_Value, which, when given a value such as 99921, results in the message: "Your new test OTP code is: 99921".
  • Select whether you want to send the message immediately or later.

Sending templated messages using the API

You can send a templated message using Falu's messaging API by making the following POST call:

curl -X POST 'https://api.falu.io/v1/messages' \
--header 'Authorization: Bearer ' \
--header 'X-Falu-Version: 2022-09-01' \
--header 'Content-Type: application/json' \
--data '{
    "to":" ",
    "template":{
        "id":" ",
        "model":{
          "key":"value"
        }
    },
    "stream":" "
}'

For example, if we defined a template otp-docs-test as follows:

curl -X POST 'https://api.falu.io/v1/message_templates' \
--header 'Authorization: Bearer MY_SECRET_KEY' \
--header 'X-Falu-Version: 2022-09-01' \
--header 'Content-Type: application/json' \
--data '{
 "alias":"otp-test",
 "description":"For documentation reference",
 "body":"Your test OTP code is: {{otp}}"
}

We would send a message as:

curl --location 'https://api.falu.io/v1/messages' \
--header 'Authorization: Bearer MY_SECRET_KEY' \
--header 'X-Falu-Version: 2022-09-01' \
--header 'Content-Type: application/json' \
--data '{
    "to":"+254SOME_NUMBER",
    "template":{
        "id":"mtpl_2sx5PxlhkU3iTD2LgXF8dbW2uM3",
        "model":{
          "otp":"99923"
        }
    },
    "stream":"transactional"
}