如何设置Telegram Bot Webhook? [英] How to set Telegram bot webhook?

查看:329
本文介绍了如何设置Telegram Bot Webhook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Telegram机器人,我想将Webhook设置为我域的URL.我已经按照电报指南生成了自签名证书.但是,我无法设置网络挂钩.我搜索了先前的答案,发现这一个,但是它没有对我不起作用.有人可以向我解释如何上传SSL证书并设置Webhook吗?

I'm developing a Telegram bot, and I want to set the webhook to my domain's URL. I've already generated a self-signed certificate following the Telegram's guide. However, I'm not able to set the webhook. I've searched previous answers and found this one, but it doesn't work to me. Can anybody explain me how to upload the SSL certificate and set the webhook?

推荐答案

我在服务器上创建了一个文件,以方便地设置电报Webhook.

I created a file on my server for conveniently setting up telegram webhooks.

您可以在服务器上使用相同的文件.

You can use the same file on your server.

该服务器应该与您要运行Telegram Bot的服务器位于同一服务器上

This should be on the same server from which you wish to run the Telegram Bot

<html>

<head>
  <title>Set Webhooks</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css" />
  <script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>

<body>
  <div class="container">
    <div id="app" class="section">
      <form :action="set_webhook" method="post" enctype="multipart/form-data">
        <label class="label">Enter your Token</label>
        <p class="control">
          <input class="input" type="text" v-model="token" />
        </p>
        <label class="label">Enter your Host</label>
        <p class="control">
          <input class="input" type="text" v-model="host" />
        </p>
        <label class="label">Enter your Port</label>
        <p class="control">
          <input class="input" type="text" v-model="port" />
        </p>

        <input type="hidden" name="url" v-model="bot_url">
        <label class="label">Maximum Connections?</label>
        <p class="control">
          <input class="input" type="text" name="max_connections" value="100" />
        </p>
        <br/>
        <p style="color:blue">{{ bot_url }}</p>
        <br/>
        <label class="label">Enter your Certificate</label>
        <p class="control">
          <input type="file" name="certificate" id="fileToUpload" />
        </p>
        <br/>
        <div class="control is-grouped">
          <p class="control">
            <button class="button is-primary" name="submit">Set Webhook</button>
          </p>
          <br/>
          <p class="control">
            <a :href="get_webhook_info" target="_blank" class="button is-info">Get Webhook Info</a>
          </p>
        </div>
    </div>
  </div>
  <script>
    new Vue({
      el: '#app',
      data: {
        token: 'xxx',
        port: 88,
        host: 'your-server.com',
      },
      computed: {
        get_webhook_info: function () {
          return 'https://api.telegram.org/bot' + this.token + '/getwebhookinfo'
        },
        set_webhook: function () {
          return 'https://api.telegram.org/bot' + this.token + '/setwebhook'
        },
        bot_url: function () {
          return 'https://' + this.host + ':' + this.port + '/' + this.token
        }
      }
    }

    )
  </script>
</body>

</html>

  1. 将此文件拖放到您希望托管机器人的服务器上
  2. 确保在您的网络服务器上启用了.pem的mime类型
  3. 浏览到我们服务器上的此页面
  4. 用您的BOT_TOKEN填写表格并选择端口
  5. 上传您的证书文件
  6. 提交表格
  1. Drop this file on the same server you wish to host you bots
  2. Ensure the mime-type for .pem is enabled on your webserver
  3. Browse to this page on our server
  4. Fill the form with your BOT_TOKEN and chosen PORT
  5. Upload your certificate file
  6. Submit the form

您将获得成功的结果:

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

这篇关于如何设置Telegram Bot Webhook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆