【问题标题】:Telegram Bot that takes data from input form and sends it to a telegram group/userTelegram Bot 从输入表单中获取数据并将其发送给电报组/用户
【发布时间】:2016-11-13 08:35:09
【问题描述】:

我想帮助一个朋友。他有一个用 HTML、JavaScript 和 jQuery 制作的简单网站。他需要将网站与电报集成,这样如果有人在网站上填写表格,电报机器人应该在群聊中发送信息(我知道如何获取chat_id,但关于电报机器人仅此而已)。

所以我尝试使用 sendMessage 方法向我的机器人发送一些带有 curl 的 POST 请求,但似乎没有成功。

也许我在命令行 curl 上犯了错误,当我发出请求时它没有显示任何输出。我发现它在标准输出中发送输出(不管是什么......)

所以我有两个问题:
1:如何让 curl 在命令行中显示响应输出?
2:我如何请求向自己发送消息(在电报机器人手册中它说它应该如下所示......)

curl -s \
-X POST \
https://api.telegram.org/bot<token>/sendMessage \
-d text="A message from your bot" \
-d chat_id=65535 \
| jq .

我认为我需要在 cmd 中编写它,我尝试使用我的个人机器人令牌和 chat_id,但它没有用。

【问题讨论】:

    标签: curl telegram telegram-bot


    【解决方案1】:

    你也可以做一个简单的 GET 请求来让 Bot 发送消息。

    https://api.telegram.org/bot<token>/sendMessage?text=Your message here&chat_id=65535
    

    以下是您可以使用的示例代码。

    function sendmessage(){
      chat_id = document.getElementById("chatid").value;
      token = document.getElementById("token").value;
      message = document.getElementById("message").value;
      $.get("https://api.telegram.org/bot"+token+"/sendMessage?text="+message+"&chat_id="+chat_id);
      }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
    
    <input type="text" id="chatid" value="Chat ID"></br>
    <input type="text" id="token" value="Bot Token"></br>
    <input type="text" id="message" value="Message"></br>
    <button onclick=sendmessage()>Send Message</button>

    【讨论】:

      猜你喜欢
      • 2022-07-28
      • 2017-05-06
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多