PHP code example of spatie / interactive-slack-notification-channel

1. Go to this page and download the library: Download spatie/interactive-slack-notification-channel 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/ */

    

spatie / interactive-slack-notification-channel example snippets


public function routeNotificationForInteractiveSlack()
{
    return [
        'token' => 'xoxp-slack-token',
        'channel' => '#general' // this is optional
    ];
}

use Spatie\InteractiveSlackNotificationChannel\Messages\SlackMessage

public function toInteractiveSlack($notifiable)
{
    return (new SlackMessage)->content('A new order has been placed');
}

public function interactiveSlackResponse(array $response)
{    
    $this->order->update(['slack_thread_ts' => $response['ts']]);
}

use Spatie\InteractiveSlackNotificationChannel\Messages\SlackMessage;
use Spatie\InteractiveSlackNotificationChannel\Messages\SlackAttachment;

public function toInteractiveSlack($notifiable)
{
    $order = $this->order;

    return (new SlackMessage)
        ->success()
        ->content('Order paid')
        ->threadTimestamp($order->slack_thread_ts)
        ->attachment(function(SlackAttachment $attachment) use ($order) {
           $attachment
                ->title("Order $order->reference has been paid for.")
                ->content('Should now be processed.')
                ->action('View Order', route('orders', $order->reference));
       });
}