Skip to main content

Sending templated messages

Once you have successfully created a message template, you can use it to send out messages. Such templated messages can be sent through either 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:

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

  • Include the recipient's phone number.
  • Select the transaction stream you wish to use to send the message. Check out 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 are using the otp-docs-test template in the picture above.
  • 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".
note

Make sure that you are familiar with your template's model values to define them properly. Refer to Template syntax to understand how Falu interprets a template's values.

  • Select whether you want to send the message immediately or at a later time.

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"
}