Slack API client providing comprehensive Python interface for messaging, file sharing, user management, and team communication features.
—
Comprehensive messaging functionality for sending, updating, and managing messages across channels, direct messages, and group conversations.
Send messages to channels with rich formatting, attachments, and interactive elements.
def post_message(self, channel, text=None, username=None, as_user=None, parse=None, link_names=None, attachments=None, unfurl_links=None, unfurl_media=None, icon_url=None, icon_emoji=None, thread_ts=None, reply_broadcast=None, blocks=None, mrkdwn=True):
"""
Post a message to a channel.
Args:
channel (str): Channel ID or name (e.g., '#general', 'C1234567890')
text (str, optional): Message text content
username (str, optional): Username for the message sender
as_user (bool, optional): Send message as authenticated user
parse (str, optional): Parsing mode ('full', 'none')
link_names (bool, optional): Find and link channel/user names
attachments (list or str, optional): Message attachments (JSON string or list)
unfurl_links (bool, optional): Enable link unfurling
unfurl_media (bool, optional): Enable media unfurling
icon_url (str, optional): URL for message icon
icon_emoji (str, optional): Emoji for message icon
thread_ts (str, optional): Timestamp of parent message for threading
reply_broadcast (bool, optional): Broadcast threaded reply to channel
blocks (list, optional): Block Kit layout elements
mrkdwn (bool): Enable markdown parsing (default: True)
Returns:
Response: Contains message timestamp and channel information
"""Usage:
# Simple message
slack.chat.post_message('#general', 'Hello, world!')
# Message with attachments
attachments = [{"text": "Attachment text", "color": "good"}]
slack.chat.post_message('#general', 'Main message', attachments=attachments)
# Threaded reply
slack.chat.post_message('#general', 'Reply text', thread_ts='1234567890.123456')Update existing messages by changing text, attachments, or other properties.
def update(self, channel, ts, text, attachments=None, parse=None, link_names=False, as_user=None, blocks=None):
"""
Update an existing message.
Args:
channel (str): Channel containing the message
ts (str): Timestamp of message to update
text (str): New message text
attachments (list or str, optional): New attachments
parse (str, optional): Parsing mode
link_names (bool): Find and link names (default: False)
as_user (bool, optional): Update as authenticated user
blocks (list, optional): New Block Kit elements
Returns:
Response: Updated message information
"""Delete messages from channels and conversations.
def delete(self, channel, ts, as_user=False):
"""
Delete a message.
Args:
channel (str): Channel containing the message
ts (str): Timestamp of message to delete
as_user (bool): Delete as authenticated user (default: False)
Returns:
Response: Deletion confirmation
"""Send private messages visible only to specific users within a channel.
def post_ephemeral(self, channel, text, user, as_user=None, attachments=None, link_names=None, parse=None, blocks=None):
"""
Post ephemeral message visible only to specific user.
Args:
channel (str): Channel to post in
text (str): Message text
user (str): User ID who will see the message
as_user (bool, optional): Send as authenticated user
attachments (list or str, optional): Message attachments
link_names (bool, optional): Link channel/user names
parse (str, optional): Parsing mode
blocks (list, optional): Block Kit elements
Returns:
Response: Ephemeral message confirmation
"""Send messages formatted as actions (similar to IRC /me commands).
def me_message(self, channel, text):
"""
Send an action message (appears as "* username text").
Args:
channel (str): Channel to send message to
text (str): Action text
Returns:
Response: Message information
"""Execute slash commands programmatically within channels.
def command(self, channel, command, text):
"""
Execute a slash command.
Args:
channel (str): Channel to execute command in
command (str): Command name (with or without leading slash)
text (str): Command arguments
Returns:
Response: Command execution result
"""Provide custom unfurling for links in messages.
def unfurl(self, channel, ts, unfurls, user_auth_message=None, user_auth_required=False, user_auth_url=None):
"""
Provide custom unfurling for links in a message.
Args:
channel (str): Channel containing the message
ts (str): Message timestamp
unfurls (dict): URL unfurling information
user_auth_message (str, optional): Authentication message
user_auth_required (bool): Whether user auth is required (default: False)
user_auth_url (str, optional): Authentication URL
Returns:
Response: Unfurling result
"""Generate permanent links to specific messages.
def get_permalink(self, channel, message_ts):
"""
Get permalink URL for a message.
Args:
channel (str): Channel containing the message
message_ts (str): Message timestamp
Returns:
Response: Contains permalink URL
"""class Chat(BaseAPI):
"""Chat and messaging endpoint handler."""
def post_message(self, channel, text=None, username=None, as_user=None, parse=None, link_names=None, attachments=None, unfurl_links=None, unfurl_media=None, icon_url=None, icon_emoji=None, thread_ts=None, reply_broadcast=None, blocks=None, mrkdwn=True): ...
def me_message(self, channel, text): ...
def command(self, channel, command, text): ...
def update(self, channel, ts, text, attachments=None, parse=None, link_names=False, as_user=None, blocks=None): ...
def delete(self, channel, ts, as_user=False): ...
def post_ephemeral(self, channel, text, user, as_user=None, attachments=None, link_names=None, parse=None, blocks=None): ...
def unfurl(self, channel, ts, unfurls, user_auth_message=None, user_auth_required=False, user_auth_url=None): ...
def get_permalink(self, channel, message_ts): ...Install with Tessl CLI
npx tessl i tessl/pypi-slacker