Vonage / vonage-node-code-snippets

NodeJS code examples for using Vonage
MIT License
67 stars 78 forks source link

Invalid parameter for media template #122

Closed Suryalg closed 1 year ago

Suryalg commented 1 year ago

Expected Behavior

Template is active so message shall go

Current Behavior

Invalid parameter

Possible Solution

Steps to Reproduce

vonage.messages.send(
            new TemplateMessage(
                {
                    name: `${WHATSAPP_TEMPLATE_NAMESPACE}:${WHATSAPP_TEMPLATE_NAME}`,
                    components: [
                        {
                            "type": "header",
                            "parameters": [
                              {
                                "type": "image",
                                "image": {
                                  "link": "https://cdn.dineorder.com/whatsapp-templates/kuick.png"
                                }
                              }
                            ]
                        },
                        {
                            type: 'body',
                            parameters: [],
                        },
                    ],
                },
                {
                    policy: 'deterministic',
                    locale: 'en',
                },
                TO_NUMBER,
                WHATSAPP_NUMBER,
            )
        )
        .then(resp => console.log(resp.message_uuid))
        .catch(err => {console.error(err); console.log(err.response.data.invalid_parameters)});
dragonmantank commented 1 year ago

For this structure, you will want to look at a CustomMessage type instead of a TemplateMessage. TemplateMessage only allows you to specify a template and the parameters in order without specifying the actual component sections.

If you are specifying the sections, you'll need to use a CustomMessage. See https://github.com/Vonage/vonage-node-code-snippets/blob/master/messages/whatsapp/send-media-template.js for more information.