laravel-slack-api, Slack.com Web API的Laravel e 流明封装

分享于 

9分钟阅读

GitHub

  繁體 雙語
Laravel e Lumen Wrapper for Slack.com Web API: https://api.slack.com
  • 源代码名称:laravel-slack-api
  • 源代码网址:http://www.github.com/vluzrmos/laravel-slack-api
  • laravel-slack-api源代码文档
  • laravel-slack-api源代码下载
  • Git URL:
    git://www.github.com/vluzrmos/laravel-slack-api.git
    Git Clone代码到本地:
    git clone http://www.github.com/vluzrmos/laravel-slack-api
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/vluzrmos/laravel-slack-api
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    

    Laravel 5-e 流明- 松弛 API

    Join the chat at https://gitter.im/vluzrmos/laravel-slack-api

    这个包提供了一种使用松弛API的简单方法。

    Latest Stable VersionTotal DownloadsLatest Unstable VersionLicense

    Instalation

    composer require vluzrmos/slack-api

    Laravel 5上的 Instalation

    添加到 config/app.php:

    <?php['providers'=> [VluzrmosSlackApiSlackApiServiceProvider::class, ]]?>

    :: 类表示法是可选的。

    如果你需要的话,把外观添加到你的别名中

    <?php['aliases'=> ['SlackApi'=>VluzrmosSlackApiFacadesSlackApi::class,'SlackChannel'=>VluzrmosSlackApiFacadesSlackChannel::class,'SlackChat'=>VluzrmosSlackApiFacadesSlackChat::class,'SlackGroup'=>VluzrmosSlackApiFacadesSlackGroup::class,'SlackFile'=>VluzrmosSlackApiFacadesSlackFile::class,'SlackSearch'=>VluzrmosSlackApiFacadesSlackSearch::class,'SlackInstantMessage'=>VluzrmosSlackApiFacadesSlackInstantMessage::class,'SlackUser'=>VluzrmosSlackApiFacadesSlackUser::class,'SlackStar'=>VluzrmosSlackApiFacadesSlackStar::class,'SlackUserAdmin'=>VluzrmosSlackApiFacadesSlackUserAdmin::class,'SlackRealTimeMessage'=>VluzrmosSlackApiFacadesSlackRealTimeMessage::class,'SlackTeam'=>VluzrmosSlackApiFacadesSlackTeam::class, ]]?>

    :: 类表示法是可选的。

    Lumen Instalation

    bootstrap/app.php 上添加该行:

    <?php// $app->register('AppProvidersAppServiceProvider'); (by default that comes commented)$app->register('VluzrmosSlackApiSlackApiServiceProvider');?>

    如果要使用外观,请在 bootstrap/app.php 上添加这一行

    <?phpclass_alias('VluzrmosSlackApiFacadesSlackApi', 'SlackApi');class_alias('VluzrmosSlackApiFacadesSlackChannel', 'SlackChannel');class_alias('VluzrmosSlackApiFacadesSlackChat', 'SlackChat');class_alias('VluzrmosSlackApiFacadesSlackGroup', 'SlackGroup');class_alias('VluzrmosSlackApiFacadesSlackUser', 'SlackUser');class_alias('VluzrmosSlackApiFacadesSlackTeam', 'SlackTeam');//... and others?>

    否则,只需使用单一快捷键:

    <?php/** @var VluzrmosSlackApiContractsSlackApi $slackapi */$slackapi= app('slack.api');/** @var VluzrmosSlackApiContractsSlackChat $slackchat */$slackchat= app('slack.chat');/** @var VluzrmosSlackApiContractsSlackChannel $slackchannel */$slackchannel= app('slack.channel');//or /** @var VluzrmosSlackApiContractsSlackApi $slackapi */$slackapi= slack();/** @var VluzrmosSlackApiContractsSlackChat $slackchat */$slackchat= slack('chat'); // or slack('slack.chat')//...//...?>

    配置

    config/services.php 中配置懒惰团队令牌

    <?php[//...,'slack'=> ['token'=>'your token here' ]]?>

    用法

    <?php//Lists all users on your teamSlackUser::lists(); //all()//Lists all channels on your teamSlackChannel::lists(); //all()//List all groupsSlackGroup::lists(); //all()//Invite a new member to your teamSlackUserAdmin::invite("example@example.com", ['first_name'=>'John', 'last_name'=>'Doe']);//Send a message to someone or channel or groupSlackChat::message('#general', 'Hello my friends!');//Upload a file/snippetSlackFile::upload(['filename'=>'sometext.txt', 'title'=>'text', 'content'=>'Nice contents','channels'=>'C0440SZU6'//can be channel, users, or groups ID]);// Search for files or messagesSlackSearch::all('my message');// Search for filesSlackSearch::files('my file');// Search for messagesSlackSearch::messages('my message');// or just use the helper//Autoload the apislack()->post('chat.postMessage', [...]);//Autoload a Slack Methodslack('Chat')->message([...]);slack('Team')->info();?>

    使用依赖注入

    <?phpnamespaceAppHttpControllers; useVluzrmosSlackApiContractsSlackUser;classYourControllerextendsController{/** @var SlackUser */protected$slackUser;publicfunction__construct(SlackUser as$slackUser){$this->slackUser=$slackUser;  }publicfunctioncontrollerMethod(){$usersList=$this->slackUser->lists(); }}?>

    所有可以注入的合同:

    通用 API

    VluzrmosSlackApiContractsSlackApi

    允许你使用以下http谓词对api执行一般请求: getpostputpatchdelete。 你可以在这里看到的所有允许的api方法: 松弛 Web API 方法

    也可以加载SlackMethod协定:

    <?php/** @var SlackChannel $channel **/$channel=$slack->load('Channel');$channel->lists();/** @var SlackChat $chat **/$chat=$slack->load('Chat');$chat->message('D98979F78', 'Hello my friend!');/** @var SlackUserAdmin $chat **/$admin= $slack('UserAdmin'); //Minimal syntax (invokable)$admin->invite('jhon.doe@example.com'); ?>

    通道 API

    VluzrmosSlackApiContractsSlackChannel

    允许你操作频道: invitearchiverenamejoinkicksetPurpose。"。

    聊天 API

    VluzrmosSlackApiContractsSlackChat

    允许你使用方法发送,更新和删除消息: deletemessageupdate

    文件 API

    VluzrmosSlackApiContractsSlackFile

    允许你发送,获取信息,删除或者仅列出文件: infolistsuploaddelete

    组 API

    VluzrmosSlackApiContractsSlackGroup

    SlackChannel相同的方法,但使用组并具有adicional方法: openclosecreateChild

    即时消息 API ( 直接消息)

    VluzrmosSlackApiContractsSlackInstantMessage

    允许你管理你的团队成员的直接消息。

    实时消息 API

    VluzrmosSlackApiContractsSlackRealTimeMessage

    允许你列出当前所有频道和用户的状态。

    全文搜索 API

    VluzrmosSlackApiContractsSlackSearch

    查找邮件或者文件。

    星 API

    VluzrmosSlackApiContractsSlackStar

    列出 starred itens。

    团队 API

    VluzrmosSlackApiContractsSlackTeam

    获取有关你的团队的信息。

    用户 API

    VluzrmosSlackApiContractsSlackUser

    获取团队中用户的信息或者只检查你的状态。

    用户管理 API

    VluzrmosSlackApiContractsSlackUserAdmin

    邀请新成员加入你的团队。

    许可证

    DBAD许可协议。


    COM  WEB  API  WRAP  换行  Laravel  
    相关文章