簡體   English   中英

如何在whatsapp cloud api中發送組件?

[英]How to send the components in whatsapp cloud api?

我想在whatsapp cloud api中發送參數。 我怎樣才能做到這一點。

$messageData = array(
        'messaging_product' => "whatsapp",
        'to' => "123456789",
        'type' => "template",
        'template' => array("name"=> "hello_world",'language'=>array("code"=>"en_Us")),
    );

我想要這樣

{
      type: 'template',
      messaging_product: 'whatsapp',
      to: e.recipient_number,
      template: {
        name: WHATSAPP_TEMPLATE_NAME,
        language: { code: LANGUAGE_CODE },
        components: [
          {
            type: 'body',
            parameters: [
              { type: 'text', text: e.customer_name },
              { type: 'text', text: e.item_name },
              { type: 'text', text: e.delivery_date },
            ],
          },
        ],
      },
    }

我得到的錯誤

{"error":{"message":"(#132000) 參數數量與預期的參數數量不匹配","type":"OAuthException","code":132000,"error_data":{"messaging_product" :"whatsapp","details":"body: localizable_params (0) 的數量與預期的參數數量 (3) 不匹配"},"error_subcode":2494073,"fbtrace_id":"Abab9mTp_dJ9Ryd4ytHPl7Y"}}

首先, hello_world模板是一個預定義的模板,由 Whatsapp 業務 API 團隊創建。 如果您需要發送參數,您必須創建一個模板,其主體中包含變量,例如

網址 - {{1}}

然后像這樣傳遞參數,

 var data = JSON.stringify({
"messaging_product": "whatsapp",
"to": number,
"type": "template",
"template": {
  "name": "template_name",
  "language": {
    "code": "language_code"
  },
  "components": [
    {
        "type": "body",
        "parameters": [{
            "type": "text",
            "text":"https://www.whatsapp.com"
        }]
    }],
}});

您的輸出消息將是 URL - https://www.whatsapp.com

$messageData = array(
    'messaging_product' => "whatsapp",
    'to' => 123456789,
    'type' => "template",
    'template' => array("name"=> "random name",'language'=>array("code"=>"en_Us"),'components'=> 
       array(array(
        "type" => "body",
        "parameters" => array(array("type"=> "text","text"=> google.com),array("type"=> "text","text"=> $shopName),array("type"=> "text","text"=> 123456789)))))
);

從上面的“薩卡的回答,

{
  "messaging_product": "whatsapp",
  "to": 123456789,
  "type": "template",
  "template": {
    "name": "random name",
    "language": {
      "code": "en_Us"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text"
          },
          {
            "type": "text"
          },
          {
            "type": "text",
            "text": 123456789
          }
        ]
      }
    ]
  }
}

暫無
暫無

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

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