Skip to content

Commit e513950

Browse files
committed
update readme & installing
1 parent c51cb34 commit e513950

File tree

2 files changed

+107
-2
lines changed

2 files changed

+107
-2
lines changed

README.md

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,110 @@
1616
- PHP ^8.0
1717
- Composer
1818
- Telegram Bot
19+
- SSL Certificate
1920

2021
## Installation
2122

22-
You can clone and install this project via [Composer](https://getcomposer.org/):
23+
The first, please clone and install this project via [Composer](https://getcomposer.org/):
2324

2425
```bash
2526
composer create-project lbiltech/telegram-bot-github-notify
2627
```
2728

28-
...
29+
After running the command above, you will have the project installed under `telegram-bot-github-notify` directory,
30+
and the environment file `.env` will be created automatically.
31+
32+
### Create a New Bot
33+
34+
To create a new bot, you need to talk to [BotFather](https://core.telegram.org/bots#6-botfather) and follow a few simple steps.
35+
36+
1. Open a chat with [BotFather](https://telegram.me/botfather) and send `/newbot` command.
37+
2. Enter a friendly name for your bot. This name will be displayed in contact details and elsewhere.
38+
3. Enter a unique username for your bot. It must end in `bot`. Like this, for example: `TetrisBot` or `tetris_bot`.
39+
4. Copy the HTTP API access token provided by [BotFather](https://telegram.me/botfather) and paste it in your `.env` file.
40+
41+
```shell
42+
TELEGRAM_BOT_TOKEN=123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ
43+
```
44+
45+
### Get your Chat ID and add it to the .env file
46+
47+
1. Open a chat with your bot.
48+
2. Send a message to your bot.
49+
3. Go to the following URL: `https://api.telegram.org/bot<YourBOTToken>/getUpdates`
50+
4. Look for the `"chat":{"id":` field and copy the number after it. This is your Chat ID.
51+
5. Paste the Chat ID in your `.env` file.
52+
53+
```shell
54+
TELEGRAM_BOT_CHAT_ID=123456789
55+
```
56+
57+
### Set the webhook
58+
59+
#### Set the webhook from source code
60+
61+
After setting up your domain and SSL certificate, you need to set the webhook for your bot. Go to:
62+
63+
```http request
64+
<APP_URL>/setWebhook.php
65+
```
66+
67+
If you see the following message, it means that the webhook has been set successfully.
68+
69+
```json
70+
{"ok":true,"result":true,"description":"Webhook was set"}
71+
```
72+
73+
#### Set the webhook manually
74+
75+
If you want to set the webhook manually, you can use the following url:
76+
77+
```http request
78+
https://api.telegram.org/bot<YourBOTToken>/setWebhook?url=<APP_URL>
79+
```
80+
81+
### Add chat ids you want to receive notifications to the .env file
82+
83+
```shell
84+
TELEGRAM_NOTIFY_CHAT_IDS="123456789,987654321,-123456789"
85+
```
86+
87+
Now your configuration is complete. And it will be like this:
88+
89+
```shell
90+
APP_NAME='Telegram Github Notify Bot'
91+
92+
# Set your app url here
93+
APP_URL=https://tele-noti-git.com
94+
95+
TELEGRAM_BOT_TOKEN=6162840106:AAH3g20lMQIkG_wHHu8R_ngdtG541uzoq4
96+
TELEGRAM_BOT_CHAT_ID=6872320129
97+
98+
# Set your telegram group chat ids here ( please use comma to separate )
99+
TELEGRAM_NOTIFY_CHAT_IDS="-978339113,-1001933979183"
100+
101+
TIMEZONE=Asia/Ho_Chi_Minh
102+
```
103+
104+
## Usage
105+
106+
Now you can send a message to your bot, and you will receive a notification.
107+
108+
```text
109+
/start
110+
```
111+
112+
## Set webhook on your GitHub repository
113+
114+
1. Go to your repository settings
115+
2. Go to `Webhooks` section
116+
3. Click on `Add webhook`
117+
4. Set `Payload URL` to `<APP_URL>`
118+
5. Set `Content type` to `application/x-www-form-urlencoded`
119+
6. Which events would you like to trigger this webhook? Select `Let me select individual events.`
120+
7. Click on `Active` checkbox and Add webhook button.
121+
8. Done. You will receive a notification when your repository has a new event.
122+
123+
Here is the first notification you will receive: ♻️ **Connection Successful**
124+
125+
> **You can add multiple webhooks to your repository.**

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,13 @@
4545
"config": {
4646
"sort-packages": true,
4747
"optimize-autoloader": true
48+
},
49+
"scripts": {
50+
"post-install-cmd": [
51+
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
52+
],
53+
"post-update-cmd": [
54+
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
55+
]
4856
}
4957
}

0 commit comments

Comments
 (0)