简体   繁体   English

发送对Webhook的答复时,如何执行对电报Bot API的请求?

[英]how perform a request to the telegram Bot API while sending an answer to the webhook?

the Telegram API say : Telegram API

If you're using webhooks, you can perform a request to the Bot API while sending an answer to the webhook. 如果您使用的是Webhooks,则可以在向Webhook发送答案的同时向Bot API执行请求。

i try to do it by this simple code: 我尝试通过以下简单代码来做到这一点:

header('Content-Type: application/x-www-form-urlencoded');
$content = http_build_query(array(
    'method' => 'sendMessage',
    'chat_id' => 123,
    'text' => 'test 123'
));
file_put_contents("php://output", $content); // or echo $content;

but i can't see any response in the robot. 但是我看不到机器人的任何反应。

the Telegram update robot API in last day and now support JSON response. 最后一天的电报更新机器人API ,现在支持JSON响应。 so we can change the code: 因此我们可以更改代码:

header('Content-Type: application/json');
echo json_encode(array(
    'method'=>'sendMessage',
    'text'=>'test 123',
    'chat_id'=>123,
));
die;

and it works for me! 它对我有用!

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

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