Closed ixiaan closed 1 year ago
改两处代码: 1、config 里 telegram 通知方式
-- telegram 通知配置, 将"YOUR_TOKEN"和"YOUR_CHAT_ID"改为自己的参数
TELEGRAM_PROXY_API = "https://api.telegram.org/bot"YOUR_TOKEN"/sendMessage?chat_id="YOUR_CHAT_ID""
2、util_notify.lua里telegram通知方式
local notify = {
-- 发送到 telegram
["telegram"] = function(msg)
if config.TELEGRAM_PROXY_API == nil or config.TELEGRAM_PROXY_API == "" then
log.error("util_notify", "未配置 `config.TELEGRAM_PROXY_API`")
return
end
local header = {
["Content-Type"] = "application/json; charset=utf-8"
}
local body = {
text = msg
}
local json_data = json.encode(body)
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
json_data = string.gsub(json_data, "\\b", "\\n")
log.info("util_notify", "POST", config.TELEGRAM_PROXY_API)
return util_http.fetch(nil, "POST", config.TELEGRAM_PROXY_API, header, json_data)
end
感谢回复! util_notify.lua里telegram通知方式 似乎没改啊
有效果 非常感谢!
已支持 1bbebd5314fd730483c06555433d786d9e0718a8 按下面配置即可
TELEGRAM_API = "https://aa.bb.cc/bot888888888:Abcikasldfjpogpaouiseor-t8/sendMessage"
TELEGRAM_CHAT_ID = ""
如题,已经用cloudflare.com免费服务代理了telegram的api 目前使用https://aa.bb.cc/bot888888888:Abcikasldfjpogpaouiseor-t8 (示意) 即可推送消息 如何修改咱这个项目使得可以使用呢 附 反代参考https://gitee.com/pp/SmsForwarder/wikis/pages?sort_id=5685750&doc_id=1821427 附录6:反向代理TG_BOT_API 准备:cloudflare账号
1.建立一个cf work 复制粘贴以下代码 const whitelist = ["/bot你的botID:"]; //示例const whitelist = ["/bot123456:"]; const tg_host = "api.telegram.org";
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) })
function validate(path) { for (var i = 0; i < whitelist.length; i++) { if (path.startsWith(whitelist[i])) return true; } return false; }
async function handleRequest(request) { var u = new URL(request.url); u.host = tg_host; if (!validate(u.pathname)) return new Response('Unauthorized', { status: 403 }); var req = new Request(u, { method: request.method, headers: request.headers, body: request.body }); const result = await fetch(req); return result; }
然后获取workers地址如:https://xx.xxx.workers.dev
测试发送消息:{}不需要填写
[https://xxx.xxx.workers.dev/bot{机器人token}/sendMessage?chat_id={消息发送人}&text=test]