Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack Blocks components #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ SlackUserAdmin::invite("[email protected]", [
//Send a message to someone or channel or group
SlackChat::message('#general', 'Hello my friends!');

//Send a block to someone or channel or group
SlackChat::block('#general', '[{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}]');

//Upload a file/snippet
SlackFile::upload([
'filename' => 'sometext.txt',
Expand Down
17 changes: 17 additions & 0 deletions src/Vluzrmos/SlackApi/Methods/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ public function message($channel, $text, $options = [])
return $this->method('postMessage', array_merge(compact('channel', 'text'), ['as_user' => !isset($options['username'])], $options));
}


/**
* This method posts a Slack block to a channel.
*
* @see https://api.slack.com/methods/chat.postMessage
*
* @param string $channel Channel to send message to. Can be a public channel, private group or IM channel. Can be an encoded ID, or a name.
* @param string $blocks Slack Block structure to send Example: [{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}].
* @param array $options
*
* @return array
*/
public function block($channel, $blocks, $options = [])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that $blocks variable can be an array and then converted to json.

{
return $this->method('postMessage', array_merge(compact('channel', 'blocks'), ['as_user' => !isset($options['username'])], $options));
}

/**
* Alias to message().
* @see https://api.slack.com/methods/chat.postMessage
Expand Down