gpt4 book ai didi

javascript - Facebook Messenger 机器人“开始”按钮

转载 作者:行者123 更新时间:2023-12-03 05:11:33 25 4
gpt4 key购买 nike

我正在用 js 构建我的第一个消息机器人,并且已经可以接收和回复消息并发送带有选项的卡片,但我已经尝试了一切来设置开始按钮,但没有成功......这就是什么我已经为此做了:

我不知道我做错了什么或者我必须在哪里调用 facebookthreadAPI 函数。需要建议。

摘自index.js:

function facebookThreadAPI(jsonFile, cmd){
// Start the request
request({
url: 'https://graph.facebook.com/v2.6/me/thread_settings?access_token='+process.env.token,
method: 'POST',
headers: {'Content-Type': 'application/json'},
form: require(jsonFile)
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
// Print out the response body
console.log(cmd+": Updated.");
console.log(body);
} else {
// TODO: Handle errors
console.log(cmd+": Failed. Need to handle errors.");
console.log(body);
}
});}

摘自 fb-get-started-button.json:

{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"payload":"action?POSTBACKHERE"
}
]
}

最佳答案

Facebook 现在提供了一个新的 API,用于设置“开始”按钮以及许多其他功能,例如问候文本和永久菜单,因此不要使用旧的 thread_setting API,而是使用信使配置文件 API。例如,使用curl

    curl -X POST -H "Content-Type: application/json" -d '{ 
"get_started":{
"payload":"GET_STARTED_PAYLOAD"
}
}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=PAGE_ACCESS_TOKEN"

将 PAGE_ACCESS_TOKEN 替换为您的页面访问 token ,将 GET_STARTED_PAYLOAD 替换为您想要的任何负载。查看完整tutorial here

关于javascript - Facebook Messenger 机器人“开始”按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41798219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com