Facebook Messenger嵌套持久菜单错误 [英] Facebook Messenger Nested Persistent Menu Error

查看:344
本文介绍了Facebook Messenger嵌套持久菜单错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将NESTED持久性菜单添加到我的chatbot中。 Facebook有3个按钮的限制,但你可以有一个最多5个按钮的嵌套按钮。



这是我运行代码时遇到的错误


响应正文错误:{message:'(#100)无效的键错误:
$ b 类型:'OAuthException',

call_to_actions在paramcall_to_actions [0]中找到,'code:100}

这是我的代码:

  function addPersistentMenu(){
request({
url:https://graph.facebook.com/ v2.6 / me / thread_settings,
qs:{access_token:token},
方法:POST,
json:{
setting_type:call_to_actions,
thread_state:existing_thread,
call_to_actions:[
{
类型:嵌套,
标题:Menu Item One,
call_to_actions:[
{
类型:回发,
标题:嵌套物品1,
有效载荷:NESTED_ONE
},
{
type:postback,
title:Nested Item Two,
payload:NESTED_TWO
}
]
},

类型:回发,
标题:菜单项目二,
有效载荷:TWO
},
{
类型:postback,
title:Menu Item Three,
payload:THREE
}
]
}
},function(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)
}
});
}

当我删除嵌套按钮时,持久菜单出现,所以我不是确定错误是什么。我的代码非常类似于持久性菜单文档。我正在使用node.js进行编程,托管在heroku上,并且我在在这里找到的代码

问题:有没有人使用npm请求包使用nodejs webhook来发送请求到Messenger?



编辑:
当我使用确切的命令通过终端使用直接CURL POST时,如何添加我的嵌套持久菜单?在持久菜单文档中,添加了嵌套的持久菜单。我不确定要添加到我的nodejs webhook版本的此请求以使其工作。



这是CURL命令:

  curl -X POST  - HContent-Type:application / json-d'{
persistent_menu:[
{
locale:default,
composer_input_disabled:true,
call_to_actions:[
{
title:我的账户,
type:嵌套,
call_to_actions:[
$ btitle:Pay Bill,
type:postback,
payload:PAYBILL_PAYLOAD
},
{
title:History,
type:postback,
payload:HISTORY_PAYLOAD
},
{
title:联系信息,
type:postback,
payload:CONTACT_INFO_PAYLOAD
}
]
},
{
type:web_url,
title:Latest N ews,
url:http://petershats.parseapp.com/hat-news,
webview_height_ratio:全部
}
]
$,
{
locale:zh_CN,
composer_input_disabled:false
}
]
}'https:/
方案

Facebook Messenger API已更新为嵌套持久性菜单。 'call_to_actions'风格似乎仍然适用于非嵌套菜单。

然而,嵌套菜单需要不同的API调用。差异似乎是URL必须是'messenger_profile'而不是'thread_settings'。出于某种原因,还需要'get_started'处理程序。最后,json数组被命名为'persistent_menu'。



我更新了示例 bot 在gitub上。键入'添加菜单'和'删除菜单'以查看持久菜单出现/消失。在某些浏览器上可能需要重新加载页面或两个页面。



以下是一些不太现实的nodejs代码,它们应该可以做到这一点。

  function addPersistentMenu(){
request({
url:'https://graph.facebook.com/v2.6/me/messenger_profile' ,
qs:{access_token:PAGE_ACCESS_TOKEN},
方法:'POST',
json:{
get_started:{
payload:GET_STARTED_PAYLOAD
}

},函数(error,response,body){
console.log(响应)
if(error){
console。 log('Error sending messages:',error)
} else if(response.body.error){
console.log('Error:',response.body.error)
}
})
request({
url:'https://graph.facebook.com/v2.6/me/messenger_profile',
qs:{access_token:PAGE_ACCESS_TOKEN} ,
方法:'POST',
json:{
persistent_menu:[
{
locale:default,
composer_input_disabled:true,
call_to_actions:[
{
title:我的账户,
type:嵌套,
call_to_actions:[
{
title:Pay Bill,
type:postback,
payload:PAYBILL_PAYLOAD
} ,
{
title:History,
type:postback,
payload:HISTORY_PAYLOAD
},
{
title:联系信息,
type:postback,
payload:CONTACT_INFO_PAYLOAD
}
]
$,
{
type:web_url,
title:最新消息,
url:http://foxnews.com ,
webview_height_ratio:全部
}
]
},
{
locale:zh_CN,
composer_input_disabl ed:false
}
]
}

},function(error,response,body){
console.log(response)
if(error){
console.log('Error sending messages:',error)
} else if(response.body.error){
console.log('Error: ',response.body.error)
}
})

}


I'm trying to add a NESTED persistent menu to my chatbot. Facebook has a limit of 3 buttons but you can have a nested button with a maximum of 5 buttons.

This is the error I get when I run my code

response body error

type: 'OAuthException',

Error: { message: '(#100) Invalid keys "call_to_actions" were found in param "call_to_actions[0]".', code: 100}

Here is my code:

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)
      }
   });
}

When I remove the nested button, the persistent menu appears so I'm not sure what the error is. My code is pretty similar to the sample posted by facebook in their persistent menu doc. I'm programing using node.js, hosted on heroku and I modeled my menu function after the code found here.

Question: Has anyone done this using a nodejs webhook using the npm request package to send requests to messenger? How do I add my nested persistent menu and what does this error mean?

Edit: When I use a direct CURL POST via the terminal using the exact command in the persistent menu documentation, the nested persistent menu is added. I'm not sure what to add to my nodejs webhook version of this request to make it work.

This is the CURL command:

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"

解决方案

The Facebook Messenger API has been updated for nested persistent menus. The 'call_to_actions' style appears to still work for a non-nested menu.

A nested menu needs a different API call however. The difference appears to be the URL must be to the 'messenger_profile' rather than 'thread_settings'. A 'get_started' handler is also required for some reason. Finally, the json array is named 'persistent_menu'.

I updated the example bot on gitub. Type 'add menu' and 'remove menu' to see the persistent menu appear/disappear. A page reload or two may be required on some browsers.

Here is some sloppy nodejs code that should do the trick.

  function addPersistentMenu(){
 request({
    url: 'https://graph.facebook.com/v2.6/me/messenger_profile',
    qs: { access_token: PAGE_ACCESS_TOKEN },
    method: 'POST',
    json:{
  "get_started":{
    "payload":"GET_STARTED_PAYLOAD"
   }
 }
}, function(error, response, body) {
    console.log(response)
    if (error) {
        console.log('Error sending messages: ', error)
    } else if (response.body.error) {
        console.log('Error: ', response.body.error)
    }
})
 request({
    url: 'https://graph.facebook.com/v2.6/me/messenger_profile',
    qs: { access_token: PAGE_ACCESS_TOKEN },
    method: 'POST',
    json:{
"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://foxnews.com",
          "webview_height_ratio":"full"
        }
      ]
    },
    {
      "locale":"zh_CN",
      "composer_input_disabled":false
    }
    ]
    }

}, function(error, response, body) {
    console.log(response)
    if (error) {
        console.log('Error sending messages: ', error)
    } else if (response.body.error) {
        console.log('Error: ', response.body.error)
    }
})

}

这篇关于Facebook Messenger嵌套持久菜单错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆