deployer/docs/contrib/telegram.md

156 lines
3.0 KiB
Markdown
Raw Normal View History

2021-09-26 15:25:58 +02:00
<!-- DO NOT EDIT THIS FILE! -->
<!-- Instead edit contrib/telegram.php -->
<!-- Then run bin/docgen -->
2022-07-26 09:18:44 +02:00
# Telegram Recipe
2021-09-26 15:25:58 +02:00
2022-09-12 12:29:44 +02:00
```php
require 'contrib/telegram.php';
```
2021-09-26 15:25:58 +02:00
[Source](/contrib/telegram.php)
2021-11-06 19:02:51 +01:00
2021-09-26 15:25:58 +02:00
## Installing
1. Create telegram bot with [BotFather](https://t.me/BotFather) and grab the token provided
2. Send `/start` to your bot and open https://api.telegram.org/bot{$TELEGRAM_TOKEN_HERE}/getUpdates
3. Take chat_id from response
Add hook on deploy:
```php
before('deploy', 'telegram:notify');
```
## Configuration
- `telegram_token` telegram bot token, **required**
- `telegram_chat_id` — chat ID to push messages to
- `telegram_proxy` - proxy connection string in [CURLOPT_PROXY](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html) form like:
```
http://proxy:80
socks5://user:password@host:3128
```
- `telegram_title` the title of application, default `{{application}}`
- `telegram_text` notification message template
```
_{{user}}_ deploying `{{branch}}` to *{{target}}*
```
- `telegram_success_text` success template, default:
```
Deploy to *{{target}}* successful
```
- `telegram_failure_text` failure template, default:
```
Deploy to *{{target}}* failed
```
## Usage
If you want to notify only about beginning of deployment add this line only:
```php
before('deploy', 'telegram:notify');
```
If you want to notify about successful end of deployment add this too:
```php
after('deploy:success', 'telegram:notify:success');
```
If you want to notify about failed deployment add this too:
```php
after('deploy:failed', 'telegram:notify:failure');
## Configuration
### telegram_title
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L63)
2021-09-26 15:25:58 +02:00
Title of project
2022-09-12 12:53:42 +02:00
```php title="Default value"
return get('application', 'Project');
```
2021-09-26 15:25:58 +02:00
### telegram_token
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L68)
2021-09-26 15:25:58 +02:00
Telegram settings
2022-09-12 12:53:42 +02:00
:::info Required
Throws exception if not set.
:::
2021-09-26 15:25:58 +02:00
### telegram_chat_id
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L71)
2021-09-26 15:25:58 +02:00
2022-09-12 12:53:42 +02:00
:::info Required
Throws exception if not set.
:::
2021-09-26 15:25:58 +02:00
### telegram_url
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L74)
2021-09-26 15:25:58 +02:00
2022-09-12 12:53:42 +02:00
```php title="Default value"
return 'https://api.telegram.org/bot' . get('telegram_token') . '/sendmessage';
```
2021-09-26 15:25:58 +02:00
### telegram_text
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L79)
2021-09-26 15:25:58 +02:00
Deploy message
```php title="Default value"
'_{{user}}_ deploying `{{branch}}` to *{{target}}*'
```
### telegram_success_text
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L80)
2021-09-26 15:25:58 +02:00
```php title="Default value"
'Deploy to *{{target}}* successful'
```
### telegram_failure_text
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L81)
2021-09-26 15:25:58 +02:00
```php title="Default value"
'Deploy to *{{target}}* failed'
```
## Tasks
### telegram:notify
2022-09-12 12:29:44 +02:00
[Source](https://github.com/deployphp/deployer/blob/master/contrib/telegram.php#L85)
2021-09-26 15:43:51 +02:00
2021-11-08 22:59:39 +01:00
Notifies Telegram.
2021-09-26 15:25:58 +02:00