尝试制作我的第一个电报机器人,在所有的例子和说明中,它看起来非常简单,很容易重复。然而,我的机器人根本不能工作。首先,我来自俄罗斯,电报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();什么也没发生,程序结束了

。

我知道这个问题出在我的代理配置中,但我不能理解到底哪里出了问题。
发布于 2019-01-07 01:20:55
问题出在代理服务器上。我使用的是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();https://stackoverflow.com/questions/54060545
复制相似问题