Send message with cloud api whatsapp and google app script
Meta recently released the cloud api to send messages from Whatsapp business, but I can't send it from the google app script.
I have this code, it runs fine... but it doesn't reach the user
function SendToUser() { var headers = { 'Authorization' : 'Bearer ACCESS_TOKEN', 'Content-Type': 'application/json' }; var payload = { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "PHONE_NUMBER", "type": "text", "text": { // the text object "preview_url": false, "body": "MESSAGE_CONTENT" } } var options = { method: "POST", headers: headers, payload: JSON.stringify(payload) // <--- Modified } let response = UrlFetchApp.fetch("https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages", options); Logger.log(response) }
See this project...
https://github.com/pro-cms/whatsappcloud-php
This work for me :)
Its google app script
The same thing happens to me, the answer is correct but the message does not arrive, only the example of the Hellow_Word template is working, the others are not.
only approved templates can be sent as first message from whatsapp API account/phone number, try sending any message say 'Hi' back to api whatsapp account/phone number by the recipient to whom you were sending the message in the above script and then run the script, it runs for me by doing this.
dear friends of the stackoverflow community, The official documentation indicates that in order to send such messages, the conversation must be initiated by the user. https://developers.facebook.com/docs/whatsapp/conversation-types
Kudos man this is the correct answer. Spam prevention!
This is an incorrect answer, the documentation indicate you need a pre-approved template by the meta developer team.
Have look at Heyooh, it's a Javascript Wrapper for WhatsApp Cloud API
Installation
npm install heyoohHere how sending to send messages;
import WhatsApp from heyhooh let messenger = new WhatsApp('TOKEN', phone_number_id='104xxxxxx') messenger.send_template("hello_world", "255757xxxxxx")Its google app script