簡體   English   中英

使用雲 api whatsapp 和 google app 腳本發送消息

[英]Send message with cloud api whatsapp and google app script

Meta最近發布了雲api來發送Whatsapp業務的消息,但是我無法從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)
            
    }

同樣的事情發生在我身上,答案是正確的,但消息沒有到達,只有 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

在此處輸入圖像描述

只有批准的模板才能作為第一條消息從 whatsapp API 帳戶/電話號碼發送,請嘗試將任何消息發送回 api whatsapp 帳戶/電話號碼,由您在上述腳本中向其發送消息的收件人發送消息,然后運行腳本,它通過這樣做為我運行。


暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM