Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vluzrmos/laravel-slack-api
Laravel e Lumen Wrapper for Slack.com Web API: https://api.slack.com
https://github.com/vluzrmos/laravel-slack-api
Last synced: about 13 hours ago
JSON representation
Laravel e Lumen Wrapper for Slack.com Web API: https://api.slack.com
- Host: GitHub
- URL: https://github.com/vluzrmos/laravel-slack-api
- Owner: vluzrmos
- Created: 2015-02-23T04:52:06.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-11-17T14:08:43.000Z (27 days ago)
- Last Synced: 2024-12-04T09:09:14.290Z (10 days ago)
- Language: PHP
- Homepage:
- Size: 238 KB
- Stars: 99
- Watchers: 5
- Forks: 60
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-brasil - Slack API
README
## Laravel e Lumen - Slack API
[![Join the chat at https://gitter.im/vluzrmos/laravel-slack-api](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/vluzrmos/laravel-slack-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This package provides a simple way to use [Slack API](https://api.slack.com/web#methods).
[![Latest Stable Version](https://poser.pugx.org/vluzrmos/slack-api/v/stable.svg)](https://packagist.org/packages/vluzrmos/slack-api) [![Total Downloads](https://poser.pugx.org/vluzrmos/slack-api/downloads.svg)](https://packagist.org/packages/vluzrmos/slack-api) [![Latest Unstable Version](https://poser.pugx.org/vluzrmos/slack-api/v/unstable.svg)](https://packagist.org/packages/vluzrmos/slack-api) [![License](https://poser.pugx.org/vluzrmos/slack-api/license.svg)](https://packagist.org/packages/vluzrmos/slack-api)
## Instalation
`composer require vluzrmos/slack-api`
## Instalation on Laravel
Add to `config/app.php`:This package uses auto-discovery laravel's feature, the service provider and all the facades will be automatic discovered.
Service Provider: `\Vluzrmos\SlackApi\SlackApiServiceProvider::class`
Facades:
```php
[
'SlackApi' => Vluzrmos\SlackApi\Facades\SlackApi::class,
'SlackChannel' => Vluzrmos\SlackApi\Facades\SlackChannel::class,
'SlackChat' => Vluzrmos\SlackApi\Facades\SlackChat::class,
'SlackGroup' => Vluzrmos\SlackApi\Facades\SlackGroup::class,
'SlackFile' => Vluzrmos\SlackApi\Facades\SlackFile::class,
'SlackSearch' => Vluzrmos\SlackApi\Facades\SlackSearch::class,
'SlackInstantMessage' => Vluzrmos\SlackApi\Facades\SlackInstantMessage::class,
'SlackUser' => Vluzrmos\SlackApi\Facades\SlackUser::class,
'SlackStar' => Vluzrmos\SlackApi\Facades\SlackStar::class,
'SlackUserAdmin' => Vluzrmos\SlackApi\Facades\SlackUserAdmin::class,
'SlackRealTimeMessage' => Vluzrmos\SlackApi\Facades\SlackRealTimeMessage::class,
'SlackTeam' => Vluzrmos\SlackApi\Facades\SlackTeam::class,
'SlackOAuth' => Vluzrmos\SlackApi\Facades\SlackOAuth::class,
'SlackOAuthV2' => Vluzrmos\SlackApi\Facades\SlackOAuthV2::class,
]
```## Instalation on Lumen
Add that line on `bootstrap/app.php`:
```php
register('App\Providers\AppServiceProvider'); (by default that comes commented)
$app->register('Vluzrmos\SlackApi\SlackApiServiceProvider');?>
```If you want to use facades, add this lines on
bootstrap/app.php
```php
```
Otherwise, just use the singleton shortcuts:
```php
```
## Slack OAuth Token
To get your slack token, you must create an app on [Slack Apps](https://api.slack.com/apps) and then give the permissions that you need at your app page on side menu "Features" -> "OAuth & Permissions", and then go to "Scopes" section, the token can be a `Bot Token` or `User Token` as you need.
Then re/install the app to your workspace.
> Note: If you edit any permission you must reinstall the app to your workspace.
## Configuration
Configure your slack team token in
config/services.php
```php
[
'token' => 'your token here'
]
]?>
```By default all api methods will return objects, to change it to associative array first publish slack-api config, and then set `response_to_assoc_array` to true
```bash
php artisan vendor:publish --provider="Vluzrmos\SlackApi\SlackApiServiceProvider"
```## Usage
```php
'John',
'last_name' => 'Doe'
]);//Send a message to someone or channel or group
SlackChat::message('#general', 'Hello my friends!');//Upload a file/snippet
SlackFile::upload([
'filename' => 'sometext.txt',
'title' => 'text',
'content' => 'Nice contents',
'channels' => 'C0440SZU6' //can be channel, users, or groups ID
]);// Search for files or messages
SlackSearch::all('my message');// Search for files
SlackSearch::files('my file');// Search for messages
SlackSearch::messages('my message');// or just use the helper
//Autoload the api
slack()->post('chat.postMessage', [...]);//Autoload a Slack Method
slack('Chat')->message([...]);
slack('Team')->info();?>
```## Using Dependency Injection
```php
slackUser = $slackUser;
}public function controllerMethod(){
$usersList = $this->slackUser->lists();
}
}?>
```## All Injectable Contracts:
### Generic API
`Vluzrmos\SlackApi\Contracts\SlackApi`Allows you to do generic requests to the api with the following http verbs:
`get`, `post`, `put`, `patch`, `delete` ... all allowed api methods you could see here: [Slack Web API Methods](https://api.slack.com/methods).And is also possible load a SlackMethod contract:
```php
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('[email protected]');?>
```### Channels API
`Vluzrmos\SlackApi\Contracts\SlackChannel`Allows you to operate channels:
`invite`, `archive`, `rename`, `join`, `kick`, `setPurpose` ...### Chat API
`Vluzrmos\SlackApi\Contracts\SlackChat`Allows you to send, update and delete messages with methods:
`delete`, `message`, `update`.### Files API
`Vluzrmos\SlackApi\Contracts\SlackFile`Allows you to send, get info, delete, or just list files:
`info`, `lists`, `upload`, `delete`.### Groups API
`Vluzrmos\SlackApi\Contracts\SlackGroup`Same methods of the SlackChannel, but that operates with groups and have adicional methods:
`open`, `close`, `createChild`### Instant Messages API (Direct Messages)
`Vluzrmos\SlackApi\Contracts\SlackInstantMessage`Allows you to manage direct messages to your team members.
### Real Time Messages API
`Vluzrmos\SlackApi\Contracts\SlackRealTimeMessage`Allows you list all channels and user presence at the moment.
### Search API
`Vluzrmos\SlackApi\Contracts\SlackSearch`Find messages or files.
### Stars API
`Vluzrmos\SlackApi\Contracts\SlackStar`List all of starred itens.
### Team API
`Vluzrmos\SlackApi\Contracts\SlackTeam`Get information about your team.
### Users API
`Vluzrmos\SlackApi\Contracts\SlackUser`Get information about an user on your team or just check your presence ou status.
### Users Admin API
`Vluzrmos\SlackApi\Contracts\SlackUserAdmin`Invite new members to your team.
### OAuth API
`Vluzrmos\SlackApi\Contracts\SlackOAuth`Methods in oauth slack api namespace.
### OAuthV2 API
`Vluzrmos\SlackApi\Contracts\SlackOAuthV2`Methods in oauth v2 slack api namespace.
## License
[DBAD License](https://dbad-license.org).