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)                  } 

Tag:google-apps-script, api, whatsapp

9 comments.

  1. Jones Heckler

    See this project...

    https://github.com/pro-cms/whatsappcloud-php

    This work for me :)

    1. MT Designer

      Its google app script

  2. Leandro Ascierto

    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.

  3. Ashutosh Pathak

    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.

  4. apositivo

    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

    1. Stephen Mudere

      Kudos man this is the correct answer. Spam prevention!

    2. Albert Hidalgo

      This is an incorrect answer, the documentation indicate you need a pre-approved template by the meta developer team.

  5. Jordan Kalebu

    Have look at Heyooh, it's a Javascript Wrapper for WhatsApp Cloud API

    Installation

    npm install heyooh

    Here how sending to send messages;

    import WhatsApp from heyhooh let messenger = new WhatsApp('TOKEN', phone_number_id='104xxxxxx') messenger.send_template("hello_world", "255757xxxxxx")
    1. MT Designer

      Its google app script

Add a new comment.