0%

Telegarf 通过代理访问 TG API 的几种方式

  • 主要分为客户端代理和服务端代理, 一般情况下只需一个就可以了

客户端代理

clash 增强模式 / clash tun 模式

  • 这种情况下 clash 已经接管了所有流量, 直接启动就可以了, 不需要额外设置

    http agent

  • 需要有一个可以访问的 http 代理, 比如 clash 默认启动的本地 http 代理

如果是手动写的 v2 配置文件, 可以参考 在 v2ray 中同时开启 socks 和 http 代理 来手动开启 http 代理服务

1
2
3
4
5
6
7
8
const Telegraf = require('telegraf')
const HttpsProxyAgent = require('https-proxy-agent')

const bot = new Telegraf('bot_token', {
telegram: {
agent: new HttpsProxyAgent('proxy url')
}
})

socks agent

  • 同上, 只不过 agent 变成了 SocksAgent
1
2
3
4
5
6
7
8
9
10
11
12
const Telegraf = require('telegraf');
const SocksAgent = require('socks5-https-client/lib/Agent');
const socksAgent = new SocksAgent({
socksHost: config.proxy.host,
socksPort: config.proxy.port,
socksUsername: config.proxy.login,
socksPassword: config.proxy.psswd,
});

const app = new Telegraf(token, {
telegram: { agent: socksAgent }
});

服务端代理

1
2
3
4
5
6
const app = new Telegraf(token, {
telegram: {
// proxy for https://api.telegram.org
apiRoot: 'https://tg-api-proxy-on-my-domain',
},
})

参见

  • https://github.com/telegraf/telegraf/issues/63
-------------本文结束再接再厉-------------

本文标题:Telegarf 通过代理访问 TG API 的几种方式

文章作者:IITII

发布时间:2022年12月31日 - 14:12

最后更新:2022年12月31日 - 14:12

原始链接:https://iitii.github.io/2022/12/31/1/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。