Reputation: 1441
I have installed MessageBird Firebase Extension. I want to send Whatsapp template(template has Button with website link) message from Firebase Cloud Functions.
To send a Whatsapp message, I need to create a document in Firebase 'messages' collection, so that MessageBird extension processes it.
What should be the format of Firebase document to send Whatsapp message? I have attached the Whatsapp template
I have tried creating Firebase document similar to this API request format - https://developers.messagebird.com/quickstarts/whatsapp/send-message-with-buttons/, but I got delivery error 'Error: api error(s): JSON is not a valid format (code: 21)'.
Thank you.
Upvotes: 0
Views: 1790
Reputation: 281
For using content variable and button variable same time, you need use component field:
{
"to": "RECEIVER",
"from": "SENDER",
"type": "hsm",
"content": {
"hsm": {
"namespace": "c24c325c_example",
"templateName": "example",
"language": {
"code": "en"
},
"components": [
{
"type": "button",
"sub_type": "url",
"parameters": [
{
"type": "text",
"text": "&from=whatsapp"
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Hi"
}
]
}
]
}
}
Upvotes: 0
Reputation: 74
You are right, you need to put a document with content into Firestore message collection that is accepted by ConversationsAPI, and then the message should be sent and the document should be updated with delivery details (response from MessageBird Conversations API).
This is example of the document that you will need to put to be able to send WA template message:
db.collection('YOUR_DOCUMENT_COLLECTION').add({
channelId: 'YOUR_CHANNEL_ID',
type: 'hsm',
content: {
hsm: {
namespace: 'YOUR_WA_ACCOUNT_NAMESPACE_ID',
templateName: 'YOUR_WA_TEMPLATE_NAME',
params: [{ default: 'YOU_PARAM_VALUE' }],
language: { code: 'en_US', policy: 'deterministic' }
}
},
to: 'RECIPIENT_OF_THE_MESSAGE',
});
You can find more details about HSM object and what each field means here: https://developers.messagebird.com/api/conversations/#messagehsm-object
I hope that helps.
Upvotes: 0