From bf781179a2ac8c717397b1b49d805c8b12e8e971 Mon Sep 17 00:00:00 2001 From: Marco Matteocci Date: Tue, 16 May 2023 14:40:53 +0200 Subject: [PATCH 1/2] added Slack Blocks function --- readme.md | 3 +++ src/Vluzrmos/SlackApi/Methods/Chat.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/readme.md b/readme.md index 8ddbab1..5f5ba45 100644 --- a/readme.md +++ b/readme.md @@ -148,6 +148,9 @@ SlackUserAdmin::invite("example@example.com", [ //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::blocks('#general', '[{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}]'); + //Upload a file/snippet SlackFile::upload([ 'filename' => 'sometext.txt', diff --git a/src/Vluzrmos/SlackApi/Methods/Chat.php b/src/Vluzrmos/SlackApi/Methods/Chat.php index 7f108b0..ec9b976 100644 --- a/src/Vluzrmos/SlackApi/Methods/Chat.php +++ b/src/Vluzrmos/SlackApi/Methods/Chat.php @@ -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 = []) + { + 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 From af91e19346db59f5af86fe34b348443e6d921bd2 Mon Sep 17 00:00:00 2001 From: Marco Matteocci Date: Tue, 16 May 2023 14:43:48 +0200 Subject: [PATCH 2/2] updated readme file --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5f5ba45..af4e85c 100644 --- a/readme.md +++ b/readme.md @@ -149,7 +149,7 @@ SlackUserAdmin::invite("example@example.com", [ SlackChat::message('#general', 'Hello my friends!'); //Send a block to someone or channel or group -SlackChat::blocks('#general', '[{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}]'); +SlackChat::block('#general', '[{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}]'); //Upload a file/snippet SlackFile::upload([