Vonage / vonage-node-sdk

Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Apache License 2.0
375 stars 178 forks source link

Cannot send Whatsapp auth template message #863

Closed Ahmad0811 closed 8 months ago

Ahmad0811 commented 10 months ago

Im trying to send whatsapp auth message using WhatsAppTemplate which attaching one param and it returns missing params always in the webhook. also there is no clear documentation for how to send a message

vonage.messages.send(
    new WhatsAppTemplate(
        {
            whatsapp: { locale: 'en', policy: 'deterministic' },
            from: 'sender_number',
            to: 'reciver_number',
            clientRef: 'Whatsapp Auth',
            template: {
                name: `${'app_id'}:${'template_name'}`,
                parameters: [
                    '1',
                ],
            },

        },

    ),
)
dahabit commented 10 months ago

I have the same issue , and I followed the documentation with no luck

Ahmad0811 commented 9 months ago

I made it work using

const { WhatsAppCustom } = require('@vonage/messages');

and then add this to message.send function

new WhatsAppCustom(
            {
                clientRef: 'TemplateName',
                from: 'SenderPhoneNumber',
                to: 'ReciverPhoneNumber',
                custom: {
                    type: 'template',
                    template: {
                        namespace: 'TemplateNameSpace:',
                        name: 'TemplateName',
                        language: {
                            policy: 'deterministic',
                            code: 'en',
                        },
                        components: [
                            {
                                type: 'body',
                                parameters: [
                                    {
                                        type: 'text',
                                        text: '12345',
                                    },
                                ],
                            },
                            {
                                type: 'button',
                                sub_type: 'url',
                                index: '0',
                                parameters: [
                                    {
                                        type: 'text',
                                        text: '12345',
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        ),
superchilled commented 8 months ago

Hi @Ahmad0811 the second example you posted is correct. With the Messages API, the template message type of the whatsapp channel (which is the WhatsAppTemplate object in the Node SDK) is only for sending static templates. For interactive templates (which includes Authentication templates) you need to use the custom message type (which is the WhatsAppCustomobject in the Node SDK).

I agree that the documentation could be improved around this, and I'm currently working on doing that. I did recently add a Code Snippet example for sending an Authentication Template, but it's currently only in cURL (I still need to add the other language variants).

manchuck commented 8 months ago

I'm going to close this issue since it is an issue with the documentation and not the SDK.