定制 eric-famiglietti/laravel-slack-events 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eric-famiglietti/laravel-slack-events

Composer 安装命令:

composer require eric-famiglietti/laravel-slack-events

包简介

Laravel package for integrating with the Slack Events API

README 文档

README

Packagist Travis StyleCI

Laravel package for integrating with the Slack Events API.

Introduction

This package makes it easy to set up a webhook in a Laravel application for receiving requests from Slack through the Slack Events API. The package handles token authentication and URL verification and leaves the specific handling of events up to you. Events can be handled through jobs or event listeners.

Before proceeding, it's recommended that you familiarize yourself with the Slack Events API and the available Event Types so you can properly set up Slack to communicate with your application.

Requirements

  • PHP 7.1 or above
  • Laravel 5.6

NOTE: These requirements are artificially high. The package could work with earlier versions of Laravel but has only been tested with Laravel 5.6.

Installation

Install the latest version using Composer:

$ composer require eric-famiglietti/laravel-slack-events

Publish the configuration file using:

$ php artisan vendor:publish --provider="LaravelSlackEvents\SlackEventsServiceProvider" --tag="config"

Usage

Setup

The package requires a SLACK_EVENTS_TOKEN environmental variable to be set. The Verification Token can be found by on your Slack application's dashboard (https://api.slack.com/apps/<app_id>), under the App Credentials section.

For the purpose of this guide, the webhook URL that we will use is https://app.tld/slack/events.

First, create the webhook route using the route macro:

Route::slackEventsWebhook('slack/events');

Next, add the route to the $except array of the VerifyCsrfToken middleware:

protected $except = [
    'slack/events',
];

Once you have created the webhook, configure Slack to send event requests to the webhook. This is done on the Event Subscriptions page (https://api.slack.com/apps/<app_id>/event-subscriptions) of your Slack application's dashboard.

If your application is publically accessible, you will begin to event requests to the webhook. Events can be handled through jobs or event listeners.

Jobs

Jobs can be executed when events are triggered. For example, to dispatch a job when a reaction_added is received, add the following to config/slack-events.php:

'jobs' => [
    'reaction_added' => \App\Jobs\SlackEvents\HandleReactionAdded::class,
],

Jobs will receive the event payload through their constructor:

namespace App\Jobs\SlackEvents;

class HandleReactionAdded
{
    public $payload;

    public function __construct(array $payload)
    {
        $this->payload = $payload;
    }
    
    public function handle()
    {
        // ...
    }
}

Events

Laravel event listeners can handle Slack event requests. For example, to listen to a reaction_added event, add an element to the $listen property of your EventServiceProvider:

protected $listen = [
    'slack-events::reaction_added' => [
        App\Listeners\SlackEvents\ReactionAddedListener::class,
    ],
];

The associated event listener would look like:

namespace App\Listeners\SlackEvents;

class ReactionAddedListener
{
    public function handle(array $payload)
    {
        // ...
    }
}

Testing

Run the included tests using:

$ vendor/bin/phpunit

Credits

Special thanks to the ohdearapp/laravel-ohdear-webhooks package, which this package was heavily based on.

License

This package is provided under the MIT License (MIT). See the license file for more information.

统计信息

  • 总下载量: 310
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固