我有 6 个机器人,我想在同一台服务器上运行它们,但是当我运行第二个机器人时,它会抛出此错误:
address already in use :::8443
我知道我只能使用 4 个端口(80,88,443,8443)进行 webhook,但我有 6 个机器人。实际上,我正在尝试在同一端口上运行所有机器人。
有办法做吗?
我正在使用 telegraf 框架。我为每个机器人创建了一个目录,因为我认为这是做到这一点的方法。也许我错了。
这是每个目录中机器人的代码:
const Telegraf = require('telegraf');
const fs = require('fs');
let token = 'botID:botToken';
const bot = new Telegraf(token);
const tlsOptions = {
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem'),
ca: []
}
bot.on('message', (ctx) => ctx.reply('Hey'));
bot.telegram.setWebhook('https://myAddress.com:8443/test/botID');
bot.startWebhook('/test/botID', tlsOptions, 8443);
Run Code Online (Sandbox Code Playgroud) 我想在 Telegraf 中使用 webHook,但我不知道如何正确使用它。
这是我的简单代码。但它仍然使用轮询。
const Telegraf = require('telegraf');
const bot = new Telegraf('123:ABC');
bot.telegram.setWebhook('https://myaddress.com');
bot.startWebhook(`/`, null, 4000);
bot.use(function(ctx, next){
try{
if(ctx.chat == undefined) return;
console.log("Hello World");
}catch (e){
console.log("Error");
}
});
bot.launch();
Run Code Online (Sandbox Code Playgroud)