简体   繁体   English

Facebook Messenger Bot空白回复

[英]Facebook Messenger Bot blank response

I've just stumbled upon messenger bot and felt like doing myself one too. 我偶然发现了Messenger bot,也想自己做一个。 I've setuped webhooks correctly, verified my webhook script and made myself a temporary simple thing to see the request when I send message to my bot. 我已经正确设置了webhook,验证了我的webhook脚本,并在将消息发送到bot时使自己成为一个临时的简单事物,可以查看请求。

<?php
$file = "data.txt";
$current = file_get_contents($file);
$data = $current ."\n". json_encode($_REQUEST);
file_put_contents ( $file , $data  );

It works (catches all the requests), but whenewer I type in the chat, I get just a blank [] in my file. 它可以工作(捕获所有请求),但是当我键入聊天内容时,我的文件中只出现一个空白[]。 This means facebook contacts my siete when I try to communicate with the bot, but without any request (data)? 这意味着当我尝试与漫游器通信时,facebook会联系我的siete,但没有任何请求(数据)吗?

Could somebody tell me what am I doing wrong? 有人可以告诉我我在做什么错吗? Thanks! 谢谢!

Facebook hits your webhook with Content-type application/json and JSON string in the request body. Facebook在请求正文中使用Content-type application/json和JSON字符串命中您的webhook。 $_REQUEST cannot handle it because $_REQUEST contains the data with HTTP Content-type application/x-www-form-urlencoded or multipart/form-data . $ _REQUEST无法处理它,因为$ _REQUEST包含HTTP Content-type application/x-www-form-urlencodedmultipart/form-data Here, you need to read the input stream (raw data). 在这里,您需要读取输入流 (原始数据)。

<?php
$file = "data.txt";
$current = file_get_contents($file);
$data = $current ."\n". file_get_contents('php://input');
file_put_contents ( $file , $data  );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM