Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook配置参考 #327

Open
jeessy2 opened this issue Jul 24, 2022 · 48 comments
Open

Webhook配置参考 #327

jeessy2 opened this issue Jul 24, 2022 · 48 comments
Labels
documentation Improvements or additions to documentation

Comments

@jeessy2
Copy link
Owner

jeessy2 commented Jul 24, 2022

可把大家常用的Webhook通知分享出来,只分享,不提问,无关的将被删除

@jeessy2
Copy link
Owner Author

jeessy2 commented Jul 24, 2022

企业微信

下载企业微信→左上角三横杠→全新创建企业→个人组件团队(创建个人的企业群聊),
进入群聊添加 [群机器人] 复制机器人Webhook地址填入ddns-go后台Webhook URL地址栏。
在RequestBody栏填入回调函数,格式:

{ "msgtype": "markdown","markdown": { "content": "公网IP变更:\n 新IPV6地址:#{ipv6Addr} \n 已解析的域名:#{ipv6Domains} \n 域名更新结果:#{ipv6Result}" } }

@jeessy2 jeessy2 pinned this issue Jul 24, 2022
@walkxspace
Copy link

饭碗警告

链接:https://fwalert.com (含 aff,注册后会赠送 10 元余额)

支持通过 邮件(0.02元/次)、短信(0.1元/次)、电话(0.2元/次)、Telegram(免费)、饭碗警告App(免费) 的方式推送通知。

先点击右上角头像选择“联系方式”并在此对你所希望的通知渠道进行绑定,然后进入“转发规则”,点击加号新建规则,其中触发方式选择 Webhook,可参照下图添加模板变量,并依据你所设置的模板变量来设置通知正文,最后联系方式选择先前绑定的通知渠道即可。
Snipaste_2022-07-29_10-32-35
Snipaste_2022-07-29_10-36-27
保存转发规则后会生成一个 Webhook 地址,将该地址后添加 ?result=#{ipv6Result}&addr=#{ipv6Addr}(此处等号前的变量需与前面设置的一致) 填入 ddns-go 后台 Webhook URL 地址栏并保持 RequestBody 留空即可。

@ccaycy
Copy link

ccaycy commented Aug 5, 2022

企业微信{"msgtype": "markdown","markdown": {"content": "#### 你的公网IP变了 \n - IPV4地址:#{ipv4Addr} \n - 域名更新结果:#{ipv4Result} \n - IPV6地址:#{ipv6Addr}\n - 域名更新结果:#{ipv6Result} \n"}}

Repository owner deleted a comment from SouLXH Aug 28, 2022
@raining1123
Copy link

Apprise的邮箱推送

  1. apprise webhook url
    https://你的公网域名:端口/notify/你的密钥 就是一个webhook url
    "你的密钥"是自建的{key}或者token,可以换成任意一个
  2. 设置推送邮箱
    进入https://你的公网域名:端口/cfg/你的密钥 配置一下
    mailto://邮箱账号:授权码@qq.com?name=📢DDNS-GO
  3. 配置DDNS-GO
    在webhook url中填入第一步里的url
    在request body中填入:
    { "title":
    "公网IP变动了",
    "format":
    "html",
    "body":
    "新IPV4地址:#{ipv4Addr}
    已解析的域名:#{ipv4Domains}
    域名更新结果:#{ipv4Result}

    ------DDNS-GO------"}
    *其中的"title"、"type"、"format"、"body"都是apprise定义的,其中的#{ipv4Addr}、#{ipv4Domains}、#{ipv4Result}是DDNS-GO定义的

效果如图:
微信图片_20220920090907

@lqsbg26
Copy link

lqsbg26 commented Oct 2, 2022

我在ddns-go的webhook通知方面主要用的是“方糖”和“爱语飞飞”,两者都是在微信(个人版)上推送通知给我的。免费用户在方糖上每天可以推送5次,爱语飞飞现在好像还是免费不限次。我用得比较初级,在此只是告诉大家有这两个渠道。它们有没有其他推送方式,例如短信,邮件,丁丁等,我也没深入研究,可否实现更复杂的功能,我也没有研究。

@naoki66
Copy link

naoki66 commented Oct 31, 2022

http://www.pushplus.plus/send?
请问下 这个直接get日志提示成功,但是收不到消息
post又无法识别到RequestBody的内容

@Austinsuyoyo
Copy link

Telegram

  • Webhook url
    https://api.telegram.org/bot{your token}/sendmessage
  • RequestBody
    {
       "chat_id":"{notify room id}",
       "text":"外網IP改變:\n新IPV4地址:#{ipv4Addr}\n域名更新结果:#{ipv4Result}"
    }
    
  • Result
    image

Repository owner deleted a comment from dppll Dec 9, 2022
@daseinem
Copy link

  • ntfy : 免费免注册可自建的多平台推送方案。

  • 使用官方/公共服务器,推荐以 uuid 为 topic :

    1. uuidgen : e056a473-c080-4f34-b49c-e62f9fcd1f9d
    2. URL :https://ntfy.sh/
    3. RequestBody :
    {
        "topic": "e056a473-c080-4f34-b49c-e62f9fcd1f9d",
        "message": "IPv4已变更:#{ipv4Addr},域名 #{ipv4Domains} 更新#{ipv4Result}",
        "title": "DDNS-GO Cloudflare 更新",
        "priority": 2,
        "actions": [{ "action": "view", "label": "管理界面", "url": "http://192.168.0.1:9876/" }]
    }
    1. 客户端添加订阅topic:e056a473-c080-4f34-b49c-e62f9fcd1f9d ,可设置别名。
  • 自建服务并且设置了认证:

    1. 生成auth参数(*nix命令):echo -n "Basic `echo -n '<user>:<pass>' | base64`" | base64 | tr -d '='(替换<user><pass>),请结合https加密url,详细请参考ntfy文档
    2. URL: https://ntfy.example.com/?auth=<上一步生成的base64 auth参数>
    3. RequestBody :
    {
        "topic": "ddns-go",
        "message": "IPv4已变更:#{ipv4Addr},域名 #{ipv4Domains} 更新#{ipv4Result}",
        "title": "DDNS-GO Cloudflare 更新",
        "priority": 2,
        "actions": [{ "action": "view", "label": "管理界面", "url": "http://192.168.0.1:9876/" }]
    }
    1. 客户端在设置里更改默认服务器为自建:https://ntfy.example.com/,设置用户名和密码,然后添加订阅topic:ddns-go
  • 推送效果
    ddnsgo-ntfy

@Java2Boy
Copy link

  • https://api.telegram.org/bot{your token}/sendmessage

测试失败,返回内容: {"ok":false,"error_code":400,"description":"Bad Request: chat not found"} ,返回状态码: 400

@jeessy2 jeessy2 added keep documentation Improvements or additions to documentation labels Feb 2, 2023
@WaterLemons2k
Copy link
Contributor

WaterLemons2k commented Feb 5, 2023

Gotify

首先,登录到 Gotify 的 WebUI,点击 APPS -> CREATE APPLICATION 来创建 Token,得到 Token 后回到 ddns-go

然后,登录到 ddns-go,找到 Webhook,在 URL 处填入:

http://[IP]/message?token=[Token]

[IP] 替换为 Gotify 服务器的 IP,将 [Token] 替换为得到的 Token。

RequestBody 处填入:

{
	"title": "你的公网 IP 变了",
	"message": "IPv4 地址:#{ipv4Addr}\n域名更新结果:#{ipv4Result}",
        "priority": 5,
	"extras": {
		"client::display": {
			"contentType": "text/plain"
		}
	}
}

效果:
result

参考:

  1. Push messages · Gotify
  2. Message Extras · Gotify

@jeessy2 jeessy2 unpinned this issue Feb 18, 2023
@jeessy2 jeessy2 pinned this issue Feb 20, 2023
Repository owner deleted a comment from spysir Feb 22, 2023
Repository owner deleted a comment from spysir Feb 22, 2023
Repository owner deleted a comment from spysir Feb 22, 2023
Repository owner deleted a comment from WaterLemons2k Feb 22, 2023
Repository owner deleted a comment from spysir Feb 22, 2023
Repository owner deleted a comment from 21denli Feb 22, 2023
Repository owner deleted a comment from hululu1068 Feb 22, 2023
@jeessy2 jeessy2 unpinned this issue Feb 23, 2023
@jeessy2 jeessy2 removed the keep label Feb 23, 2023
Repository owner locked and limited conversation to collaborators Feb 25, 2023
Repository owner unlocked this conversation Apr 19, 2023
@dreyooneday
Copy link

像是使用本地搭建的通知服务(设置了证书),ddns访问内网地址会提示“无法验证由服务器提供的证书“,请问这个如何解决

@taotieren
Copy link

飞书的配置

{"msg_type": "post","content": {"post": {"zh_cn": {"title": "你的公网IP变了","content": [[{"tag": "text","text": "IPv4地址:#{ipv4Addr}"}] , [{"tag": "text","text": "域名更新结果:#{ipv4Result}"}],[{"tag": "text","text": "IPv6地址:#{ipv6Addr}"}] , [{"tag": "text","text": "域名更新结果:#{ipv6Result}"}]]}}}}

图片

@fanzhene
Copy link

fanzhene commented Sep 6, 2023

请教在ddnsgo具体配置iyuu的方法
https://iyuu.cn/【token】.send?title=你的公网IP变了&desp=主人IPv4变了#{ipv4Addr} , 域名更新结果:#{ipv4Result}

@Faramitas
Copy link

请教在ddnsgo具体配置iyuu的方法
https://iyuu.cn/【token】.send?title=你的公网IP变了&desp=主人IPv4变了#{ipv4Addr} , 域名更新结果:#{ipv4Result}

需要把title改为text,没有title这个参数了

@Jxb0123
Copy link

Jxb0123 commented Oct 2, 2023

Telegram测试成功,不是用楼上的方案,填写{your token}和,{your id},要把{}去掉

URL:https://api.telegram.org/bot{your token}/sendMessage?chat_id={your id}&text=IPV4变更#{ipv4Result},IPV6变更#{ipv6Result},注意看下QQ和Wechat是否能上网

是不是失效了,我用不行提示404

@hululu1068
Copy link

使用CF 反代TG api,通知自建BOT

新建CF Workers,填入以下内容,并使用自定义域

const tg_host = "api.telegram.org";
addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
    var u = new URL(request.url);
    u.host = tg_host;
    var req = new Request(u, {
        method: request.method,
        headers: request.headers,
        body: request.body
    });
    const result = await fetch(req);
    return result;
}
  • 例如:你的自定义域www.tiktok.com,那么api.telegram.org=www.tiktok.com

自建BOT

DDNS-GOWebhook填写

  • URL:
# 注意:bot后直接接Token,没有其它符号
https://www.tiktok.com/bot<自建BOT Token>/sendmessage
  • RequestBody:
{
  "chat_id": "你自己的UserID",
  "text": "主人!您的 IP 有变化\n\nIPv4: #{ipv4Result}\nIP: #{ipv4Addr}\n域名: telegram.org\n\nIPv6: #{ipv6Result}\nIP: #{ipv6Addr}\n域名: telegram.org"
}
image

@zraxx
Copy link

zraxx commented Dec 12, 2023

用文本格式可在微信中直接看
Webhook地址填入ddns-go后台Webhook URL地址栏。 在RequestBody栏填入回调函数,格式:

{ "msgtype": "text","text": {"content": "公网IP变更:\n 新IP地址:#{ipv4Addr} \n 已解析的域名:#{ipv4Domains} \n 域名更新结果:#{ipv4Result} \n 新IP地址:#{ipv6Addr} \n 已解析的域名:#{ipv6Domains} \n 域名更新结果:#{ipv6Result}" } }" } }

Screenshot_2023-12-12-14-02-02-546_com.tencent.mm.png

@ljr78
Copy link

ljr78 commented Dec 23, 2023

webhook在slack上怎么配置?一直配置不好。

@ljr78
Copy link

ljr78 commented Dec 24, 2023

Slack配置webhook:
捕获
先去这个位置把webhook url复制下来。
RequestBody填写:
{"text": "您的公网IP已经变化:\n\n 新IPV4地址:#{ipv4Addr} \n 已解析的域名:#{ipv4Domains} \n 域名更新结果:#{ipv4Result} \n\n 新IPV6地址:#{ipv6Addr} \n 已解析的域名:#{ipv6Domains} \n 域名更新结果:#{ipv6Result}" }
Headers填写:
'Content-Type': 'application/json'

@lxgz12345
Copy link

企业微信:

{ "msgtype": "markdown","markdown": { "content": "**公网IP变更:**\n >域名更新结果:<font color=\"warning\">#{ipv4Result}</font> \n>新ipv4地址:<font color=\"comment\">#{ipv4Addr}</font> \n>已解析的域名:<font color=\"comment\">#{ipv4Domains}</font>" } }

Screenshot_2024-01-20-18-12-45-773_com tencent we

@NEANC
Copy link

NEANC commented Jan 20, 2024

钉钉

{
    "msgtype": "markdown",
    "markdown": {
        "title": "您的公网IP已变更:",
        "text": "**公网IP已变更:**  \n ------IPv4------  \n 域名更新结果:**<font color=\"warning\">#{ipv4Result}</font>**  \n 新IPV4地址:#{ipv4Addr}  \n 已解析的域名:#{ipv4Domains}  \n ------IPv6------  \n 域名更新结果:**<font color=\"warning\">#{ipv6Result}</font>**  \n 新IPv6地址:#{ipv6Addr}  \n 已解析的域名:#{ipv6Domains}  \n ------DDNS-GO------\n"
    }
}

PixPin_2024-01-20_22-30-03

@shaojs321
Copy link

用文本格式可在微信中直接看 Webhook地址填入ddns-go后台Webhook URL地址栏。 在RequestBody栏填入回调函数,格式:

{ "msgtype": "text","text": {"content": "公网IP变更:\n 新IP地址:#{ipv4Addr} \n 已解析的域名:#{ipv4Domains} \n 域名更新结果:#{ipv4Result} \n 新IP地址:#{ipv6Addr} \n 已解析的域名:#{ipv6Domains} \n 域名更新结果:#{ipv6Result}" } }" } }

Screenshot_2023-12-12-14-02-02-546_com.tencent.mm.png

在微信中怎么看啊

@shaojs321
Copy link

使用CF 反代TG api,通知自建BOT

新建CF Workers,填入以下内容,并使用自定义域

const tg_host = "api.telegram.org";
addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
    var u = new URL(request.url);
    u.host = tg_host;
    var req = new Request(u, {
        method: request.method,
        headers: request.headers,
        body: request.body
    });
    const result = await fetch(req);
    return result;
}
  • 例如:你的自定义域www.tiktok.com,那么api.telegram.org=www.tiktok.com

自建BOT

DDNS-GOWebhook填写

  • URL:
# 注意:bot后直接接Token,没有其它符号
https://www.tiktok.com/bot<自建BOT Token>/sendmessage
  • RequestBody:
{
  "chat_id": "你自己的UserID",
  "text": "主人!您的 IP 有变化\n\nIPv4: #{ipv4Result}\nIP: #{ipv4Addr}\n域名: telegram.org\n\nIPv6: #{ipv6Result}\nIP: #{ipv6Addr}\n域名: telegram.org"
}
image

这个是不能用了吗,ddnsgo上webhook模拟测试总是有问题 Webhook调用失败! 异常信息:返回内容: error code: 522 ,返回状态码: 522

@WorldHim
Copy link

WorldHim commented Feb 16, 2024

WxPusher

URL: https://wxpusher.zjiecode.com/api/send/message
RequestBody:

{
  "appToken":"AT_xxx", //填入 AppToken
  "content":"新的 IPv4 地址: #{ipv4Addr}\n影响域名: #{ipv4Domains}\n更新结果: #{ipv4Result}\n新的 IPv6 地址: #{ipv6Addr}\n影响域名: #{ipv6Domains}\n更新结果: #{ipv6Result}",
  "summary":"IPv4: #{ipv4Addr} #{ipv4Result} | IPv6: #{ipv6Addr} #{ipv6Result}",
  "contentType":1,
  "topicIds":[
      114514 //填入 TopicID
  ]
}

@fudadds
Copy link

fudadds commented Feb 21, 2024

gotify 自建的多平台推送方案。

URL: http://x.x.x.x.:port/message?token=AXWpiJam7V_rSwW
RequestBody: 为json格式
{
"title": "公网IP变动了",
"message": "新IPV4地址:#{ipv4Addr}\n已解析的域名:#{ipv4Domains}\n域名更新结果:#{ipv4Result}\n\n 新IPV6地址:#{ipv6Addr}\n已解析的域名:#{ipv6Domains}\n域名更新结果:#{ipv6Result}\n\n------DDNS-GO-----"
}

@Jackie264
Copy link

企业微信

下载企业微信→左上角三横杠→全新创建企业→个人组件团队(创建个人的企业群聊), 进入群聊添加 [群机器人] 复制机器人Webhook地址填入ddns-go后台Webhook URL地址栏。 在RequestBody栏填入回调函数,格式:

{ "msgtype": "markdown","markdown": { "content": "公网IP变更:\n 新IPV6地址:#{ipv6Addr} \n 已解析的域名:#{ipv6Domains} \n 域名更新结果:#{ipv6Result}" } }

2024/03/02 17:48:16 Webhook called successfully! Response body: {"errcode":0,"errmsg":"ok. WARNING: invalid character after json. "}
消息是推送过来了,但是日志里面显示错误
Screenshot 2024-03-02 at 17 49 08

@lxgz12345
Copy link

企业微信

下载企业微信→左上角三横杠→全新创建企业→个人组件团队(创建个人的企业群聊), 进入群聊添加 [群机器人] 复制机器人Webhook地址填入ddns-go后台Webhook URL地址栏。 在RequestBody栏填入回调函数,格式:

{ "msgtype": "markdown","markdown": { "content": "公网IP变更:\n 新IPV6地址:#{ipv6Addr} \n 已解析的域名:#{ipv6Domains} \n 域名更新结果:#{ipv6Result}" } }

2024/03/02 17:48:16 Webhook called successfully! Response body: {"errcode":0,"errmsg":"ok. WARNING: invalid character after json. "} 消息是推送过来了,但是日志里面显示错误 屏幕截图 2024-03-02 at 17 49 08

把填写的Webhook放到 在线json网站 中,如果报错就肯定是你填的Webhook不对,有语法错误

@iNewWay
Copy link

iNewWay commented Mar 4, 2024

企业微信 - 机器人

创建企业内部群聊,进入群聊,右上角三个点->群机器人->添加 [群机器人],复制机器人Webhook地址填入ddns-go后台Webhook URL地址栏,在RequestBody栏填入回调函数,

RequestBody格式:
{ "msgtype": "text", "text": { "content": "°o.O【公网IP变更通知】O.o°
⋆⌁⌁⌁⋆⌁⌁❤︎⌁⌁⌁⋆⌁⌁⌁❤︎⌁⌁⋆⌁⌁⌁⋆
IPv4:#{ipv4Addr}
域名:#{ipv4Domains}
结果:解析#{ipv4Result}
𓆟𓆜𓆞𓆝𓆟𓆜𓆞𓆝𓆟𓆜
IPv6:#{ipv6Addr}
域名:#{ipv6Domains}
结果:解析#{ipv6Result}" } }

预览图:
微信图片_20240304201536

@hjh165
Copy link

hjh165 commented Mar 8, 2024

用的方糖(Server酱),示例中只是推送title,把Body也一起加进去了:
https://sctapi.ftqq.com/Token.send?title=公网IP更新了&desp=新的IPv4地址<#{ipv4Addr}>,已解析域名<#{ipv4Domains}>,IPv4域名更新结果<#{ipv4Result}>。新的IPv6地址<#{ipv6Addr}>,已解析域名<#{ipv6Domains}>,IPv6域名更新结果<#{ipv6Result}>。
预览图:
8e1bff93aacf5536c171b8f126ffbfe

Repository owner deleted a comment from even0306 Mar 14, 2024
@2499751842
Copy link

{ "msgtype": "text", "text": { "content": "🍯🍯【公网IP变更通知】🍯🍯
🚞🚃🚃🚃💨
IPv4地址:#{ipv4Addr}
已解析域名:#{ipv4Domains}
IPv4更新结果:#{ipv4Result}
𓆟𓆜𓆞𓆝𓆟𓆜𓆞𓆝𓆟𓆜
IPv6地址:#{ipv6Addr}
已解析域名:#{ipv6Domains}
IPv6更新结果:#{ipv6Result}" } }
20240425-222825

@xiaobaozi233
Copy link

pushdeer


URL: https://api2.pushdeer.com/message/push?pushkey=yourkey

RequestBody:

{
    "title": "你的公网IP变了",
    "text": "\n ipv4是:#{ipv4Addr}  \n 域名更新结果:#{ipv4Result}  \n 更新的域名是:#{ipv4Domains}",
    "type": "markdown"
}

@sztuxp
Copy link

sztuxp commented Jun 13, 2024

使用CF 反代TG api,通知自建BOT

新建CF Workers,填入以下内容,并使用自定义域

const tg_host = "api.telegram.org";
addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
    var u = new URL(request.url);
    u.host = tg_host;
    var req = new Request(u, {
        method: request.method,
        headers: request.headers,
        body: request.body
    });
    const result = await fetch(req);
    return result;
}
  • 例如:你的自定义域www.tiktok.com,那么api.telegram.org=www.tiktok.com

自建BOT

DDNS-GOWebhook填写

  • URL:
# 注意:bot后直接接Token,没有其它符号
https://www.tiktok.com/bot<自建BOT Token>/sendmessage
  • RequestBody:
{
  "chat_id": "你自己的UserID",
  "text": "主人!您的 IP 有变化\n\nIPv4: #{ipv4Result}\nIP: #{ipv4Addr}\n域名: telegram.org\n\nIPv6: #{ipv6Result}\nIP: #{ipv6Addr}\n域名: telegram.org"
}
image

现在主要问题是域名被qiang, 用这个方案可以解决

@yw1573
Copy link

yw1573 commented Jun 19, 2024

anpush
可以推送至
image
免费账户,每天30条
post请求:
curl --location --request POST 'https://api.anpush.com/push/your_token'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'title=your_title'
--data-urlencode 'content=your_content'
--data-urlencode 'channel=your_channel'

get请求:
curl --location --request GET 'https://api.anpush.com/push/your_token?title=your_title&content=your_content&channel=your_channel'

image

支持markdown格式的消息内容

image

@shaojs321
Copy link

用文本格式可在微信中直接看
Webhook地址填入ddns-go后台Webhook URL地址栏。 在RequestBody栏填入回调函数,格式:

我目前也是这样做的,只能使用text格式,markdown的话,个人微信看不了,只能跳转到企业微信,你有什么办法不

@zraxx
Copy link

zraxx commented Jun 26, 2024

用文本格式可在微信中直接看
Webhook地址填入ddns-go后台Webhook URL地址栏。 在RequestBody栏填入回调函数,格式:

我目前也是这样做的,只能使用text格式,markdown的话,个人微信看不了,只能跳转到企业微信,你有什么办法不

企业微信中拉入个人微信号

@getiid
Copy link

getiid commented Jun 30, 2024

24年最新使用CF 反代TG api,通知自建BOT

新建CF Workers,填入以下内容,并使用自定义域

/**
 * Helper functions to check if the request uses
 * corresponding method.
 *
 */
const Method = (method) => (req) => req.method.toLowerCase() === method.toLowerCase();
const Get = Method('get');
const Post = Method('post');

const Path = (regExp) => (req) => {
	const url = new URL(req.url);
	const path = url.pathname;
	return path.match(regExp) && path.match(regExp)[0] === path;
};

/*
 * The regex to get the bot_token and api_method from request URL
 * as the first and second backreference respectively.
 */
const URL_PATH_REGEX = /^\/bot(?<bot_token>[^/]+)\/(?<api_method>[a-z]+)/i;

/**
 * Router handles the logic of what handler is matched given conditions
 * for each request
 */
class Router {
	constructor() {
		this.routes = [];
	}

	handle(conditions, handler) {
		this.routes.push({
			conditions,
			handler,
		});
		return this;
	}

	get(url, handler) {
		return this.handle([Get, Path(url)], handler);
	}

	post(url, handler) {
		return this.handle([Post, Path(url)], handler);
	}

	all(handler) {
		return this.handler([], handler);
	}

	route(req) {
		const route = this.resolve(req);

		if (route) {
			return route.handler(req);
		}

		const description = 'No matching route found';
		const error_code = 404;

		return new Response(
			JSON.stringify({
				ok: false,
				error_code,
				description,
			}),
			{
				status: error_code,
				statusText: description,
				headers: {
					'content-type': 'application/json',
				},
			}
		);
	}

	/**
	 * It returns the matching route that returns true
	 * for all the conditions if any.
	 */
	resolve(req) {
		return this.routes.find((r) => {
			if (!r.conditions || (Array.isArray(r) && !r.conditions.length)) {
				return true;
			}

			if (typeof r.conditions === 'function') {
				return r.conditions(req);
			}

			return r.conditions.every((c) => c(req));
		});
	}
}

/**
 * Sends a POST request with JSON data to Telegram Bot API
 * and reads in the response body.
 * @param {Request} request the incoming request
 */
async function handler(request) {
	// Extract the URl method from the request.
	const { url, ..._request } = request;

	const { pathname: path, search } = new URL(url);

	// Leave the first match as we are interested only in backreferences.
	const { bot_token, api_method } = path.match(URL_PATH_REGEX).groups;

	// Build the URL
	const api_url = 'https://api.telegram.org/bot' + bot_token + '/' + api_method + search;

	// Get the response from API.
	const response = await fetch(api_url, _request);

	const result = await response.text();

	const res = new Response(result, _request);

	res.headers.set('Content-Type', 'application/json');

	return res;
}

/**
 * Handles the incoming request.
 * @param {Request} request the incoming request.
 */
async function handleRequest(request) {
	const r = new Router();
	r.get(URL_PATH_REGEX, (req) => handler(req));
	r.post(URL_PATH_REGEX, (req) => handler(req));

	const resp = await r.route(request);
	return resp;
}

/**
 * Hook into the fetch event.
 */
addEventListener('fetch', (event) => {
	event.respondWith(handleRequest(event.request));
});

什么都不要动直接复制粘贴进去。其他步骤和以前一直。

然后添加workers的路由,指向这个workers。

也可以不做。

### 这个地址需要外网访问
https://api.telegram.org/bot<bot的token>/sendMessage?chat_id=<tg用户的id>&text=<发送内容>
### 这个地址在国内就可以访问
https://tg.你的域名/bot<bot的token>/sendMessage?chat_id=<tg用户的id>&text=<发送内容>

@MC-MineFeng
Copy link

QQ机器人LLOneBot

LLOneBot如何安装,自己看: https://llonebot.github.io/

LLOneBot下载: 需要版本QQNT
https://github.com/super1207/install_llob/releases/download/0.0.4/llob_install.exe

然后启用HTTP 默认3000端口

QQ截图20240702140341

在DDNS-GO如下写就行了 user_id 写需要发送消息的QQ号

URL:http://localhost:3000/send_private_msg?user_id=QQ号

RequestBody:
{"message": "公网IP变更:\n\n域名更新结果:#{ipv6Result} \n\n新IPV6地址:#{ipv6Addr} \n\n已解析的域名:#{ipv6Domains} "}

QQ截图20240702135657

以下就是享有效果:
QQ截图20240702140928
4079140467B81444FC84D0CB8EE34C88

@ashxlong
Copy link

ashxlong commented Oct 7, 2024

ddns-telegram-bot是不是挂了,提示“Webhook调用失败! 异常信息:Post "https://ddns-bot.vercel.app/api/hook/xxxxxxxxx?": dial tcp 173.236.182.137:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests