clawrock / slack-api
Slack Integration
Installs: 1 321
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.5
- marc-mabe/php-enum: ^2.3
- monolog/monolog: 1.*
Requires (Dev)
- phpdocumentor/phpdocumentor: 2.*
- phpunit/phpunit: 4.*
- sebastian/phpcpd: 2.*
This package is auto-updated.
Last update: 2024-10-29 05:04:57 UTC
README
Introduction
Slack-API lets you build simple response system for slack's slash command API.
Installation
For production make sure you have composer installed. Then run:
composer require clawrock/slack-api
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
Code Examples
Basic example with anonymous function.
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();
You can also add Guard to manage the user/team/channel permissions.
use ClawRock\Slack\Enums\Permissions; $dispatcher->addGuard(SlackFactory::guard() ->defaultBehavior(Permissions::DenyAll()) ->allowUserIds(['U01']) ->allowTeamIds(['T01'])) ->addCommand(//commands) ->dispatch(SlackFactory::getRequest()) ->create() ->toRequest() ->serve();
It's worth to notice that every callable object can be used in addCommand() method.
You can send messages via Incoming webhooks
use ClawRock\Slack\SlackFactory; SlackFactory::getMessageService('')->sendText("Hello world!");
Documentation
There are very well documented examples in examples/ directory. You should take a look on them.
Tests
Simply run
vendor/bin/phpunit
Requirements
Slack API requires server with SSL enabled. Please refer to the Slack's API reference to get more informations.
Contributing
If you wish to participate in the development, you may use grunt to generate the documentation files. To do so make sure you have node and npm installed.
$ node -v
v4.7.0
$ npm -v
2.15.11
Then run
$ npm install $ grunt init
And then to generate docs run
grunt build
This will also launch unit tests.
Credits
Slack-API was initiated with generator-composer, a Yeoman generator that builds a PHP Composer project.
This project uses the following as development dependencies:
License
Author: cr-team office@clawrock.com