PHP Class Slack\ApiClient

Show file Open project: coderstephen/slack-client Class Usage Examples

Protected Properties

Property Type Description
$httpClient A Guzzle HTTP client.
$loop An event loop instance.
$token The Slack API token string.

Public Methods

Method Description
__construct ( React\EventLoop\LoopInterface $loop, GuzzleHttp\ClientInterface $httpClient = null ) Creates a new API client instance.
apiCall ( string $method, array $args = [] ) : React\Promise\PromiseInterface Sends an API request.
getAuthedUser ( ) : React\Promise\PromiseInterface Gets the currently authenticated user.
getChannelById ( string $id ) : React\Promise\PromiseInterface Gets a channel by its ID.
getChannelByName ( string $name ) : React\Promise\PromiseInterface Gets a channel by its name.
getChannelGroupOrDMByID ( string $id ) : React\Promise\PromiseInterface Gets a channel, group, or DM channel by ID.
getChannels ( ) : React\Promise\PromiseInterface Gets all channels in the team.
getDMById ( string $id ) : React\Promise\PromiseInterface Gets a direct message channel by its ID.
getDMByUser ( User $user ) : React\Promise\PromiseInterface Gets a direct message channel for a given user.
getDMByUserId ( string $id ) : React\Promise\PromiseInterface Gets a direct message channel by user's ID.
getDMs ( ) : React\Promise\PromiseInterface Gets all DMs the authenticated user has.
getGroupById ( string $id ) : React\Promise\PromiseInterface Gets a group by its ID.
getGroupByName ( string $name ) : React\Promise\PromiseInterface Gets a group by its name.
getGroups ( ) : React\Promise\PromiseInterface Gets all groups the authenticated user is a member of.
getMessageBuilder ( ) : Slack\Message\MessageBuilder Gets a message builder for creating a new message object.
getTeam ( ) : React\Promise\PromiseInterface Gets information about the current Slack team logged in to.
getUserById ( string $id ) : React\Promise\PromiseInterface Gets a user by its ID.
getUserByName ( $username ) : React\Promise\PromiseInterface Gets a user by username.
getUsers ( ) : React\Promise\PromiseInterface Gets all users in the Slack team.
postMessage ( Message $message ) : React\Promise\PromiseInterface Posts a message.
send ( string $text, slack\ChannelInterface $channel ) : React\Promise\PromiseInterface Sends a regular text message to a given channel.
setToken ( string $token ) Sets the Slack API token to be used during method calls.

Method Details

__construct() public method

Creates a new API client instance.
public __construct ( React\EventLoop\LoopInterface $loop, GuzzleHttp\ClientInterface $httpClient = null )
$loop React\EventLoop\LoopInterface
$httpClient GuzzleHttp\ClientInterface A Guzzle client instance to send requests with.

apiCall() public method

Sends an API request.
public apiCall ( string $method, array $args = [] ) : React\Promise\PromiseInterface
$method string The API method to call.
$args array An associative array of arguments to pass to the method call.
return React\Promise\PromiseInterface A promise for an API response.

getAuthedUser() public method

Gets the currently authenticated user.
public getAuthedUser ( ) : React\Promise\PromiseInterface
return React\Promise\PromiseInterface A promise for the currently authenticated user.

getChannelById() public method

Gets a channel by its ID.
public getChannelById ( string $id ) : React\Promise\PromiseInterface
$id string A channel ID.
return React\Promise\PromiseInterface A promise for a channel object.

getChannelByName() public method

Gets a channel by its name.
public getChannelByName ( string $name ) : React\Promise\PromiseInterface
$name string The name of the channel.
return React\Promise\PromiseInterface

getChannelGroupOrDMByID() public method

Gets a channel, group, or DM channel by ID.
public getChannelGroupOrDMByID ( string $id ) : React\Promise\PromiseInterface
$id string The channel ID.
return React\Promise\PromiseInterface A promise for a channel interface.

getChannels() public method

Gets all channels in the team.
public getChannels ( ) : React\Promise\PromiseInterface
return React\Promise\PromiseInterface

getDMById() public method

Gets a direct message channel by its ID.
public getDMById ( string $id ) : React\Promise\PromiseInterface
$id string A DM channel ID.
return React\Promise\PromiseInterface A promise for a DM object.

getDMByUser() public method

Gets a direct message channel for a given user.
public getDMByUser ( User $user ) : React\Promise\PromiseInterface
$user User The user to get a DM for.
return React\Promise\PromiseInterface A promise for a DM object.

getDMByUserId() public method

Gets a direct message channel by user's ID.
public getDMByUserId ( string $id ) : React\Promise\PromiseInterface
$id string A user ID.
return React\Promise\PromiseInterface A promise for a DM object.

getDMs() public method

Gets all DMs the authenticated user has.
public getDMs ( ) : React\Promise\PromiseInterface
return React\Promise\PromiseInterface

getGroupById() public method

Gets a group by its ID.
public getGroupById ( string $id ) : React\Promise\PromiseInterface
$id string A group ID.
return React\Promise\PromiseInterface A promise for a group object.

getGroupByName() public method

Gets a group by its name.
public getGroupByName ( string $name ) : React\Promise\PromiseInterface
$name string The name of the group.
return React\Promise\PromiseInterface

getGroups() public method

Gets all groups the authenticated user is a member of.
public getGroups ( ) : React\Promise\PromiseInterface
return React\Promise\PromiseInterface

getMessageBuilder() public method

Gets a message builder for creating a new message object.
public getMessageBuilder ( ) : Slack\Message\MessageBuilder
return Slack\Message\MessageBuilder

getTeam() public method

Gets information about the current Slack team logged in to.
public getTeam ( ) : React\Promise\PromiseInterface
return React\Promise\PromiseInterface A promise for the current Slack team.

getUserById() public method

Gets a user by its ID.
public getUserById ( string $id ) : React\Promise\PromiseInterface
$id string A user ID.
return React\Promise\PromiseInterface A promise for a user object.

getUserByName() public method

If the user could not be found, the returned promise is rejected with a UserNotFoundException exception.
public getUserByName ( $username ) : React\Promise\PromiseInterface
return React\Promise\PromiseInterface A promise for a user object.

getUsers() public method

Gets all users in the Slack team.
public getUsers ( ) : React\Promise\PromiseInterface
return React\Promise\PromiseInterface A promise for an array of users.

postMessage() public method

Posts a message.
public postMessage ( Message $message ) : React\Promise\PromiseInterface
$message Slack\Message\Message The message to post.
return React\Promise\PromiseInterface

send() public method

Sends a regular text message to a given channel.
public send ( string $text, slack\ChannelInterface $channel ) : React\Promise\PromiseInterface
$text string The message text.
$channel slack\ChannelInterface The channel to send the message to.
return React\Promise\PromiseInterface

setToken() public method

Sets the Slack API token to be used during method calls.
public setToken ( string $token )
$token string The API token string.

Property Details

$httpClient protected property

A Guzzle HTTP client.
protected $httpClient

$loop protected property

An event loop instance.
protected $loop

$token protected property

The Slack API token string.
protected $token