PHP code example of vluzrmos / slack-api

1. Go to this page and download the library: Download vluzrmos/slack-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vluzrmos / slack-api example snippets


[
    '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,
]


// $app->register('App\Providers\AppServiceProvider'); (by default that comes commented)
$app->register('Vluzrmos\SlackApi\SlackApiServiceProvider');




class_alias('Vluzrmos\SlackApi\Facades\SlackApi', 'SlackApi');
class_alias('Vluzrmos\SlackApi\Facades\SlackChannel', 'SlackChannel');
class_alias('Vluzrmos\SlackApi\Facades\SlackChat', 'SlackChat');
class_alias('Vluzrmos\SlackApi\Facades\SlackGroup', 'SlackGroup');
class_alias('Vluzrmos\SlackApi\Facades\SlackUser', 'SlackUser');
class_alias('Vluzrmos\SlackApi\Facades\SlackTeam', 'SlackTeam');
//... and others




/** @var \Vluzrmos\SlackApi\Contracts\SlackApi $slackapi */
$slackapi     = app('slack.api');

/** @var \Vluzrmos\SlackApi\Contracts\SlackChat $slackchat */
$slackchat    = app('slack.chat');

/** @var \Vluzrmos\SlackApi\Contracts\SlackChannel $slackchannel */
$slackchannel = app('slack.channel');

//or

/** @var \Vluzrmos\SlackApi\Contracts\SlackApi $slackapi */
$slackapi  = slack();

/** @var \Vluzrmos\SlackApi\Contracts\SlackChat $slackchat */
$slackchat = slack('chat'); // or slack('slack.chat')

//...
//...




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




//Lists all users on your team
SlackUser::lists(); //all()

//Lists all channels on your team
SlackChannel::lists(); //all()

//List all groups
SlackGroup::lists(); //all()

//Invite a new member to your team
SlackUserAdmin::invite("[email protected]", [
    'first_name' => '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();




namespace App\Http\Controllers;

use Vluzrmos\SlackApi\Contracts\SlackUser;

class YourController extends Controller{
    /** @var  SlackUser */
    protected $slackUser;

    public function __construct(SlackUser as $slackUser){
        $this->slackUser = $slackUser;
    }

    public function controllerMethod(){
        $usersList = $this->slackUser->lists();
    }
}




/** @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('[email protected]');

bash
php artisan vendor:publish --provider="Vluzrmos\SlackApi\SlackApiServiceProvider"