PHP code example of hidalgo-rides / slack-notifier

1. Go to this page and download the library: Download hidalgo-rides/slack-notifier 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/ */

    

hidalgo-rides / slack-notifier example snippets


// your Webhook URL
$webhookAPI = 'https://hooks.slack.com/services/Txxxxxx/Byyyyyyy/Zzzzzzzzz';

// new SlackNotifier instance
$slackNotifier = new \TimKippDev\SlackNotifier\SlackNotifier($webhookAPI);

$slackNotifier->sendMessage('First message using Slack Notifier!');

\TimKippDev\SlackNotifier\SlackNotifier::sendMessageToChannel($webhookAPI, 'First message using Slack Notifier!');

$slackAttachment = new \TimKippDev\SlackNotifier\SlackAttachment();
$slackAttachment
    ->setAuthorName('Author name goes here')
    ->setAuthorLinkUrl('https://example.com/author')
    ->setAuthorIconUrl('https://img.icons8.com/ultraviolet/48/000000/soy.png')
    ->setColor('#222222')
    ->setFallbackText('Fallback goes here')
    ->setFooterIconUrl('https://img.icons8.com/color/48/000000/soy.png')
    ->setFooterText('Footer text goes here')
    ->setImageUrl('https://img.icons8.com/color/400/000000/soy.png')
    ->setPretext('Pretext goes here')
    ->setText('Attached using Slack Notifier!')
    ->setThumbnailUrl('https://img.icons8.com/ultraviolet/96/000000/soy.png')
    ->setTitle('Title goes here')
    ->setTitleLinkUrl('https://example.com/title');

// with instance method
$slackNotifier->sendMessage('First message with attachments using Slack Notifier!', [
    $slackAttachment
]);

// with static method
\TimKippDev\SlackNotifier\SlackNotifier::sendMessageToChannel($webhookAPI, 'First message using Slack Notifier!', [
    $slackAttachment
]);

$slackActionConfirmation = new \TimKippDev\SlackNotifier\SlackActionConfirmation();
$slackActionConfirmation->setDismissButtonText('Dismiss')
    ->setOkButtonText('Confirm')
    ->setText('Confirmation Text')
    ->setTitle('Confirmation Title');

$slackAction = new \TimKippDev\SlackNotifier\SlackAction();
$slackAction->setStyle('primary')
    ->setType('button')
    ->setText('Click Me with Confirmation')
    ->setUrl('https://example.com/action')
    ->setName('action-name')
    ->setConfirmation($slackActionConfirmation);

$slackAttachment = new \TimKippDev\SlackNotifier\SlackAttachment();
$slackAttachment
    ->setText('Attached using Slack Notifier!')
    ->setActions([$slackAction]);

// with instance method
$slackNotifier->sendMessage('First message attachment containing actions using Slack Notifier!', [
    $slackAttachment
]);

// with static method
\TimKippDev\SlackNotifier\SlackNotifier::sendMessageToChannel($webhookAPI, 'First message using Slack Notifier!', [
    $slackAttachment
]);

$slackField = new \TimKippDev\SlackNotifier\SlackField();
$slackField->setTitle('Field Title')
    ->setValue('Field Value');

$slackAttachment = new \TimKippDev\SlackNotifier\SlackAttachment();
$slackAttachment
    ->setText('Attached using Slack Notifier!')
    ->setFields([$slackField]);

// with instance method
$slackNotifier->sendMessage('First message attachment containing fields using Slack Notifier!', [
    $slackAttachment
]);

// with static method
\TimKippDev\SlackNotifier\SlackNotifier::sendMessageToChannel($webhookAPI, 'First message using Slack Notifier!', [
    $slackAttachment
]);