Home > Software design >  Send message with cloud api whatsapp and google app script
Send message with cloud api whatsapp and google app script

Time:05-24

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

CodePudding user response:

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.

CodePudding user response:

See this project...

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

This work for me :)

CodePudding user response:

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")
  • Related