docs/contrib/slack.md
<!-- DO NOT EDIT THIS FILE! -->
<!-- Instead edit contrib/slack.php -->
<!-- Then run bin/docgen -->
# Slack Recipe
```php
require 'contrib/slack.php';
```
[Source](/contrib/slack.php)
## Installing
<a href="https://slack.com/oauth/authorize?&client_id=113734341365.225973502034&scope=incoming-webhook"><img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/add_to_slack.png" srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x" /></a>
Add hook on deploy:
```php
before('deploy', 'slack:notify');
```
## Configuration
- `slack_webhook` – slack incoming webhook url, **required**
```
set('slack_webhook', 'https://hooks.slack.com/...');
```
- `slack_channel` - channel to send notification to. The default is the channel configured in the webhook
- `slack_title` – the title of application, default `{{application}}`
- `slack_text` – notification message template, markdown supported
```
set('slack_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
```
- `slack_success_text` – success template, default:
```
set('slack_success_text', 'Deploy to *{{target}}* successful');
```
- `slack_failure_text` – failure template, default:
```
set('slack_failure_text', 'Deploy to *{{target}}* failed');
```
- `slack_color` – color's attachment
- `slack_success_color` – success color's attachment
- `slack_failure_color` – failure color's attachment
- `slack_fields` - set attachments fields for pretty output in Slack, default:
```
set('slack_fields', []);
```
## Usage
If you want to notify only about beginning of deployment add this line only:
```php
before('deploy', 'slack:notify');
```
If you want to notify about successful end of deployment add this too:
```php
after('deploy:success', 'slack:notify:success');
```
If you want to notify about failed deployment add this too:
```php
after('deploy:failed', 'slack:notify:failure');
```
## Configuration
### slack_channel
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L69)
Channel to publish to, when false the default channel the webhook will be used
```php title="Default value"
false
```
### slack_title
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L72)
Title of project
```php title="Default value"
return get('application', 'Project');
```
### slack_text
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L77)
Deploy message
```php title="Default value"
'_{{user}}_ deploying `{{target}}` to *{{hostname}}*'
```
### slack_success_text
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L78)
```php title="Default value"
'Deploy to *{{target}}* successful'
```
### slack_failure_text
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L79)
```php title="Default value"
'Deploy to *{{target}}* failed'
```
### slack_rollback_text
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L80)
```php title="Default value"
'_{{user}}_ rolled back changes on *{{target}}*'
```
### slack_fields
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L81)
### slack_color
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L84)
Color of attachment
```php title="Default value"
'#4d91f7'
```
### slack_success_color
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L85)
```php title="Default value"
'#00c100'
```
### slack_failure_color
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L86)
```php title="Default value"
'#ff0909'
```
### slack_rollback_color
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L87)
```php title="Default value"
'#eba211'
```
## Tasks
### slack:notify
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L99)
Notifies Slack.
### slack:notify:success
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L119)
Notifies Slack about deploy finish.
### slack:notify:failure
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L140)
Notifies Slack about deploy failure.
### slack:notify:rollback
[Source](https://github.com/deployphp/deployer/blob/master/contrib/slack.php#L160)
Notifies Slack about rollback.