0

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 templateenter image description here

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.

Krishna Shetty
  • 1,361
  • 4
  • 18
  • 39

2 Answers2

0

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.

NIBERIUM
  • 76
  • 6
  • Does this work for the template with action button? How to pass button url parameter? – Krishna Shetty Oct 26 '22 at 12:08
  • MessageBird firebase extension doesn't work. I have created a simple whatsapp template, and tried send a message, it updates 'state' in 'delivery' as SUCCRSS in the documents. But it actually doesn't send the message!! There is no information on what went wrong! Very unreliable – Krishna Shetty Oct 27 '22 at 13:52
0

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