PHP code example of wgmv / laravel-slack-api

1. Go to this page and download the library: Download wgmv/laravel-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/ */

    

wgmv / laravel-slack-api example snippets


[
    'providers' => [
        Wgmv\SlackApi\SlackApiServiceProvider::class,
    ]
]

 

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


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


class_alias('Wgmv\SlackApi\Facades\SlackApi', 'SlackApi');
//... and others

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

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

etc

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

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

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

//Invite a new member to your team
SlackUserAdmin::invite("[email protected]", [
    'first_name' => 'John', 
    'last_name' => 'Doe'
]);

// or just use the helper

//Autoload the api
slack()->post('chat.postMessage', [...]);

//Autoload a Slack Method
slack('Chat')->message([...]);
slack('Team')->info();

/** @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]');