slack
The slack
module supports easily creating and sending messages to Slack channels, managing conversations, and interacting with users and user groups.
Module
slack.new_client(token string) slack.client
Initialize a new Slack client with an API token.
>>> client := slack.new_client("xoxb-your-token-here")
>>> client.post_message("#general", "Hello from Risor!")
{channel: "#general", timestamp: "1710000000.000000"}
Client
The Slack client provides methods for interacting with the Slack API.
post_message
post_message(channel_id string, message string|map) map
Sends a message to a Slack channel.
>>> client.post_message("#general", "Hello world!")
{channel: "#general", timestamp: "1710000000.000000"}
>>> client.post_message("#general", {
... text: "Message with attachment",
... attachments: [
... {
... title: "Attachment Title",
... text: "Attachment text here",
... color: "#36a64f"
... }
... ]
... })
{channel: "#general", timestamp: "1710000000.000000"}
post_ephemeral_message
post_ephemeral_message(channel_id string, user_id string, message string|map) map
Sends an ephemeral message to a Slack channel that is only visible to a specific user.
>>> client.post_ephemeral_message("#general", "U123456", "Only you can see this message")
{channel: "#general", timestamp: "1710000000.000000", user: "U123456"}
update_message
update_message(channel_id string, timestamp string, message string|map) map
Updates an existing message in a Slack channel.
>>> client.update_message("#general", "1710000000.000000", "Updated message content")
{channel: "#general", timestamp: "1710000000.000001"}
delete_message
delete_message(channel_id string, timestamp string)
Deletes a message from a Slack channel.
>>> client.delete_message("#general", "1710000000.000000")
add_reaction
add_reaction(emoji string, item_ref map) map
Adds an emoji reaction to a message or other item.
>>> client.add_reaction("thumbsup", {
... channel: "#general",
... timestamp: "1710000000.000000"
... })
{emoji: "thumbsup", added: true, channel: "#general", timestamp: "1710000000.000000"}
remove_reaction
remove_reaction(emoji string, item_ref map)
Removes an emoji reaction from a message or other item.
>>> client.remove_reaction("thumbsup", {
... channel: "#general",
... timestamp: "1710000000.000000"
... })
upload_file
upload_file(channel_id string, options map) map
Uploads a file to a Slack channel.
>>> client.upload_file("#general", {
... content: "File content here",
... filename: "example.txt",
... title: "Example File"
... })
{id: "F123456", title: "Example File"}
get_users
get_users(options map={}) [slack.user]
Gets a list of all users in the workspace.
>>> users := client.get_users()
>>> len(users)
42
>>> users[0].name
"johndoe"
get_user_info
get_user_info(user_id string) slack.user
Gets information about a specific user.
>>> user := client.get_user_info("U123456")
>>> user.name
"johndoe"
>>> user.profile.email
"[email protected]"
get_user_groups
get_user_groups(options map={}) [map]
Gets all user groups in the workspace.
>>> groups := client.get_user_groups({include_users: true})
>>> groups[0].name
"Engineering"
>>> groups[0].users
["U123456", "U234567"]
get_conversation_info
get_conversation_info(channel_id string) slack.channel
Gets information about a specific conversation.
>>> channel := client.get_conversation_info("C123456")
>>> channel.name
"general"
>>> channel.is_private
false
get_conversations
get_conversations(options map={}) slack.conversation_iterator
Gets a list of all conversations in the workspace.
Options:
types
: An optional array of conversation types to include. Valid values are:public_channel
: Public channels that anyone in the workspace can joinprivate_channel
: Private channels with restricted membershipmpim
: Multi-person direct messages (group DMs)im
: Direct messages between two users
exclude_archived
: Whether to exclude archived channels (default: false)
>>> convs := client.get_conversations({
... types: ["public_channel", "private_channel"],
... exclude_archived: true
... })
>>> for i, conv in convs {
... print(conv.name)
... }
general
random
team-project
create_conversation
create_conversation(name string, options map={}) slack.channel
Creates a new conversation (channel).
>>> channel := client.create_conversation("new-project", {is_private: true})
>>> channel.name
"new-project"
>>> channel.is_private
true
get_conversation_history
get_conversation_history(channel_id string, options map={}) slack.message_iterator
Gets the message history of a conversation.
>>> messages := client.get_conversation_history("#general", {limit: 10})
>>> for i, msg in messages {
... print(msg.text)
... }
Hello world!
Important announcement
Check out this link: https://example.com
get_conversation_members
get_conversation_members(channel_id string, options map={}) slack.conversation_members_iterator
Gets the members of a conversation.
>>> members := client.get_conversation_members("#general")
>>> for i, member_id in members {
... user := client.get_user_info(member_id)
... print(user.name)
... }
johndoe
janedoe
bobsmith
message_builder
message_builder() slack.message_builder
Creates a new message builder for constructing complex messages.
>>> builder := client.message_builder()
>>> builder.add_text("Hello world!")
>>> builder.add_divider()
>>> builder.add_section("This is a section")
>>> msg := builder.build()
>>> client.post_message("#general", msg)
{channel: "#general", timestamp: "1710000000.000000"}
Types
slack.client
The Slack client represents a connection to the Slack API and provides methods for interacting with it.
slack.channel
The channel object represents a Slack channel and provides access to its properties.
Properties
id
- The channel IDname
- The channel nameis_channel
- Whether the channel is a standard channelis_group
- Whether the channel is a groupis_im
- Whether the channel is a direct messageis_mpim
- Whether the channel is a multi-person direct messagecreated
- When the channel was createdcreator
- The user ID of the channel creatoris_archived
- Whether the channel is archivedis_general
- Whether the channel is the general channelunlinked
- When the channel was unlinkedname_normalized
- The normalized channel nameis_shared
- Whether the channel is sharedis_ext_shared
- Whether the channel is externally sharedis_org_shared
- Whether the channel is org sharedis_pending_ext_shared
- Whether the channel is pending external sharingis_member
- Whether the current user is a memberis_private
- Whether the channel is privateis_open
- Whether the channel is opentopic
- The channel topicpurpose
- The channel purposemembers
- The channel membersnum_members
- The number of members in the channel
Methods
json
json() map
Returns a map representation of the channel object.
>>> channel := client.get_conversation_info("C123456")
>>> channel_map := channel.json()
>>> channel_map.id
"C123456"
slack.message
The message object represents a Slack message and provides access to its properties.
Properties
text
- The message textchannel
- The channel IDtimestamp
- The message timestampthread_timestamp
- The thread timestampuser
- The user ID of the message sendertype
- The message typesubtype
- The message subtypeteam
- The team IDbot_id
- The bot ID if sent by a botusername
- The username if sent by a botreactions
- The reactions to the messageis_bot_message
- Whether the message was sent by a botreply_count
- The number of replies to the messagelatest_reply
- The timestamp of the latest reply
Methods
conversation
conversation() [slack.message]
Gets the conversation thread for this message.
>>> msg := messages[0]
>>> replies := msg.conversation()
>>> for reply in replies {
... print(reply.text)
... }
This is a reply
Another reply
json
json() map
Returns a map representation of the message object.
>>> msg := messages[0]
>>> msg_map := msg.json()
>>> msg_map.text
"Hello world!"
slack.user
The user object represents a Slack user and provides access to their properties.
Properties
id
- The user IDteam_id
- The team IDname
- The usernamedeleted
- Whether the user has been deletedcolor
- The user's color preferencereal_name
- The user's real nametz
- The user's timezonetz_label
- The user's timezone labeltz_offset
- The user's timezone offsetprofile
- The user's profileis_admin
- Whether the user is an adminis_owner
- Whether the user is an owneris_primary_owner
- Whether the user is the primary owneris_restricted
- Whether the user is restrictedis_ultra_restricted
- Whether the user is ultra restrictedis_bot
- Whether the user is a botis_app_user
- Whether the user is an app userupdated
- When the user was last updatedhas_2fa
- Whether the user has two-factor authentication enabledtwo_factor_type
- The user's two-factor authentication typehas_files
- Whether the user has filespresence
- The user's presence statuslocale
- The user's locale settingis_stranger
- Whether the user is a strangeris_invited_user
- Whether the user was invited
Methods
json
json() map
Returns a map representation of the user object.
>>> user := client.get_user_info("U123456")
>>> user_map := user.json()
>>> user_map.id
"U123456"
slack.user_profile
The user profile object represents a Slack user's profile and provides access to its properties.
Properties
real_name
- The user's real namereal_name_normalized
- The user's normalized real namedisplay_name
- The user's display namedisplay_name_normalized
- The user's normalized display nameemail
- The user's email addressfirst_name
- The user's first namelast_name
- The user's last namephone
- The user's phone numberskype
- The user's Skype handletitle
- The user's titleteam
- The user's teamstatus_text
- The user's status textstatus_emoji
- The user's status emojibot_id
- The user's bot IDimage_24
- URL to a 24x24 image for the userimage_32
- URL to a 32x32 image for the userimage_48
- URL to a 48x48 image for the userimage_72
- URL to a 72x72 image for the userimage_192
- URL to a 192x192 image for the userimage_512
- URL to a 512x512 image for the userimage_original
- URL to the original image for the user
Methods
json
json() map
Returns a map representation of the user profile object.
>>> user := client.get_user_info("U123456")
>>> profile_map := user.profile.json()
>>> profile_map.email
"[email protected]"
slack.conversation_iterator
An iterator for paging through conversations in a workspace.
>>> convs := client.get_conversations()
>>> for i, conv in convs {
... print(conv.name)
... }
general
random
team-project
Note: Iterators must be consumed through iteration and don't support len()
operations directly.
slack.message_iterator
An iterator for paging through messages in a conversation.
>>> messages := client.get_conversation_history("#general")
>>> for i, msg in messages {
... print(msg.text)
... }
Hello world!
Important announcement
Check out this link: https://example.com
slack.conversation_members_iterator
An iterator for paging through members of a conversation.
>>> members := client.get_conversation_members("#general")
>>> for i, member_id in members {
... user := client.get_user_info(member_id)
... print(user.name)
... }
johndoe
janedoe
bobsmith