🛠 Configuration
Once installed, please follow the instructions below to configure the package properly.
Create a New Bot and Get the Token
To create a new bot, you need to talk to BotFather and follow a few simple steps.
- Open a chat with BotFather and send
/newbot
command. - 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:TetrisBot
ortetris_bot
. - Copy the HTTP API access token provided by BotFather and paste it into your
.env
file.
TELEGRAM_BOT_TOKEN=123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ
Get Your Chat ID
To get your chat ID, you need to talk to IDBot and follow a few simple steps.
- Open a chat with IDBot and send
/getid
command. - Copy the chat ID provided by IDBot and paste it into your
.env
file.
TELEGRAM_BOT_CHAT_ID=123456789
Set the tool URL for Webhook Requests
You need to set the URL so that the webhook from GitHub or GitLab sends a request when an event occurs.
By default, Laravel already has the APP_URL variable. If you have updated this variable, it is not necessary to update the TGN_APP_URL variable anymore.
But if for some reason the APP_URL variable can't match the actual address of the website, you need to add actual address to the TGN_APP_URL variable.
TGN_APP_URL=http://localhost:8000
http://localhost:8000
is only used for testing purposes. You need to use a real domain name or IP address.
So now, the telegram-git-notifier tool will be available at the following address:
http://localhost:8000/telegram-git-notifier
telegram-git-notifier
is the default route prefix of the tool.
- You can change it in the
config/tg-notifier.php
file with thedefaults.route_prefix
key. - Or you can change it in the
.env
file with theTGN_DEFAULT_ROUTE_PREFIX
key.
-> The tool will be available at the following address: http://localhost:8000/{route_prefix}
.
Set the webhook
You need to set the webhook to tool URL
so that the webhook from GitHub or GitLab sends a request when an event occurs. You can choose one of the two following methods.
Method 1: Using with the command in console
Run the following command to set the webhook.
php artisan tg-notifier:webhook:set
Method 2: Using with the webhook route
Go to the tool URL
/webhook/set route to set the webhook.
Example: (Access via your browser)
http://localhost:8000/telegram-git-notifier/webhook/set
If you see the following message, it means that the webhook has been sent successfully.
{"ok":true,"result":true,"description":"Webhook was set"}
Set the Chat IDs That Will Receive Notifications
You can add the owner bot ID, group ID, supper group with multiple topics ID, ...
- The
TELEGRAM_NOTIFY_CHAT_IDS
variable is optional. - Please use semicolon
;
to separate chat IDs. - And use a colon
:
to separate chat ID and topic(Thread ID). - And use the comma
,
if you want to add multiple topics(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;...
Example:
TELEGRAM_NOTIFY_CHAT_IDS="-978339113;-1001933979183:2,13;6872320129"
Conclusion
So, the .env file will require to have the following contents:
TELEGRAM_BOT_TOKEN=123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ
TELEGRAM_BOT_CHAT_ID=123456789
TGN_APP_URL=http://localhost:8000
TELEGRAM_NOTIFY_CHAT_IDS="-978339113;-1001933979183:2,13;6872320129"