我怎样才能知道电报将消息发送到我设置为 webhook 的 url

How can I find out that telegram sends messages to the url that I set as webhook

我执行了这些步骤来为我的电报机器人设置 Webhook:

我从我的 https url(https://mywebapp.com/index./index.jsp) 获取 .cer 文件,然后按此顺序生成 .jks 文件(我转到 cmd 中的 jre/bin 文件夹):

keytool -importcert -file mywebapp.cer -keystore myKeystore.jks -alias mywebapp.com

然后我将其转换为 .p12 文件:

keytool -importkeystore -srckeystore myKeystore.jks -destkeystore myPkcs.p12 -srcstoretype jks -deststoretype pkcs12

然后我通过 openSSL 将 .p12 文件转换为 .pem 文件:

openssl pkcs12 -in myPkcs.p12 -out myPem.pem

然后我生成这个表单来设置 webhook:

<form id="telegramForm" action="https://api.telegram.org/botTOKEN/setWebhook" method="POST" enctype="multipart/form-data">
            <input type="text" name="url" id="url" value="https://mywebapp.com/index.jsp">
            <input type="file" name='certificate' id='certificate'>
            <input type="submit" value="submit">
        </form>

然后我从输入 [type=file] 浏览 myPem.pem 文件。我提交此表格并收到以下回复:

{"ok":true,"result":true,"description":"Webhook was set"}

但是当我(或用户电报)通过电报应用程序向我的机器人发送一些消息(如短信 "hello")时,https://mywebapp.com/index.jsp(url 被设置为 webhook ) 没有收到任何请求。

我如何才能知道电报将消息(用户发送到我的电报机器人)发送到我设置为 webhook 的 url?我如何才能知道这个 url (https://mywebapp.com/index.jsp) 可以接收电报用户发送到我的电报机器人的消息? 为什么我无法收到电报用户发送到我的机器人的消息?我怎样才能得到它们? 谢谢。

最好像这样设置您的网络挂钩:https://mywebapp.com/index.php

index.php 是您的机器人处理器文件。

将此代码放入您的 index.php 文件中进行测试:

<?php

define('BOT_TOKEN','1234:xyz'); //replace second parameter with your bot token
$command_prefix_url = 'https://api.telegram.org/bot' . BOT_TOKEN;
$update = json_decode(file_get_contents('php://input'));

$rep = json_decode(file_get_contents($command_prefix_url . '/SendMessage?chat_id=' .
    $update->message->chat->id . '&text='.urlencode($update->message->text)));
?>

现在每次,如果有人向您发送一些文本,它就会收到来自机器人的文本。

如果你想知道,是否有人向你的机器人发送了一些东西,你可以将这个 $update 保存到数据库或重新发送给你的(管理员)客户端!(很多消息)