2017 © Pedro Peláez
 

library slack

Slack integration with PHP

image

timfeid/slack

Slack integration with PHP

  • Tuesday, May 16, 2017
  • by timfeid1
  • Repository
  • 1 Watchers
  • 0 Stars
  • 87 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

Slack via PHP

This package will utilize Slack's incoming webhooks., (*1)

Requirements

  • PHP 7+
  • PHP mbstring extension

Basic Usage

Create a client

// Quick istantiation
$client = new TimFeid\Slack\Client('https://hooks.slack.com...');

// Instantiate with default params
$pamas = [
    'username' => 'Tim Feid',
    'channel' => '#general',
    'unfurl_media' => true,
];

$client = new TimFeid\Slack\Client('https://hooks.slack.com...', $params);

Customizing a message

// Explicitly create a default message
$message = $client->createMessage();

// Set parameters on the message
$message->text = 'This is the text';
$message->icon = ':slack:';

// Or like this
$message['text'] = 'This is the text';

// Or using fluent methods
$message->write('This is the text')->icon(':slack:')->from('username')->to('channel');

// Create a default message from text
$message = $client->write('The text here');

// Create a message with all the parameters you wish to send
$params = [
    'username' => 'Tim Feid',
    'channel' => '#general',
    'text' => 'It\'s happening!',
    'icon' => ':poop:',
    'attachments' => [
        [
            'fallback' => 'This is fallback text',
            'text' => 'Some text on the attachment',
            'image_url' => 'http://placehold.it/320x240',
            'fields' => [
                'title' => 'Field title',
                'value' => 'Field value',
                'short' => false,
            ],
        ],
    ],
];
$message = $client->createMessage($params);

Sending a message

Send a basic, default message

$client->send('Hello world!');

Send a message to a different channel

$client->to('#general')->send('Hello world!');

Send a direct message with a different username

$client->to('@username')->from('Bob')->send('Hello!');

Fluent sending

// Implicitly
$message = $message->write('This is the text')->to('channel/@username')->from('username')->icon(':slack:');
$message->send();

// Explicitly
$message->to('channel/@username')->from('username')->icon(':slack:')->send('This is the text');

The Versions

16/05 2017

dev-master

9999999-dev

Slack integration with PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tim Feid

16/05 2017

1.0.1

1.0.1.0

Slack integration with PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tim Feid

05/05 2017

1.0.0

1.0.0.0

Slack integration with PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tim Feid