Giter Club home page Giter Club logo

slack-api's Introduction

Slack-API

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 [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.