1. Go to this page and download the library: Download mcrumm/phlack library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mcrumm / phlack example snippets
$phlack = new Crummy\Phlack\Phlack('https://my.webhook.url');
$response = $phlack->send('Hello, from Phlack!');
if (200 === $response['status']) {
echo 'Success!';
}
$client = new Crummy\Phlack\Bridge\Guzzle\PhlackClient('https://my.webhook.url');
$phlack = new Crummy\Phlack\Phlack($client);
// ...
$messageBuilder = $phlack->getMessageBuilder();
$messageBuilder
->setText('I was created in the MessageBuilder')
->setChannel('testing')
->setIconEmoji('ghost');
$message = $messageBuilder->create();
$messageBuilder = $phlack->getMessageBuilder(); // Get the MessageBuilder
$messageBuilder
->setText('This message contains multiple attachments.') // Message text.
->createAttachment() // Returns the AttachmentBuilder.
->setTitle($title)
->setTitleLink($link)
->setPretext($pretext)
->setText($body)
->setColor($color)
->setFallback($title . ' ' . $pretext)
->end() // Creates the first attachment and returns the MessageBuilder
->setUsername($username) // Sets username on the Message object.
->createAttachment() // Returns the AttachmentBuilder.
->setTitle('Attachment #2')
->setFallback('Attachment #2 for example purposes')
->setText('Add multiple attachments to a Phlack Message via method chaining.')
->end() // Creates the second attachment and returns the MessageBuilder.
;
$message = $messageBuilder->create();
// ...
// Get the AttachmentBuilder
$attachmentBuilder = $phlack->getAttachmentBuilder();
// Create the Attachment
$attachment =
$attachmentBuilder
->setTitle('My Attachment Title')
->setTitleLink('http://www.example.com')
->setPretext('Some optional pretext')
->setText('This is the body of my attachment')
->setColor($color)
->addField('Field 1', 'Some Value', true)
->setFallback($title . ' ' . $pretext)
->create()
;
// Create a Message to contain the Attachment
$message = new \Crummy\Phlack\Message\Message('This message contains an attachment.');
// Add the Attachment to the Message
$message->addAttachment($attachment);
//...
use Crummy\Phlack\Message\Message;
$message = new Message('Hello, from phlack!');
echo 'The message payload: ' . PHP_EOL:
echo $message; // Output: {"text": "Hello, from phlack!"}
//...
use Crummy\Phlack\Message\Message;
$message = new Message('Hello, from phlack!', '#random');
echo 'The message payload: ' . PHP_EOL:
echo $message; // Output: {"text": "Hello, from phlack!", "channel": "#random"}
// ...
$response = $phlack->send($message);
if (200 != $response['status']) {
die('FAIL! - ' . $response['text']);
}
echo 'The message was sent: ' . $message;