如何在whatsapp云api中发送组件?

Sar*_*kar 1 php api curl

我想在whatsapp云api中发送参数。我怎样才能做到这一点。

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

我想要这样的

{
      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 },
            ],
          },
        ],
      },
    }
Run Code Online (Sandbox Code Playgroud)

我收到的错误

{“error”:{“message”:“(#132000)参数数量与预期参数数量不匹配”,“type”:“OAuthException”,“code”:132000,“error_data”:{“messaging_product” :"whatsapp","details":"body: localized_pa​​rams 的数量 (0) 与预期的参数数量 (3) 不匹配"},"error_subcode":2494073,"fbtrace_id":"Abab9mTp_dJ9Ryd4ytHPl7Y"}}

Sha*_*i M 6

首先,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"
        }]
    }],
}});
Run Code Online (Sandbox Code Playgroud)

您的输出消息将是 URL - https://www.whatsapp.com