我想添加一个嵌套持久菜单到我的聊天机器人。 Facebook有3个按钮的限制,但你可以有一个最多5个按钮的嵌套按钮。Facebook Messenger嵌套持久菜单错误
这是当我跑我的代码
response body error
type: 'OAuthException',
Error: { message: '(#100) Invalid keys "call_to_actions" were found in param "call_to_actions[0]".', code: 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)
}
});
}
当我删除嵌套的按钮,连续的菜单出现,所以我不确定错误是什么。我的代码与persistent menu doc中facebook发布的示例非常相似。我正在使用node.js进行编程,托管在heroku上,我在the code found here之后对我的菜单功能进行了建模。
问题:是否有人使用npm请求包使用nodejs webhook完成此操作以向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"
谢谢!我尝试了节点js代码,我没有看到我的开始按钮,或菜单。我没有再想到那个错误消息。并发送的JSON响应显示{“object”:“Object”}而不是{“result”:“成功添加new_thread的CTA”} –
再次尝试。没有改变。刚刚删除了开始使用按钮和菜单ID试图以前添加。有效。 –
我注意到持久菜单缓存它的状态。重新加载页面或重新启动应用程序重复您有时需要看到更新 –