我正在尝试为 Whatsapp 业务创建消息模板,但不断收到错误消息。根据文档,我认为我的实现是正确的。如果不包含按钮(具有动态内容,则在元仪表板上非常容易,但在这里我尝试使用具有动态内容的按钮,这在仪表板上是不可能的,所以我必须采用卷曲方式,但它不起作用。下面是我的实现(不得不切换到Python,认为我可能会做一些事情)
import requests
from requests.structures import CaseInsensitiveDict
url = "https://graph.facebook.com/v20.0/whatsapp_busines_id/message_templates"
headers = CaseInsensitiveDict()
headers["Authorization"] = "Bearer YOUR_ACCESS_TOKEN"
headers["Content-Type"] = "application/json"
data = """
{
"name": "payment_success_property_contact",
"language": "en",
"category": "UTILITY",
"components": [
{
"type": "HEADER",
"format": "TEXT",
"text": "Payment Successful"
},
{
"type": "BODY",
"text": "Hi there! Great news! Your payment for \"{{1}}\" is successful. Please contact the owner via WhatsApp or normal call to visit and check the property. After your visit, you can confirm or cancel the payment.\n\nEnjoy your visit!",
"example": {
"body_text": [
"Seaside Villa"
]
}
},
{
"type": "FOOTER",
"text": "Nanohunt Software"
},
{
"type": "BUTTONS",
"buttons": [
{
"type": "URL",
"text": "Contact via WhatsApp",
"url": "https://wa.me/{{2}}",
"example": {
"parameters": [
{
"type": "text",
"text": "YOUR_PHONE_NUMBER"
}
]
}
},
{
"type": "PHONE_NUMBER",
"text": "Call Owner",
"phone_number": "{{2}}",
"example": {
"parameters": [
{
"type": "text",
"text": "YOUR_PHONE_NUMBER"
}
]
}
},
{
"type": "URL",
"text": "Confirm or Cancel Payment",
"url": "{{3}}",
"example": {
"parameters": [
{
"type": "text",
"text": "https://yourwebsite.com/transaction/TRANSACTION_ID"
}
]
}
}
]
}
]
}
"""
resp = requests.post(url, headers=headers, json=data)
print(resp.json())
所以运行后我得到了
mbishu@fedora:~/Desktop/nanohuntapi$ python template.py
{'error': {'message': '(#100) The parameter name is required.', 'type': 'OAuthException', 'code': 100, 'fbtrace_id': 'AywCoC2brI1L5kRVmtbHD-c'}}
我到目前为止在互联网上搜索但没有可行的解决方案
我遇到了同样的错误,经过一番挖掘文档后,我发现了this:
"type": "body",
"parameters": [
{
"type": "text",
"paramter_name": "customer_name", // This is what we've missed
"text": "John"
},
{
"type": "text",
"parameter_name": "order_id", // This is what we've missed
"text": "9128312831"
}
]
本质上,它会要求您输入在创建模板时创建的参数名称。我显然不知道你是如何创建它们的,但你可以检查你的结构并将其转换为元建议的格式。