PHP code example of slack-php / slack-socket-mode

1. Go to this page and download the library: Download slack-php/slack-socket-mode 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/ */

    

slack-php / slack-socket-mode example snippets




use Psr\Log\LogLevel;
use SlackPhp\Framework\{App, Context, StderrLogger};
use SlackPhp\SocketMode\SocketServer;

App::new()
    ->command('cool', function (Context $ctx) {
        $ctx->ack(':thumbsup: That is so cool!');
    })
    ->withLogger(new StderrLogger(LogLevel::DEBUG))
    ->run(new SocketServer());



use Psr\Log\LogLevel;
use SlackPhp\Framework\{App, Context, StderrLogger};
use SlackPhp\Framework\Http\HttpServer;
use SlackPhp\SocketMode\SocketServer;

$app = App::new()
    ->command('cool', function (Context $ctx) {
        $ctx->ack(':thumbsup: That is so cool!');
    });

if (getenv('SOCKET_MODE')) {
    $server = SocketServer::new()->withLogger(new StderrLogger(LogLevel::DEBUG));
} else {
    $server = HttpServer::new()->withLogger(new StderrLogger(LogLevel::NOTICE));
}

$server->withApp($app)->start();