【问题标题】:Telegram bot ends unexpectedlyTelegram 机器人意外结束
【发布时间】:2019-01-06 10:17:59
【问题描述】:

尝试制作我的第一个电报机器人,在所有示例和说明中,它看起来非常简单且易于重复。但是,我的机器人根本不起作用。首先,我来自俄罗斯,电报 api 被阻止,所以我需要使用代理。从https://www.socks-proxy.net/ 拿了一张。从 BotFather 获得令牌。现在当我运行我的脚本telegraf.js:

const Telegraf = require('telegraf');
const SocksAgent = require('socks5-https-client/lib/Agent');
const socksAgent = new SocksAgent({
   socksHost: '103.206.97.70',
   socksPort: 4145,
});
const bot = new Telegraf(MY_TOKEN, {
telegram: {
    agent: socksAgent,
}
});
bot.hears('hi', ctx => {
   return ctx.reply('Hey!');
});
bot.startPolling();

什么都没有发生,程序完成

我知道问题出在我的代理配置中,但不明白到底出了什么问题。

【问题讨论】:

    标签: javascript node.js telegram-bot http-proxy


    【解决方案1】:

    问题出在代理上。我用https-proxy-agent代替socks5-https-client

    import Telegraf from 'telegraf';
    import config from 'config';
    import HttpsProxyAgent from 'https-proxy-agent';
    
    const TOKEN = config.get('token');
    const proxy = config.get('proxy');
    
    const bot = new Telegraf(TOKEN, {
        telegram: {
            agent: new HttpsProxyAgent({
                host: proxy.host,
                port: proxy.port
            })
        },
    });
    
    bot.hears('hi', ctx => {
        return ctx.reply('Hey!');
    });
    bot.startPolling();
    

    【讨论】:

      猜你喜欢
      • 2020-07-22
      • 2018-08-11
      • 2016-01-20
      • 2021-11-07
      • 2022-11-01
      • 1970-01-01
      • 2012-06-23
      • 2016-03-09
      • 1970-01-01
      相关资源
      最近更新 更多