如何在向 webhook 发送答案的同时向电报 Bot API 执行请求?

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

电报 API say:

If you're using webhooks, you can perform a request to the Bot API while sending an answer to the webhook.

我试着用这个简单的代码来做:

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;

但是我看不到机器人有任何反应。

Telegram 更新 robot API 最后一天,现在支持 JSON 响应。 所以我们可以更改代码:

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

它对我有用!