无法通过 WhatsApp Business API 发送消息

问题描述 投票:0回答:1

我正在尝试使用 WhatsApp Business API 和 GraphQL 发送 WhatsApp 消息。

但我收到此错误:

Failed to send message to : 
{
    "error":{
        "message":"(#132012) Parameter format does not match format in the created template",
        "type":"OAuthException",
        "code":132012,
        "error_data": {
            "messaging_product":"whatsapp",
            "details":"header: Format mismatch, expected IMAGE, received UNKNOWN"
        },
        "fbtrace_id":"AyPLLsvyikPmg66DWF_ZfYU"
    }
}

这是我写的代码。我也在分享消息结构。

import requests
import openpyxl


access_token = ""
template_name = "healthy_sports_b2s_2"  # Replace with your template name
language_code = "en"


wb = openpyxl.load_workbook("numbers.xlsx")
sheet = wb.active


for row in sheet.iter_rows(min_row=2, values_only=True):
    customer_number = row[0]
    url = f"https://graph.facebook.com/v17.0/XXXXXXXXXXXXXXX/messages"

    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json",
    }

    message_payload = {
        "messaging_product": "whatsapp",
        "to": customer_number,
        "type": "template",
        "template": {"name": template_name, "language": {"code": language_code}},
        "components": [
            {
                "parameters": [
                    {
                        "type": "template",
                        "image": {
                            "link": "https://res.cloudinary.com/dapnrioqr/image/upload/v1691648851/02_wgucrp.jpg"
                        },
                    }
                ]
            }
        ],
    }

    response = requests.post(url, json=message_payload, headers=headers)
    if response.status_code == 200:
        print(f"Message sent to {customer_number}")
    else:
        print(f"Failed to send message to {customer_number}: {response.text}")

我可以做什么来解决这个问题

This is the actual message

python facebook-graph-api graphql whatsapp
1个回答
0
投票

消息模板的截图还不够,您需要显示编辑模板中的模板设置,您已在其中添加了参数。

我可以在请求中的标头组件中看到问题,应该提供组件的类型

header
和参数的类型
image

"components": [
  {
    "type": "header",
    "parameters": [
      {
        "type": "image",
        "image": {
          "link": "https://res.cloudinary.com/dapnrioqr/image/upload/v1691648851/02_wgucrp.jpg"
        }
      }
    ]
  }
]

如果错误仍然存在,那么您需要查看文档

© www.soinside.com 2019 - 2024. All rights reserved.