@@ -10,7 +10,7 @@ A simple PHP package for sending messages to [Slack](https://slack.com)
1010with [ incoming webhooks] ( https://my.slack.com/services/new/incoming-webhook ) ,
1111focused on ease-of-use and elegant syntax.
1212
13- ** supports:** PHP ` 7.0 ` , ` 7.1 ` , ` 7.2 `
13+ ** supports:** PHP ` 7.1 ` , ` 7.2 ` , ` 7.3 ` , ` 7.4 ` or ` 8.0 `
1414** require:** ` guzzlehttp/guzzle ` any of versions ` ~6.0|~5.0|~4.0 `
1515
1616> This is the fork of popular, great, but abandoned package [ ` maknz/slack ` ] ( https://github.com/maknz/slack )
@@ -60,10 +60,10 @@ $client = new Maknz\Slack\Client('https://hooks.slack.com/...');
6060// use response_type (in_channel | ephemeral) to denote whether the message will be visible
6161// to others in the channel.
6262$settings = [
63- 'username' => 'Cyril',
64- 'channel' => '#accounting',
65- 'reponse_type' => 'in_channel',
66- 'link_names' => true
63+ 'username' => 'Cyril',
64+ 'channel' => '#accounting',
65+ 'reponse_type' => 'in_channel',
66+ 'link_names' => true
6767];
6868
6969$client = new Maknz\Slack\Client('https://hooks.slack.com/...', $settings);
@@ -121,66 +121,69 @@ $client->to('#accounting')->withIcon('http://example.com/accounting.png')->send(
121121
122122``` php
123123$client->to('#operations')->attach([
124- 'fallback' => 'Server health: good',
125- 'text' => 'Server health: good',
126- 'color' => 'danger',
124+ 'fallback' => 'Server health: good',
125+ 'text' => 'Server health: good',
126+ 'color' => 'danger',
127127])->send('New alert from the monitoring system'); // no message, but can be provided if you'd like
128128```
129129
130130#### Send an attachment with fields ([ preview] ( https://goo.gl/264mhU ) )
131131
132132``` php
133133$client->to('#operations')->attach([
134- 'fallback' => 'Current server stats',
135- 'text' => 'Current server stats',
136- 'color' => 'danger',
137- 'fields' => [
138- [
139- 'title' => 'CPU usage',
140- 'value' => '90%',
141- 'short' => true // whether the field is short enough to sit side-by-side other fields, defaults to false
142- ],
143- [
144- 'title' => 'RAM usage',
145- 'value' => '2.5GB of 4GB',
146- 'short' => true
147- ]
148- ]
134+ 'fallback' => 'Current server stats',
135+ 'text' => 'Current server stats',
136+ 'color' => 'danger',
137+ 'fields' => [
138+ [
139+ 'title' => 'CPU usage',
140+ 'value' => '90%',
141+ 'short' => true // whether the field is short enough to sit side-by-side other fields, defaults to false
142+ ],
143+ [
144+ 'title' => 'RAM usage',
145+ 'value' => '2.5GB of 4GB',
146+ 'short' => true
147+ ]
148+ ]
149149])->send('New alert from the monitoring system'); // no message, but can be provided if you'd like
150150```
151151
152152#### Send an attachment with an author ([ preview] ( https://goo.gl/CKd1zJ ) )
153153
154154``` php
155155$client->to('@regan')->attach([
156- 'fallback' => 'Keep up the great work! I really love how the app works.',
157- 'text' => 'Keep up the great work! I really love how the app works.',
158- 'author_name' => 'Jane Appleseed',
159- 'author_link' => 'https://yourapp.com/feedback/5874601',
160- 'author_icon' => 'https://static.pexels.com/photos/61120/pexels-photo-61120-large.jpeg'
156+ 'fallback' => 'Keep up the great work! I really love how the app works.',
157+ 'text' => 'Keep up the great work! I really love how the app works.',
158+ 'author_name' => 'Jane Appleseed',
159+ 'author_link' => 'https://yourapp.com/feedback/5874601',
160+ 'author_icon' => 'https://static.pexels.com/photos/61120/pexels-photo-61120-large.jpeg'
161161])->send('New user feedback');
162162```
163163
164164#### Using blocks ([ Block Kit] ( https://api.slack.com/block-kit ) )
165165
166166``` php
167- $client->to('@regan')->withBlock([
168- 'type' => 'section',
169- 'text' => 'Do you love the app?'
170- ])->withBlock([
171- 'type' => 'actions',
172- 'elements' => [[
173- 'type' => 'button',
174- 'text' => 'Love it',
175- 'style' => 'primary',
176- 'action_id' => 'love',
177- ], [
178- 'type' => 'button',
179- 'text' => 'Hate it',
180- 'style' => 'danger',
181- 'action_id' => 'hate',
182- ],
183- ])->send('Notification fallback message');
167+ $client->to('@regan')
168+ ->withBlock([
169+ 'type' => 'section',
170+ 'text' => 'Do you love the app?'
171+ ])
172+ ->withBlock([
173+ 'type' => 'actions',
174+ 'elements' => [[
175+ 'type' => 'button',
176+ 'text' => 'Love it',
177+ 'style' => 'primary',
178+ 'action_id' => 'love',
179+ ], [
180+ 'type' => 'button',
181+ 'text' => 'Hate it',
182+ 'style' => 'danger',
183+ 'action_id' => 'hate',
184+ ],]
185+ ])
186+ ->send('Notification fallback message');
184187```
185188
186189## Advanced usage
@@ -201,11 +204,11 @@ $client->to('#general')->enableMarkdown()->send('Enable _markdown_ just for this
201204
202205``` php
203206$client->to('#operations')->attach([
204- 'fallback' => 'It is all broken, man',
205- 'text' => 'It is _all_ broken, man',
206- 'pretext' => 'From user: *JimBob*',
207- 'color' => 'danger',
208- 'mrkdwn_in' => ['pretext', 'text']
207+ 'fallback' => 'It is all broken, man',
208+ 'text' => 'It is _all_ broken, man',
209+ 'pretext' => 'From user: *JimBob*',
210+ 'color' => 'danger',
211+ 'mrkdwn_in' => ['pretext', 'text']
209212])->send('New alert from the monitoring system');
210213```
211214
@@ -219,10 +222,12 @@ $client->to('@regan')->send('I am sending this implicitly');
219222
220223// Explicitly
221224$message = $client->createMessage();
225+ $message
226+ ->to('@regan')
227+ ->setText('I am sending this explicitly')
228+ ;
222229
223- $message->to('@regan')->setText('I am sending this explicitly');
224-
225- $message->send();
230+ $client->send($message);
226231```
227232
228233### Attachments
@@ -231,34 +236,35 @@ When using attachments, the easiest way is to provide an array of data as shown
231236
232237``` php
233238$attachment = new Attachment([
234- 'fallback' => 'Some fallback text',
235- 'text' => 'The attachment text'
239+ 'fallback' => 'Some fallback text',
240+ 'text' => 'The attachment text'
236241]);
237242
238243// Explicitly create a message from the client
239244// rather than using the magic passthrough methods
240245$message = $client->createMessage();
241246
242247$message->attach($attachment);
243-
244248// Explicitly set the message text rather than
245249// implicitly through the send method
246- $message->setText('Hello world')->send();
250+ $message->setText('Hello world');
251+
252+ $client->send($message);
247253```
248254
249255Each attachment field is also an object, an AttachmentField. They can be used as well instead of their data in array form:
250256
251257``` php
252258$attachment = new Attachment([
253- 'fallback' => 'Some fallback text',
254- 'text' => 'The attachment text',
255- 'fields' => [
256- new AttachmentField([
257- 'title' => 'A title',
258- 'value' => 'A value',
259- 'short' => true
260- ])
261- ]
259+ 'fallback' => 'Some fallback text',
260+ 'text' => 'The attachment text',
261+ 'fields' => [
262+ new AttachmentField([
263+ 'title' => 'A title',
264+ 'value' => 'A value',
265+ 'short' => true
266+ ])
267+ ]
262268]);
263269```
264270
0 commit comments