lbiltech/telegram-bot-github-notify
最新稳定版本:v1.3.1
Composer 安装命令:
composer create-project lbiltech/telegram-bot-github-notify
包简介
The PHP app to send notification from Gitlab and Github events to Telegram
关键字:
README 文档
README
Warning
⚠️ This Project is Deprecated – Use the New Laravel Package
- This project is outdated as it is built on a pure PHP source code.
- Instead, we highly recommend using our latest Laravel package, which offers:
- Better security with built-in authentication and protection mechanisms.
- More features for modern web development.
- Active maintenance and community support.
- 👉 Click here to explore the new Laravel Telegram Git Notifier package
Welcome to Telegram Bot GitHub/GitLab Notify 👋
This package provides the ability to integrate the Telegram messaging service and GitHub/GitLab. With this package, you can create a Telegram bot to receive notifications from GitHub or GitLab events and manage customization through messages and buttons on Telegram.
📝 Information
- Send notifications of your GitHub/GitLab repositories to Telegram Bots, Groups, Super Groups (Multiple Topics), and Channels.
- The bot must be created using the BotFather
🎉 Features
- GitHub/GitLab Notifications to Telegram: The package allows you to configure a Telegram bot to receive notifications from various GitHub/GitLab events, including events like commits, pull requests, issues, releases, and many more.
- Customize Notifications: You can customize the types of notifications you want to receive through options on Telegram.
- Interactive Buttons: The package supports creating interactive buttons on Telegram to perform actions such as enabling or disabling notifications.
-
Event Management: You can manage specific events that you want to receive notifications for, allowing you to focus on what's most important for your projects.
- Support for multiple platforms: GitHub and GitLab.
- Manage event notifications separately between platforms.
- Easy Integration: The package provides an API and user-friendly functions to create a Telegram bot and link it to your GitHub/GitLab account.
- Support for multiple chats: You can add multiple chat IDs to the
.envfile. These chat IDs will be the chat IDs of your groups, channels, or users. Also, you can add the chat ID of this bot to receive incoming notifications for itself.
- For premium users, you can use the following features:
- Support for multiple topics: You can add multiple topics to the
.envfile. These topics will be the topics of your supergroups.
- Support for multiple topics: You can add multiple topics to the
📋 Requirements
- PHP ^8.1
- Composer
- Core: Telegram Git Notifier
🔧 Installation
As for the installation and configuration, this project provides two different installation ways depending on your preference or suitability for your system.
Way 1: Install by composer directly on the system (Requires the system to install composer, previous PHP version)
Way 2: Install by Docker (Requires the system to install Docker, Docker Compose)
I. Installation and configuration 🛠
Please choose only one of the following two ways to set up the project.
Way 1: Install by composer directly on the system ⚙
First, please clone and install this project via Composer:
composer create-project cslant/telegram-git-notifier-app
After running the command above, you will have the project installed under the telegram-git-notifier-app directory,
and the environment file .env will be created automatically.
Some of the JSON files will be created automatically in the storage directory.
These files are used to store the data and serve for features in this bot.
1. Create a New Bot
To create a new bot, you need to talk to BotFather and follow a few simple steps.
- Open a chat with BotFather and send
/newbotcommand. - Enter a friendly name for your bot. This name will be displayed in contact details and elsewhere.
- Enter a unique username for your bot. It must end in
bot. Like this, for example:TetrisBotortetris_bot. - Copy the HTTP API access token provided by BotFather and paste it into your
.envfile.
TELEGRAM_BOT_TOKEN=123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ
2. Set up your domain and SSL certificate
We recommend that you use HTTPS to set up your domain and webhook. You can build your own server or use a service like Heroku.
In this example, we will use localhost and ngrok to set up the domain and webhook:
- Download and install ngrok.
- Go to this project directory and run the command in the terminal:
php -S localhost:8000 - Continue to run the command in the terminal:
ngrok http 8000 - Copy the HTTPS URL provided by ngrok and paste it into your
.envfile.
TGN_APP_URL=https://123456789.ngrok.io
3. Get your Chat ID and add it to the .env file
- Open a chat with your bot.
- Send any message to your bot. (This handle needs to get your chat ID)
- Go to the following URL:
<TGN_APP_URL>/webhooks/getUpdate.php - Look for the
"chat":{"id":field and copy the number after it. This is your Chat ID. - Paste the Chat ID in your
.envfile.
TELEGRAM_BOT_CHAT_ID=123456789
At this time, the source launch process is done, please skip way 2 and go to step II. Set the webhook to continue.
Way 2: Install by Docker 🐳
Note: This way requires the system to install Docker and Docker Compose.
⚠ If you set up the project by way one, please skip this way. 🚸
And go to step II. Set the webhook to continue.
First, please clone this project and copy the environment file .env.example to .env:
git clone git@github.com:cslant/telegram-git-notifier-app.git
cd telegram-git-notifier-app
cp .env.example .env
1. Update the environment variables
Open the .env file and update the following variables:
PHP_VERSION_SELECTED=8.2 APP_PORT=3180 # You can customize the container name to suit your needs using GitHub and GitLab CONTAINER_NAME=tgn-app
Note:
- The
PHP_VERSION_SELECTEDvariable is the PHP version you want to use in the container.- The
APP_PORTvariable is the port of the container. (Please don't set the same port as the host)- The
CONTAINER_NAMEvariable is the name of the container you want to create.
2. Install and run the container
Run the following command to install and run the container:
bash ./docker.sh
Some of the JSON files will be created automatically in the storage directory.
These files are used to store the data and serve for features in this bot.
3. Create a New Bot
To create a new bot, you need to talk to BotFather and follow a few simple steps.
- Open a chat with BotFather and send
/newbotcommand. - Enter a friendly name for your bot. This name will be displayed in contact details and elsewhere.
- Enter a unique username for your bot. It must end in
bot. Like this, for example:TetrisBotortetris_bot. - Copy the HTTP API access token provided by BotFather and paste it into your
.envfile.
TELEGRAM_BOT_TOKEN=123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ
4. Set up your domain and SSL certificate
In this way, we use the proxy in the container and ngrok to set up the domain and webhook:
- Check the proxy of the container:
docker inspect <CONTAINER_NAME>-nginx | grep IPAddress
Note: Replace
<CONTAINER_NAME>with the name of the container in .env file.
Example:
- Download and install ngrok.
- Continue to run the command in the terminal:
ngrok http <CONTAINER_IP>
Note: Replace
<CONTAINER_IP>is the IP address of the container in step 1.
Example:
ngrok http 172.28.0.3
- Copy the HTTPS URL provided by ngrok and paste it into your
.envfile.
TGN_APP_URL=https://123456789.ngrok-free.app
5. Get your Chat ID and add it to the .env file
- Open a chat with your bot.
- Send any message to your bot. (This handle needs to get your chat ID)
- Go to the following URL:
<TGN_APP_URL>/webhooks/getUpdate.php - Look for the
"chat":{"id":field and copy the number after it. This is your Chat ID. - Paste the Chat ID in your
.envfile.
TELEGRAM_BOT_CHAT_ID=123456789
II. Set the webhook
We have two ways to set the webhook:
1. Set the webhook from this project
After setting up your domain and SSL certificate, you need to set up the webhook for your bot.
Go to:
<APP_URL>/webhooks/set.php
Note: Replace
<APP_URL>with your app URL in .env file.
If you see the following message, it means that the webhook has been sent successfully.
{"ok":true,"result":true,"description":"Webhook was set"}
2. Set the webhook manually from Telegram
If you want to set the webhook manually, you can use the following URL:
https://api.telegram.org/bot<YourTelegramBotToken>/setWebhook?url=<APP_URL>
Note: Replace
<YourTelegramBotToken>with your bot token and<APP_URL>with your app URL in the.envfile.
III. Add chat IDs you want to receive notifications to the .env file
1. Add multiple chat IDs to the .env file.
These chat IDs will be the chat IDs of your groups, channels, or users.
Also, you can add the chat ID of this bot to receive incoming notifications for itself.
TELEGRAM_NOTIFY_CHAT_IDS="-978339113;-1001933979183"
2. Add a topic for supergroups with premium users (Thread ID)
You can add topic for supergroups with premium users (Thread ID).
These topics will be the topics of your supergroups.
TELEGRAM_NOTIFY_CHAT_IDS="-978339113;-1001933979183:topic_1;"
3. Add multiple topics for supergroups with premium users (Thread IDs)
You can add multiple topics for each supergroup with premium users (Thread IDs).
TELEGRAM_NOTIFY_CHAT_IDS="-978339113;-1001933979183:topic_1,topic_2;"
Note:
- Please use semicolon ";" to separate chat ids
- And use a colon ":" to separate chat ID and topic
- And use the comma "," if you want to add multiple topics
Now your configuration is complete. And the .env file will be like this:
TGN_APP_NAME='Telegram GitHub/GitLab Notify Bot' # Set your app URL here (Required for the bot to work properly) TGN_APP_URL=https://123456789.ngrok.io TELEGRAM_BOT_TOKEN=6162840106:AAH3g20lMQIkG_wHHu8R_ngdtG541uzoq4 TELEGRAM_BOT_CHAT_ID=6872320129 # Set the chat IDs that will receive notifications here. # You can add the owner bot ID, group id, ... # ------------------------------------------------------- # Note: # Please use semicolon ";" to separate chat ids # And use a colon ":" to separate chat ID and thread ID # And use comma "," if you want to add multiple thread ids # ------------------------------------------------------- # The environment variable is expected to be in the format: # "chat_id1;chat_id2:thread_id2;chat_id3:thread_id3_1,thread_id3_2;..." TELEGRAM_NOTIFY_CHAT_IDS="-978339113;-1001933979183:2,13;6872320129" TIMEZONE=Asia/Ho_Chi_Minh PHP_VERSION_SELECTED=8.2 CONTAINER_NAME=tgn-bot APP_PORT=3180
🚀 Usage
Now you can send a message to your bot, and you will receive a welcome message from the bot.
/start
If you want to check the menu, you can send the following message to your bot.
/menu
🎊 At this point, the configuration process for your telegram bot is completed. You can use all the features of this bot. 🎉🎉
To increase ease of use. Let's create a menu with a list of commands listed for you.
Please send the following message to your bot to create a menu button.
/set_menu
Now you will need to add the Webhook for your GitHub and GitLab repository to receive notifications.
📌 Add webhook on your GitHub repository to receive notifications
- Go to your repository settings.
- Go to the
Webhookssection. - Click on
Add webhook. - Set
Payload URLto<APP_URL>. - Set
Content typetoapplication/x-www-form-urlencoded. - Which events would you like to trigger this webhook? Select
Let me select individual events.. - Click on the
Activecheckbox and Add webhook button. - Done. You will receive a notification when your repository has a new event.
Here is the first notification you will receive:
📌 Add a webhook on your GitLab repository to receive notifications
- Go to your repository settings.
- Go to the
Webhookssection. - Click on
Add new webhook. - Set
URLto<APP_URL>. - Choose any
Triggeryou want. - Click on the
Enable SSL verificationcheckbox and Add webhook button.
Note: You can set up this webhook for different repositories. Please similarly set up the webhook for each repository.
Then every time one of those repositories appears an event, this telegram bot will immediately send you a notification.
lbiltech/telegram-bot-github-notify 适用场景与选型建议
lbiltech/telegram-bot-github-notify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 28, 最近一次更新时间为 2023 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notify」 「telegram-bot」 「git-webhook」 「telegram-notifier」 「github-notifier」 「github-telegram-bot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lbiltech/telegram-bot-github-notify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lbiltech/telegram-bot-github-notify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lbiltech/telegram-bot-github-notify 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Send notification from Gitlab and Github events to Telegram
Send notification from Gitlab and GitHub events to Telegram
The PHP app to send notification from Gitlab and Github events to Telegram
Laravel 5 Flash Notifications with icons and animations and with a timeout
Tools set for messenger managing. Allows you to send any content via Telegram, Viber, WhatsApp, VK and so on
Simple and convenient object-oriented implementation Telegram bot API with php version ^7.4 support. You'll like it)
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-29