【发布时间】:2022-06-10 18:29:41
【问题描述】:
阅读此https://developers.facebook.com/docs/messenger-platform/discovery/facebook-chat-plugin/ 手册 我创建了 Facebook 页面并将 Messenger 聊天插件代码插入到我的 Laravel 9 页面中, 所以我可以在 Facebook 页面和我的网站页面上的聊天机器人中发送和接收消息。 接下来我想在某些情况下从 laravel 应用程序向用户发送消息,比如用户有一些我们想要通知他的事件。
我用代码阅读了这个例子:
向 /PAGE-ID/chat_plugin 端点发送 POST 请求以进行自定义 插件的欢迎屏幕问候语、颜色、图标等。
示例请求 curl -i -X POST “https://graph.facebook.com/v14.0/PAGE-ID/chat_plugin ?welcome_screen_greeting:YOUR-WELCOME-TEXT &theme_color:553399 &entry_point_icon:MESSENGER_ICON &entry_point_label:聊天
我在我的控制动作中做出:
$messageData = [
"welcome_screen_greeting"=> "welcome to my app",
"theme_color"=> "553399",
"messaging_type"=> "welcome_screen_greeting",
"entry_point_icon"=> "MESSENGER_ICON",
"entry_point_label"=> "CHAT", // ?
"recipient" => [
"user_ref" => 'NNNNNN', // That is id of my profile https://www.facebook.com/profile.php?id=NNNNNN
],
"message" => [
"text" => "hello, world from the app!",
],
];
$ch = curl_init('https://graph.facebook.com/v14.0/PAGE-ID/chat_plugin?access_token=' . config('app.PAGE_ACCESS_TOKEN'));
\Log::info( varDump($ch, ' -1 BotController sendTextMessage $ch::') );
我在屏幕上看到了结果:
{"success":true}
我不确定这个输出是哪个命令?
var $ch 在日志中的值为空(假)。 我在 .env 文件中有有效的 app.PAGE_ACCESS_TOKEN 参数。 如果我在 $messageData 中隐藏其中一个参数,我 - 会出错。
但我的 Facebook 中没有任何聊天机器人通知...
修改的第 1 部分: 看起来我走错了方向,我需要这个
curl -X POST -H "Content-Type: application/json" -d '{
"messaging_type": "<MESSAGING_TYPE>",
"recipient": {
"user_ref": "<USER_REF>"
},
"message": {
"text": "hello, world!"
}
}' "https://graph.facebook.com/v14.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
但是,这里的“
{"error":{"message":"(#100) No matching user found","type":"OAuthException","code":100,"error_subcode":2018001,"fbtrace_id":"AQoLtZt7yUdw3WiBrF0TOKs"}}
在网上搜索我发现了这个Facebook API {"error":{"message":"(#100) No matching user found","type":"OAuthException" Checkbox Plugin 分支,但打开了我下一个引用的页面:https://prnt.sc/TZs0V4eGqIgw 不确定它是有效的方向吗? 另外,如果我需要通知我网站的注册用户,我需要以某种方式获取并保存在我的数据库中这个 USER_REF ?
怎么了?
谢谢!
【问题讨论】:
-
请看修改后的部分#1
标签: laravel php-curl facebook-chatbot