使用云 api whatsapp 和 google app 脚本发送消息

Meta最近发布了从Whatsapp业务发送消息的云api,但我无法从google app脚本发送。

我有这段代码,它运行良好......但它没有到达用户

    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)

    }
stack overflow Send message with cloud api whatsapp and google app script
原文答案

答案:

作者头像

同样的事情发生在我身上,答案是正确的,但消息没有到达,只有 Hellow_Word 模板的例子在工作,其他的都没有。

作者头像

看到这个项目...

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

这对我有用:)

作者头像

看看 Heyooh ,它是 WhatsApp Cloud API 的 Javascript Wrapper

安装

npm install heyooh

这里如何发送发送消息;

import WhatsApp from heyhooh
let messenger = new WhatsApp('TOKEN',  phone_number_id='104xxxxxx')
messenger.send_template("hello_world", "255757xxxxxx")
作者头像

stackoverflow 社区的各位亲爱的朋友们,官方文档指出,要发送此类消息,对话必须由用户发起https://developers.facebook.com/docs/whatsapp/conversation-types

enter image description here

作者头像

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.