PHP code example of slack-php / slick

1. Go to this page and download the library: Download slack-php/slick 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 / slick example snippets




SlackPhp\Slick::app()
    ->route('command', '/cool', function (array $payload) {
        return "Thanks for running the `{$payload['command']}` command. You are cool! :thumbsup:";
    })
    ->run();



// Create the Slick app object.
SlackPhp\Slick::app()
    // Add a routable listener to the app to handle logic for a specific interaction.
    ->route(
        // The payload type (e.g., command, block_actions, view_submission, shortcut, and others).
        'command',
        // The payload ID. It's different based on the type. For commands, it is the command name.
        '/cool',
        // The listener that handles the specific interaction's logic.
        function (array $payload) {
            // Any app logic can be done here, including calling Slack's APIs.
            // Whatever you do, it should take less than 3 seconds, so you can "ack" before Slack's timeout.
        
            // Whatever is returned will be included as part of the "ack" (response) body. You can return a string, an
            // associative array, or JSON-serializable object. You should make sure that anything you include in the ack
            // is supported by the type of interaction you are responding to. Many interactions don't 



SlackPhp\Slick::app()
    ->route(...)
    ->route(...)
    ->route(...)
    ->on404(function (array $payload) {
        // Do something custom. This is essentially used as a catch-all listener.
        // If you don't use on404(), then your app throws an error.
    })
    ->onErr(function (Throwable $err) {
        // Do something custom.
        // If you don't use onErr(), then your app calls `error_log()` and acks with a 500-level response.
    })
    ->run();

composer