Expand description
§Slack Morphism for Rust
Slack Morphism is a modern client library for Slack Web/Events API and Block Kit.
§Slack Web API client
§Create a client instance:
use slack_morphism::prelude::*;
let client = SlackClient::new(SlackClientHyperConnector::new());
§Make Web API methods calls
For most of Slack Web API methods (except for OAuth methods, Incoming Webhooks and event replies) you need a Slack token to make a call. For simple bots you can have it in your config files, or you can obtain workspace tokens using Slack OAuth.
In the example below, we’re using a hardcoded Slack token, but don’t do that for your production bots and apps. You should securely and properly store all of Slack tokens.
use slack_morphism::prelude::*;
let client = SlackClient::new(SlackClientHyperConnector::new());
// Create our Slack API token
let token_value: SlackApiTokenValue = "xoxb-89.....".into();
let token: SlackApiToken = SlackApiToken::new(token_value);
// Create a Slack session with this token
// A session is just a lightweight wrapper around your token
// not to specify it all the time for series of calls.
let session = client.open_session(&token);
// Make your first API call (which is `api.test` here)
let test: SlackApiTestResponse = session
.api_test(&SlackApiTestRequest::new().with_foo("Test".into()))
.await?;
// Send a simple text message
let post_chat_req =
SlackApiChatPostMessageRequest::new("#general".into(),
SlackMessageContent::new().with_text("Hey there!".into())
);
let post_chat_resp = session.chat_post_message(&post_chat_req).await?;
§Block Kit
Blocks, block elements, and views are modeled as typed structs and enums,
with the slack_blocks! macro (and md!/pt! for text objects)
to build the block lists they hold:
use slack_morphism::prelude::*;
let show_footer = true;
let blocks: Vec<SlackBlock> = slack_blocks![
SlackHeaderBlock::new(pt!("Deploy report")),
SlackSectionBlock::new()
.with_text(md!("Deployed *{}* to {}", "api", "us-east-1"))
.with_fields(vec![md!("*Duration:*\n42s"), md!("*Result:*\nsuccess")]),
SlackActionsBlock::new(slack_blocks![
SlackBlockButtonElement::new(pt!("Rollback"))
.with_action_id("rollback".into())
.with_style(SlackBlockButtonStyle::Danger),
SlackBlockButtonElement::new(pt!("View details")).with_action_id("details".into()),
]),
SlackRichTextBlock::new(vec![SlackRichTextSection::new(vec![
"Triggered by ".into(),
SlackRichTextText::new("the release bot".to_string()).bold().into(),
])
.into()]),
SlackTableBlock::new(vec![
vec!["Service".into(), "Status".into()],
vec!["api".into(), "healthy".into()],
]),
optionally(show_footer => SlackContextBlock::new(vec![md!("Posted automatically")])),
];
let content = SlackMessageContent::new().with_blocks(blocks);See the blocks::block_kit module docs for a full guide covering text
objects, sections, actions and inputs, rich text, tables, templates, and
views.
§Events API and OAuth support for Hyper and Axum
The library provides two different ways to work with Slack Events API:
- Using pure Hyper-based solution
- Using more high-level solution for axum web framework.
Also the library provides Slack events signature verifier (SlackEventSignatureVerifier)
(which is already integrated in the routes implementation for you).
All you need is provide your client id and secret configuration to route implementation.
§Socket Mode support
The library provides Socket Mode support additionally Events API leveraging Web-sockets in cases you don’t want/need to expose publicly available HTTP endpoint.
§Docs and examples
Please follow to the official website. Examples available on: github.
Re-exports§
pub use socket_mode::*;
Modules§
Macros§
- md
- Builds a
SlackBlockMarkDownText, converted into the caller’s target type viaInto. - pt
- Builds a
SlackBlockPlainText, converted into the caller’s target type viaInto. - slack_
block_ item - slack_
blocks - Builds a
Vec<T>of block-kit items from a comma-separated list, in one of two syntaxes that may be freely mixed within a single list:
Structs§
- Email
Address - Phone
Number - SLACK_
HTTP_ EMPTY_ GET_ PARAMS - Slack
Action Id - Slack
Action Type - Slack
ApiCookie Value - Slack
ApiResponse Scroller State - Slack
ApiToken - Slack
ApiToken Init - Required fields of
SlackApiToken; convert withSlackApiToken::fromor.into(). - Slack
ApiToken Scope - Slack
ApiToken Value - Slack
AppContext Entity Type - Slack
AppCredentials - Slack
AppCredentials Init - Required fields of
SlackAppCredentials; convert withSlackAppCredentials::fromor.into(). - Slack
AppId - Slack
AppManifest - Slack
AppManifest Display Information - Slack
AppManifest Display Information Init - Required fields of
SlackAppManifestDisplayInformation; convert withSlackAppManifestDisplayInformation::fromor.into(). - Slack
AppManifest Features - Slack
AppManifest Features AppHome - Slack
AppManifest Features AppHome Init - Required fields of
SlackAppManifestFeaturesAppHome; convert withSlackAppManifestFeaturesAppHome::fromor.into(). - Slack
AppManifest Features BotUser - Slack
AppManifest Features BotUser Init - Required fields of
SlackAppManifestFeaturesBotUser; convert withSlackAppManifestFeaturesBotUser::fromor.into(). - Slack
AppManifest Features Init - Required fields of
SlackAppManifestFeatures; convert withSlackAppManifestFeatures::fromor.into(). - Slack
AppManifest Features Shortcut - Slack
AppManifest Features Shortcut Init - Required fields of
SlackAppManifestFeaturesShortcut; convert withSlackAppManifestFeaturesShortcut::fromor.into(). - Slack
AppManifest Features Slash Command - Slack
AppManifest Features Slash Command Init - Required fields of
SlackAppManifestFeaturesSlashCommand; convert withSlackAppManifestFeaturesSlashCommand::fromor.into(). - Slack
AppManifest Features Workflow Step - Slack
AppManifest Features Workflow Step Init - Required fields of
SlackAppManifestFeaturesWorkflowStep; convert withSlackAppManifestFeaturesWorkflowStep::fromor.into(). - Slack
AppManifest Init - Required fields of
SlackAppManifest; convert withSlackAppManifest::fromor.into(). - Slack
AppManifest Metadata - Slack
AppManifest Metadata Init - Required fields of
SlackAppManifestMetadata; convert withSlackAppManifestMetadata::fromor.into(). - Slack
AppManifestO Auth Config - Slack
AppManifestO Auth Config Init - Required fields of
SlackAppManifestOAuthConfig; convert withSlackAppManifestOAuthConfig::fromor.into(). - Slack
AppManifestO Auth Config Scopes - Slack
AppManifestO Auth Config Scopes Init - Required fields of
SlackAppManifestOAuthConfigScopes; convert withSlackAppManifestOAuthConfigScopes::fromor.into(). - Slack
AppManifest Settings - Slack
AppManifest Settings Event Subscriptions - Slack
AppManifest Settings Event Subscriptions Init - Required fields of
SlackAppManifestSettingsEventSubscriptions; convert withSlackAppManifestSettingsEventSubscriptions::fromor.into(). - Slack
AppManifest Settings Init - Required fields of
SlackAppManifestSettings; convert withSlackAppManifestSettings::fromor.into(). - Slack
AppManifest Settings Interactivity - Slack
AppManifest Settings Interactivity Init - Required fields of
SlackAppManifestSettingsInteractivity; convert withSlackAppManifestSettingsInteractivity::fromor.into(). - Slack
Assistant Prompt - Slack
Assistant Prompt Init - Required fields of
SlackAssistantPrompt; convert withSlackAssistantPrompt::fromor.into(). - Slack
Assistant Thread - Slack
Assistant Thread Context - Slack
Assistant Thread Context Init - Required fields of
SlackAssistantThreadContext; convert withSlackAssistantThreadContext::fromor.into(). - Slack
Assistant Thread Init - Required fields of
SlackAssistantThread; convert withSlackAssistantThread::fromor.into(). - Slack
Avatar Hash - Slack
Basic Channel Info - Slack
Basic Channel Info Init - Required fields of
SlackBasicChannelInfo; convert withSlackBasicChannelInfo::fromor.into(). - Slack
Basic Team Info - Slack
Basic Team Info Init - Required fields of
SlackBasicTeamInfo; convert withSlackBasicTeamInfo::fromor.into(). - Slack
Basic User Info - Slack
Basic User Info Init - Required fields of
SlackBasicUserInfo; convert withSlackBasicUserInfo::fromor.into(). - Slack
BotId - Slack
BotInfo - Slack
BotInfo Init - Required fields of
SlackBotInfo; convert withSlackBotInfo::fromor.into(). - Slack
Callback Id - Slack
Canvas Id - Slack
Canvas Section Id - A section inside a canvas, e.g.
temp:C:eBa219af721c664422cb90a52fac. - Slack
Channel Current State - Slack
Channel Current State Init - Required fields of
SlackChannelCurrentState; convert withSlackChannelCurrentState::fromor.into(). - Slack
Channel Details - Slack
Channel Details Init - Required fields of
SlackChannelDetails; convert withSlackChannelDetails::fromor.into(). - Slack
Channel Flags - Slack
Channel Flags Init - Required fields of
SlackChannelFlags; convert withSlackChannelFlags::fromor.into(). - Slack
Channel Id - Slack
Channel Info - Slack
Channel Info Init - Required fields of
SlackChannelInfo; convert withSlackChannelInfo::fromor.into(). - Slack
Channel Priority - Slack
Channel Type - Slack
Client - Slack
Client ApiCall Context - Slack
Client Http Api - Slack
Client Http ApiUri - Slack
Client Http Session Api - Slack
Client Id - Slack
Client Message Id - Slack
Client Secret - Slack
Client Session - Slack
Color - Slack
Command Id - Slack
Conversation Id - Slack
Cursor Id - Slack
Date - Slack
Date Time - Slack
Emoji - Slack
Emoji Name - Represent a Slack custom emoji name without the leading
:and trailing: - Slack
Enterprise Id - Slack
Enterprise Subteam Id - Slack
Enterprise User - Slack
Enterprise User Init - Required fields of
SlackEnterpriseUser; convert withSlackEnterpriseUser::fromor.into(). - Slack
Envelope Message - Slack
Event Type - Slack
File - Slack
File Comment Id - Slack
File External Type - Slack
File Flags - Slack
File Flags Init - Required fields of
SlackFileFlags; convert withSlackFileFlags::fromor.into(). - Slack
File Id - Slack
File Init - Required fields of
SlackFile; convert withSlackFile::fromor.into(). - Slack
File Pretty Type - Slack
File Snippet Type - Slack
File Type - Slack
File Upload Url - Slack
History Message - Slack
History Message Init - Required fields of
SlackHistoryMessage; convert withSlackHistoryMessage::fromor.into(). - Slack
Icon - Slack
Icon Images - Slack
Icon Images Init - Required fields of
SlackIconImages; convert withSlackIconImages::fromor.into(). - Slack
Icon Init - Required fields of
SlackIcon; convert withSlackIcon::fromor.into(). - Slack
Locale - Slack
Message - Slack
Message Attachment - Slack
Message Attachment Field Object - Slack
Message Attachment Field Object Init - Required fields of
SlackMessageAttachmentFieldObject; convert withSlackMessageAttachmentFieldObject::fromor.into(). - Slack
Message Attachment Id - Slack
Message Attachment Init - Required fields of
SlackMessageAttachment; convert withSlackMessageAttachment::fromor.into(). - Slack
Message Content - Slack
Message Content Init - Required fields of
SlackMessageContent; convert withSlackMessageContent::fromor.into(). - Slack
Message Edited - Slack
Message Edited Init - Required fields of
SlackMessageEdited; convert withSlackMessageEdited::fromor.into(). - Slack
Message Init - Required fields of
SlackMessage; convert withSlackMessage::fromor.into(). - Slack
Message Metadata - Slack
Message Metadata Init - Required fields of
SlackMessageMetadata; convert withSlackMessageMetadata::fromor.into(). - Slack
Message Origin - Slack
Message Origin Init - Required fields of
SlackMessageOrigin; convert withSlackMessageOrigin::fromor.into(). - Slack
Message Sender - Slack
Message Sender Init - Required fields of
SlackMessageSender; convert withSlackMessageSender::fromor.into(). - Slack
Mime Type - Slack
Parent Message Params - Slack
Parent Message Params Init - Required fields of
SlackParentMessageParams; convert withSlackParentMessageParams::fromor.into(). - Slack
Pin - Slack
PinInit - Required fields of
SlackPin; convert withSlackPin::fromor.into(). - Slack
Reaction - Slack
Reaction Init - Required fields of
SlackReaction; convert withSlackReaction::fromor.into(). - Slack
Reaction Name - Slack
Relaxed Url - This type is needed since Slack allowes invalid URLs in some places like Rich sections and we still need to read them on the client side, so we store it as a string but provide convinent messages to convert to Url if possible.
- Slack
Response Metadata - Slack
Response Metadata Init - Required fields of
SlackResponseMetadata; convert withSlackResponseMetadata::fromor.into(). - Slack
Response Url - Slack
Scheduled Mid - Slack
Signing Secret - Slack
Stars Item Channel - Slack
Stars Item Channel Init - Required fields of
SlackStarsItemChannel; convert withSlackStarsItemChannel::fromor.into(). - Slack
Stars Item File - Slack
Stars Item File Comment - Slack
Stars Item File Comment Init - Required fields of
SlackStarsItemFileComment; convert withSlackStarsItemFileComment::fromor.into(). - Slack
Stars Item File Init - Required fields of
SlackStarsItemFile; convert withSlackStarsItemFile::fromor.into(). - Slack
Stars Item Group - Slack
Stars Item Group Init - Required fields of
SlackStarsItemGroup; convert withSlackStarsItemGroup::fromor.into(). - Slack
Stars Item Im - Slack
Stars Item ImInit - Required fields of
SlackStarsItemIm; convert withSlackStarsItemIm::fromor.into(). - Slack
Stars Item Message - Slack
Stars Item Message Init - Required fields of
SlackStarsItemMessage; convert withSlackStarsItemMessage::fromor.into(). - Slack
Team Id - Slack
Team Info - Slack
Team Info Init - Required fields of
SlackTeamInfo; convert withSlackTeamInfo::fromor.into(). - Slack
Team Profile - Slack
Team Profile Field - Slack
Team Profile Field Id - Slack
Team Profile Field Init - Required fields of
SlackTeamProfileField; convert withSlackTeamProfileField::fromor.into(). - Slack
Team Profile Init - Required fields of
SlackTeamProfile; convert withSlackTeamProfile::fromor.into(). - Slack
Team Url - Slack
Trigger Id - SlackTs
- Slack
Unfurl Id - Slack
Updated Message - Slack
Updated Message Init - Required fields of
SlackUpdatedMessage; convert withSlackUpdatedMessage::fromor.into(). - Slack
User - Slack
User Flags - Slack
User Flags Init - Required fields of
SlackUserFlags; convert withSlackUserFlags::fromor.into(). - Slack
User Group - Slack
User Group Id - Slack
User Group Init - Required fields of
SlackUserGroup; convert withSlackUserGroup::fromor.into(). - Slack
User Group Prefs - Slack
User Group Prefs Init - Required fields of
SlackUserGroupPrefs; convert withSlackUserGroupPrefs::fromor.into(). - Slack
User Id - Slack
User Init - Required fields of
SlackUser; convert withSlackUser::fromor.into(). - Slack
User Profile - Slack
User Profile Field Id - Slack
User Profile Field Value - Slack
User Profile Init - Required fields of
SlackUserProfile; convert withSlackUserProfile::fromor.into(). - Slack
Verification Token - Slack
View Id - Slack
WebSockets Url
Enums§
- Slack
ApiToken Type - Slack
Auto Type - Slack
Conversation Type - Slack
Emoji Ref - Slack
Huddle State - Slack
Message Response Type - Slack
Reactions Item - Slack
Shortcut Type - Slack
Stars Item
Traits§
- HasChannel
Info - Slack
ApiResponse Scroller - Slack
ApiScrollable Request - Slack
ApiScrollable Response - Slack
Blocks Template - Slack
Client Http Connector - Slack
Message Template - Slack
Text Format
Type Aliases§
- AnyStd
Result - Client
Result - Slack
Channel Purpose Info - Slack
Channel Topic Info - Slack
Civil Date - A calendar date without a time zone, as used by the Slack API.
- Slack
UtcDate Time - An instant in time in UTC, as used by the Slack API.
- User
Callback Result