WhatsApp Template Error
# 🤝help
Hi, I'm trying to send a message from my bot to a WhatsApp template and I always get the same error: "An unexpected error ocurred". I add some pictures so you can see template and bot configuration. I thinks it's a JSON parameter problem because I have tried with a plain template and it works perfect but when I want to send a parameter from the bot to the template I always get the same error. Thanks in advance!!
thnks for the link! I have tried multiple ways of setting the info into de Template Variables JSON: - ["Iñaki"] - Iñaki - "Iñaki" - [ {{event.tags.user['whatsapp:name'] }}] With the last one I get this error: An error occured while executing an integration action: Value provided for Template Variables JSON isn't valid JSON (error: Unexpected token I in JSON at position 2). Received: [ Iñaki]}) But the arguments seems rigth: { "userPhone": "+34648258558", "templateName": "new_experience", "templateVariablesJson": "[ Iñaki]", "templateLanguage": "en_US" } Don't know what more to test 😔
This is the way I created the variable and it worked workflow.textvariable =
Refer to the image as the grave accent symbol is not shown in Discord While the variable is set correctly and I am passing the value, it still will give me this error
Copy code
[2906416d17]    [dm]    :     An unexpected error occurred.
  [Error, Failed to start Whatsapp conversation using template "sendhello1" and language "en_US" - Error: {"message":"(#132000) Number of parameters does not match the expected number of params","type":"OAuthException","code":132000,"error_data":{"messaging_product":"whatsapp","details":"header: number of localizable_params (0) does not match the expected number of params (1)"},"fbtrace_id":"A1T1WvbMLVKOcsbCQNPN6xf"}]
Expected params are 0 and received 1. This means in the body there were no parameters required and it received one This problem is related Start Conversation Card of WhatsApp in Botpress, it cannot send variables to the header and footer
To solve this you have to send it it via axios.post like this workflow.textvariable = "Noemi" const url = 'https://graph.facebook.com/v17.0/Phone_number_ID/messages' const data = { messaging_product: 'whatsapp', to: user.phonenumber, recipient_type: 'individual', type: 'template', template: { name: 'sendhello1', language: { code: 'en_US' }, components: [ { type: 'header', parameters: [ { type: 'text', text: workflow.textvariable } ] } ] } } console.log('Payload ', data) const headers = { Authorization:
Bearer ${bot.fbtoken}
, 'Content-Type': 'application/json' } axios .post(url, data, { headers }) .then((response) => { console.log('Message sent successfully:', response.data) }) .catch((error) => { console.error('Error sending message:', error.response.data) })` In this code, there is nothing passed to the body, but to the header parameter workflow.textvariable is passed into which Noemi was assigned at the very top This works the message is sent successfully. Below is the log Here is the Payload - from console.log('Payload', data)
Copy code
Payload { messaging_product: 'whatsapp',
  to: 'xxxxxxxxxxx',
  recipient_type: 'individual',
  type: 'template',
   { name: 'sendhello1',
     language: { code: 'en_US' },
     components: [ [Object] ] } }
and here is the success message
Copy code
Message sent successfully: { messaging_product: 'whatsapp',
  contacts: [ { input: 'xxxxxxx', wa_id: 'xxxxxxxxxxxxx' } ],
   [ { id: 'wamid.HBgMOTE5NzQxMzkxNzAwFQIAERgSMzIwRUEwNjYwQzg2QUU2MDZDAA==',
       message_status: 'accepted' } ] }
You can use the code as is by replacing Phone_number_ID and bot.fbtoken with yours
Message received
wow @limited-pencil-78283 incredible work and thank you so much for the effort!! Just one more question. If I have understood there is no option to invoque the Template from the card, right? Because I have tried this and still don't work:
There is, but not with variables in header and footer
Why don't you edit the template to have Hi Neomi in the body instead of the header and the card will work
As I mentioned above, the card is not sending value to variables to the header or footer of the message, but to the body. So if you shift the variable to the body, it will work
ok now I got it. Just delete the variable in the header and add it into the body. I'm going to test it and let you know the result. Apreciate your time, thanks!!
Did it @limited-pencil-78283 , just deleted the header parameter and it worked. Even I have added 5 parameters into the body and everything has worked perfect. Thank you so much for your help!!! Have a nice day!