PHP Class Maknz\Slack\Client

Show file Open project: maknz/slack Class Usage Examples

Protected Properties

Property Type Description
$allow_markdown boolean Whether message text should be formatted with Slack's Markdown-like language.
$channel string The default channel to send messages to.
$endpoint string The Slack incoming webhook endpoint.
$guzzle GuzzleHttp\Client The Guzzle HTTP client instance.
$icon string The default icon to send messages with.
$link_names boolean Whether to link names like @regan or leave them as plain text.
$markdown_in_attachments array The attachment fields which should be formatted with Slack's Markdown-like language.
$unfurl_links boolean Whether Slack should unfurl text-based URLs.
$unfurl_media boolean Whether Slack should unfurl media URLs.
$username string The default username to send messages as.

Public Methods

Method Description
__call ( string $name, array $arguments ) : Message Pass any unhandled methods through to a new Message instance.
__construct ( string $endpoint, array $attributes = [], Client $guzzle = null ) : void Instantiate a new Client.
createMessage ( ) : Message Create a new message with defaults.
getAllowMarkdown ( ) : boolean Get whether message text should be formatted with Slack's Markdown-like language.
getDefaultChannel ( ) : string Get the default channel messages will be created for.
getDefaultIcon ( ) : string Get the default icon messages will be created with.
getDefaultUsername ( ) : string Get the default username messages will be created for.
getEndpoint ( ) : string Get the Slack endpoint.
getLinkNames ( ) : boolean Get whether messages sent will have names (like @regan) will be converted into links.
getMarkdownInAttachments ( ) : array Get the attachment fields which should be formatted in Slack's Markdown-like language.
getUnfurlLinks ( ) : boolean Get whether text links should be unfurled.
getUnfurlMedia ( ) : boolean Get whether media links should be unfurled.
preparePayload ( Message $message ) : array Prepares the payload to be sent to the webhook.
sendMessage ( Message $message ) : void Send a message.
setAllowMarkdown ( boolean $value ) : void Set whether message text should be formatted with Slack's Markdown-like language.
setDefaultChannel ( string $channel ) : void Set the default channel messages will be created for.
setDefaultIcon ( string $icon ) : void Set the default icon messages will be created with.
setDefaultUsername ( string $username ) : void Set the default username messages will be created for.
setEndpoint ( string $endpoint ) : void Set the Slack endpoint.
setLinkNames ( boolean $value ) : void Set whether messages sent will have names (like @regan) will be converted into links.
setMarkdownInAttachments ( array $fields ) : void Set the attachment fields which should be formatted in Slack's Markdown-like language.
setUnfurlLinks ( boolean $value ) : void Set whether text links should be unfurled.
setUnfurlMedia ( boolean $value ) : void Set whether media links should be unfurled.

Protected Methods

Method Description
getAttachmentsAsArrays ( Message $message ) : array Get the attachments in array form.

Method Details

__call() public method

Pass any unhandled methods through to a new Message instance.
public __call ( string $name, array $arguments ) : Message
$name string The name of the method
$arguments array The method arguments
return Message

__construct() public method

Instantiate a new Client.
public __construct ( string $endpoint, array $attributes = [], Client $guzzle = null ) : void
$endpoint string
$attributes array
$guzzle GuzzleHttp\Client
return void

createMessage() public method

Create a new message with defaults.
public createMessage ( ) : Message
return Message

getAllowMarkdown() public method

Get whether message text should be formatted with Slack's Markdown-like language.
public getAllowMarkdown ( ) : boolean
return boolean

getAttachmentsAsArrays() protected method

Get the attachments in array form.
protected getAttachmentsAsArrays ( Message $message ) : array
$message Message
return array

getDefaultChannel() public method

Get the default channel messages will be created for.
public getDefaultChannel ( ) : string
return string

getDefaultIcon() public method

Get the default icon messages will be created with.
public getDefaultIcon ( ) : string
return string

getDefaultUsername() public method

Get the default username messages will be created for.
public getDefaultUsername ( ) : string
return string

getEndpoint() public method

Get the Slack endpoint.
public getEndpoint ( ) : string
return string

getLinkNames() public method

Get whether messages sent will have names (like @regan) will be converted into links.
public getLinkNames ( ) : boolean
return boolean

getMarkdownInAttachments() public method

Get the attachment fields which should be formatted in Slack's Markdown-like language.
public getMarkdownInAttachments ( ) : array
return array

getUnfurlMedia() public method

Get whether media links should be unfurled.
public getUnfurlMedia ( ) : boolean
return boolean

preparePayload() public method

Prepares the payload to be sent to the webhook.
public preparePayload ( Message $message ) : array
$message Message The message to send
return array

sendMessage() public method

Send a message.
public sendMessage ( Message $message ) : void
$message Message
return void

setAllowMarkdown() public method

Set whether message text should be formatted with Slack's Markdown-like language.
public setAllowMarkdown ( boolean $value ) : void
$value boolean
return void

setDefaultChannel() public method

Set the default channel messages will be created for.
public setDefaultChannel ( string $channel ) : void
$channel string
return void

setDefaultIcon() public method

Set the default icon messages will be created with.
public setDefaultIcon ( string $icon ) : void
$icon string
return void

setDefaultUsername() public method

Set the default username messages will be created for.
public setDefaultUsername ( string $username ) : void
$username string
return void

setEndpoint() public method

Set the Slack endpoint.
public setEndpoint ( string $endpoint ) : void
$endpoint string
return void

setLinkNames() public method

Set whether messages sent will have names (like @regan) will be converted into links.
public setLinkNames ( boolean $value ) : void
$value boolean
return void

setMarkdownInAttachments() public method

Set the attachment fields which should be formatted in Slack's Markdown-like language.
public setMarkdownInAttachments ( array $fields ) : void
$fields array
return void

setUnfurlMedia() public method

Set whether media links should be unfurled.
public setUnfurlMedia ( boolean $value ) : void
$value boolean
return void

Property Details

$allow_markdown protected property

Whether message text should be formatted with Slack's Markdown-like language.
protected bool $allow_markdown
return boolean

$channel protected property

The default channel to send messages to.
protected string $channel
return string

$endpoint protected property

The Slack incoming webhook endpoint.
protected string $endpoint
return string

$guzzle protected property

The Guzzle HTTP client instance.
protected Client,GuzzleHttp $guzzle
return GuzzleHttp\Client

$icon protected property

The default icon to send messages with.
protected string $icon
return string

$markdown_in_attachments protected property

The attachment fields which should be formatted with Slack's Markdown-like language.
protected array $markdown_in_attachments
return array

$unfurl_media protected property

Whether Slack should unfurl media URLs.
protected bool $unfurl_media
return boolean

$username protected property

The default username to send messages as.
protected string $username
return string