Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Telegram failed notify (#207)
Browse files Browse the repository at this point in the history
* Telegram deploy failure support

* Update documentation for telegram recipe
  • Loading branch information
asafov authored and antonmedv committed Jan 17, 2019
1 parent f330fd5 commit 4c24707
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/telegram.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ before('deploy', 'telegram:notify');
- `telegram_success_text` – success template, default:
```
Deploy to *{{target}}* successful
```
- `telegram_failure_text` – failure template, default:
```
Deploy to *{{target}}* failed
```

## Tasks

- `telegram:notify` – send message to telegram
- `telegram:notify:success` – send success message to telegram
- `telegram:notify:failure` – send failure message to telegram

## Usage

Expand All @@ -53,4 +59,8 @@ If you want to notify about successful end of deployment add this too:
```php
after('success', 'telegram:notify:success');
```
If you want to notify about failed deployment add this too:

```php
after('deploy:failed', 'telegram:notify:failure');

33 changes: 32 additions & 1 deletion recipe/telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
2. Take telegrambot token (Like: 123456789:SOME_STRING) and set `telegram_token` parameter
3. Send /start to your bot, open https://api.telegram.org/bot{telegram_token}/getUpdates
4. Take chat_id from response, and set `telegram_chat_id` parameter
5. If you want, you can edit `telegram_text` and `telegram_success_text`
5. If you want, you can edit `telegram_text`, `telegram_success_text` or `telegram_failure_text`
6. Profit!
*/
namespace Deployer;
Expand All @@ -31,6 +31,7 @@
// Deploy message
set('telegram_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
set('telegram_success_text', 'Deploy to *{{target}}* successful');
set('telegram_failure_text', 'Deploy to *{{target}}* failed');


desc('Notifying Telegram');
Expand Down Expand Up @@ -93,3 +94,33 @@
->once()
->shallow()
->setPrivate();

desc('Notifying Telegram about deploy failure');
task('telegram:notify:failure', function () {
if (!get('telegram_token', false)) {
return;
}

if (!get('telegram_chat_id', false)) {
return;
}

$telegramUrl = get('telegram_url') . '?' . http_build_query (
Array (
'chat_id' => get('telegram_chat_id'),
'text' => get('telegram_failure_text'),
'parse_mode' => 'Markdown',
)
);

$httpie = Httpie::get($telegramUrl);

if (get('telegram_proxy', '') !== '') {
$httpie = $httpie->setopt(CURLOPT_PROXY, get('telegram_proxy'));
}

$httpie->send();
})
->once()
->shallow()
->setPrivate();

0 comments on commit 4c24707

Please sign in to comment.