【发布时间】:2017-10-26 06:25:26
【问题描述】:
我正在尝试向我的聊天机器人添加一个 NESTED 持久菜单。 Facebook 限制为 3 个按钮,但您可以拥有最多 5 个按钮的嵌套按钮。
这是我运行代码时遇到的错误
响应正文错误
类型:'OAuthException',
错误:{ message: '(#100) 在参数“call_to_actions[0]”中发现无效键“call_to_actions”。',代码:100}
这是我的代码:
function addPersistentMenu(){
request({
url: "https://graph.facebook.com/v2.6/me/thread_settings",
qs: {access_token: token},
method: "POST",
json:{
setting_type : "call_to_actions",
thread_state : "existing_thread",
call_to_actions : [
{
type: "nested",
title: "Menu Item One",
call_to_actions: [
{
type: "postback",
title: "Nested Item One",
payload: "NESTED_ONE"
},
{
type: "postback",
title: "Nested Item Two",
payload: "NESTED_TWO"
}
]
},
{
type: "postback",
title: "Menu Item Two",
payload: "TWO"
},
{
type: "postback",
title: "Menu Item Three",
payload: "THREE"
}
]
}
}, function(error, response, body) {
if(error){
console.log('sending error')
console.log('Error sending messages: ', error)
}else if(response.body.error){
console.log('response body error')
console.log('Error: ', response.body.error)
}
});
}
当我删除嵌套按钮时,会出现永久菜单,所以我不确定错误是什么。我的代码与 facebook 在persistent menu doc 中发布的示例非常相似。我正在使用托管在 heroku 上的 node.js 进行编程,我在 the code found here 之后建模了我的菜单功能。
问题:有没有人使用 nodejs webhook 使用 npm request 包向 messenger 发送请求?如何添加我的嵌套持久菜单,这个错误是什么意思?
编辑: 当我使用持久菜单文档中的确切命令通过终端使用直接 CURL POST 时,会添加嵌套的持久菜单。我不确定要在我的 nodejs webhook 版本中添加什么以使其正常工作。
这是 CURL 命令:
curl -X POST -H "Content-Type: application/json" -d '{
"persistent_menu":[
{
"locale":"default",
"composer_input_disabled":true,
"call_to_actions":[
{
"title":"My Account",
"type":"nested",
"call_to_actions":[
{
"title":"Pay Bill",
"type":"postback",
"payload":"PAYBILL_PAYLOAD"
},
{
"title":"History",
"type":"postback",
"payload":"HISTORY_PAYLOAD"
},
{
"title":"Contact Info",
"type":"postback",
"payload":"CONTACT_INFO_PAYLOAD"
}
]
},
{
"type":"web_url",
"title":"Latest News",
"url":"http://petershats.parseapp.com/hat-news",
"webview_height_ratio":"full"
}
]
},
{
"locale":"zh_CN",
"composer_input_disabled":false
}
]
}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=YOUR_ACCESS_TOKEN_HERE"
【问题讨论】:
标签: javascript node.js facebook-graph-api heroku bots