如何设置 Telegram bot webhook?
How to set Telegram bot webhook?
我正在开发 Telegram 机器人,我想将 webhook 设置到我域的 URL。我已经在 Telegram's guide. However, I'm not able to set the webhook. I've searched previous answers and found this one 之后生成了一个自签名证书,但它对我不起作用。谁能解释一下如何上传 SSL 证书和设置 webhook?
我在我的服务器上创建了一个文件,用于方便地设置电报 webhooks。
您可以在您的服务器上使用相同的文件。
这应该在您希望 运行 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>
- 将此文件放在您希望托管机器人的同一台服务器上
- 确保在您的网络服务器上启用
.pem
的 mime 类型
- 在我们的服务器上浏览到此页面
- 用您的 BOT_TOKEN 和选择的 PORT
填写表格
- 上传您的证书文件
- 提交表格
你会得到一个成功的结果:
{"ok":true,"result":true,"description":"Webhook was set"}
设置网络钩子
https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to}
例如:
https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/setWebhook?url=https://www.example.com
获取 Webhook
https://api.telegram.org/bot{my_bot_token}/getWebhookInfo
我正在开发 Telegram 机器人,我想将 webhook 设置到我域的 URL。我已经在 Telegram's guide. However, I'm not able to set the webhook. I've searched previous answers and found this one 之后生成了一个自签名证书,但它对我不起作用。谁能解释一下如何上传 SSL 证书和设置 webhook?
我在我的服务器上创建了一个文件,用于方便地设置电报 webhooks。
您可以在您的服务器上使用相同的文件。
这应该在您希望 运行 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>
- 将此文件放在您希望托管机器人的同一台服务器上
- 确保在您的网络服务器上启用
.pem
的 mime 类型 - 在我们的服务器上浏览到此页面
- 用您的 BOT_TOKEN 和选择的 PORT 填写表格
- 上传您的证书文件
- 提交表格
你会得到一个成功的结果:
{"ok":true,"result":true,"description":"Webhook was set"}
设置网络钩子
https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to}
例如:
https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/setWebhook?url=https://www.example.com
获取 Webhook
https://api.telegram.org/bot{my_bot_token}/getWebhookInfo