Skip to content

一个简单的基于Python的Telegram机器人,配合Github Webhook实现仓库Commit消息的推送

License

Notifications You must be signed in to change notification settings

IcyBlue17/Github_pusher_telegram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Github_pusher_telegram



⭐️ 您的 Star 对我来说很有用!

部署

Docker

您可以通过一行命令快速部署项目:

docker run -d
--name github-pusher
-e TOKEN=<你的 token>
-e CHATID=<你的 chat_id>
-p 1145:1145 \
icymichiko/github_pusher_telegram:latest

环境变量说明:

环境变量 说明
TOKEN Telegram Bot Token,可以通过 @BotFather 获取
CHATID Telegram Chat ID ,可以通过机器人/第三方客户端等方式获取

配置 GitHub 仓库 Webhook

为了让 GitHub 仓库的提交信息发送到 Telegram 机器人,你需要在你的 GitHub 仓库中配置 Webhook。

1. 获取 Webhook URL

部署项目后,记住暴露的端口,假设服务器 IP 地址为 114.5.1.4,那么此时的 Webhook URL 为:

http://114.5.1.4:暴露的端口/github

可以根据情况自行反代(确保Webhook可用就行了)

2. 在 GitHub 仓库中添加 Webhook

  1. 进入需要配置推送的 GitHub 仓库,点击 Settings

  2. 找到 Webhooks 点击 Add webhook

  3. Payload URL 中输入上一步获取的Webhook URL(例如 http://114.5.1.4:1145/github)。

  4. Content type 设为 application/json

  5. Which events would you like to trigger this webhook? 中,选择 Just the push event,根据具体情况决定开不开启https

  6. 点击 Add webhook 完成配置。

3. 测试 Webhook

成功配置后,你可以尝试推送代码到 GitHub 仓库,或者在 Webhook 设置页面点击 Recent Deliveries 旁边的 Redeliver 按钮,来测试 Webhook 是否正常工作。
如果是群,你需要先@机器人发个/start后续机器人才能正常推送,私聊也要先发个/start。

如果配置成功,您会在 Telegram 中收到类似以下格式的消息:

🔨 在仓库 xxx/xxx 中有一个新的提交❕
📖 xxx by xxx
❕提交信息: 我喜欢你
⌚️提交时间: xxx

About

一个简单的基于Python的Telegram机器人,配合Github Webhook实现仓库Commit消息的推送

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published