|
16 | 16 | - PHP ^8.0 |
17 | 17 | - Composer |
18 | 18 | - Telegram Bot |
| 19 | +- SSL Certificate |
19 | 20 |
|
20 | 21 | ## Installation |
21 | 22 |
|
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/): |
23 | 24 |
|
24 | 25 | ```bash |
25 | 26 | composer create-project lbiltech/telegram-bot-github-notify |
26 | 27 | ``` |
27 | 28 |
|
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.** |
0 commit comments