PHP code example of clawrock / slack-api

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

    

clawrock / slack-api example snippets




use ClawRock\Slack\SlackFactory;

//Create new dispatcher
$dispatcher = SlackFactory::dispatcher();


//Add commands to respond to your request
$dispatcher->addCommand(SlackFactory::slashCommand('your-command-token')
          ->run(function ($req, $res){
                $res->addText('Hello world!');
          }))->dispatch(SlackFactory::getRequest())
      ->create()
      ->toRequest()
      ->serve();

use ClawRock\Slack\Enums\Permissions;

$dispatcher->addGuard(SlackFactory::guard()
        ->defaultBehavior(Permissions::DenyAll())
        ->allowUserIds(['U01'])
        ->allowTeamIds(['T01']))
    ->addCommand(//commands)
    ->dispatch(SlackFactory::getRequest())
    ->create()
    ->toRequest()
    ->serve();

use ClawRock\Slack\SlackFactory;

SlackFactory::getMessageService('')->sendText("Hello world!");