0
# Chat & Messaging
1
2
Comprehensive messaging functionality for sending, updating, and managing messages across channels, direct messages, and group conversations.
3
4
## Capabilities
5
6
### Message Posting
7
8
Send messages to channels with rich formatting, attachments, and interactive elements.
9
10
```python { .api }
11
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):
12
"""
13
Post a message to a channel.
14
15
Args:
16
channel (str): Channel ID or name (e.g., '#general', 'C1234567890')
17
text (str, optional): Message text content
18
username (str, optional): Username for the message sender
19
as_user (bool, optional): Send message as authenticated user
20
parse (str, optional): Parsing mode ('full', 'none')
21
link_names (bool, optional): Find and link channel/user names
22
attachments (list or str, optional): Message attachments (JSON string or list)
23
unfurl_links (bool, optional): Enable link unfurling
24
unfurl_media (bool, optional): Enable media unfurling
25
icon_url (str, optional): URL for message icon
26
icon_emoji (str, optional): Emoji for message icon
27
thread_ts (str, optional): Timestamp of parent message for threading
28
reply_broadcast (bool, optional): Broadcast threaded reply to channel
29
blocks (list, optional): Block Kit layout elements
30
mrkdwn (bool): Enable markdown parsing (default: True)
31
32
Returns:
33
Response: Contains message timestamp and channel information
34
"""
35
```
36
37
Usage:
38
```python
39
# Simple message
40
slack.chat.post_message('#general', 'Hello, world!')
41
42
# Message with attachments
43
attachments = [{"text": "Attachment text", "color": "good"}]
44
slack.chat.post_message('#general', 'Main message', attachments=attachments)
45
46
# Threaded reply
47
slack.chat.post_message('#general', 'Reply text', thread_ts='1234567890.123456')
48
```
49
50
### Message Updates
51
52
Update existing messages by changing text, attachments, or other properties.
53
54
```python { .api }
55
def update(self, channel, ts, text, attachments=None, parse=None, link_names=False, as_user=None, blocks=None):
56
"""
57
Update an existing message.
58
59
Args:
60
channel (str): Channel containing the message
61
ts (str): Timestamp of message to update
62
text (str): New message text
63
attachments (list or str, optional): New attachments
64
parse (str, optional): Parsing mode
65
link_names (bool): Find and link names (default: False)
66
as_user (bool, optional): Update as authenticated user
67
blocks (list, optional): New Block Kit elements
68
69
Returns:
70
Response: Updated message information
71
"""
72
```
73
74
### Message Deletion
75
76
Delete messages from channels and conversations.
77
78
```python { .api }
79
def delete(self, channel, ts, as_user=False):
80
"""
81
Delete a message.
82
83
Args:
84
channel (str): Channel containing the message
85
ts (str): Timestamp of message to delete
86
as_user (bool): Delete as authenticated user (default: False)
87
88
Returns:
89
Response: Deletion confirmation
90
"""
91
```
92
93
### Ephemeral Messages
94
95
Send private messages visible only to specific users within a channel.
96
97
```python { .api }
98
def post_ephemeral(self, channel, text, user, as_user=None, attachments=None, link_names=None, parse=None, blocks=None):
99
"""
100
Post ephemeral message visible only to specific user.
101
102
Args:
103
channel (str): Channel to post in
104
text (str): Message text
105
user (str): User ID who will see the message
106
as_user (bool, optional): Send as authenticated user
107
attachments (list or str, optional): Message attachments
108
link_names (bool, optional): Link channel/user names
109
parse (str, optional): Parsing mode
110
blocks (list, optional): Block Kit elements
111
112
Returns:
113
Response: Ephemeral message confirmation
114
"""
115
```
116
117
### Me Messages
118
119
Send messages formatted as actions (similar to IRC /me commands).
120
121
```python { .api }
122
def me_message(self, channel, text):
123
"""
124
Send an action message (appears as "* username text").
125
126
Args:
127
channel (str): Channel to send message to
128
text (str): Action text
129
130
Returns:
131
Response: Message information
132
"""
133
```
134
135
### Slash Commands
136
137
Execute slash commands programmatically within channels.
138
139
```python { .api }
140
def command(self, channel, command, text):
141
"""
142
Execute a slash command.
143
144
Args:
145
channel (str): Channel to execute command in
146
command (str): Command name (with or without leading slash)
147
text (str): Command arguments
148
149
Returns:
150
Response: Command execution result
151
"""
152
```
153
154
### Link Unfurling
155
156
Provide custom unfurling for links in messages.
157
158
```python { .api }
159
def unfurl(self, channel, ts, unfurls, user_auth_message=None, user_auth_required=False, user_auth_url=None):
160
"""
161
Provide custom unfurling for links in a message.
162
163
Args:
164
channel (str): Channel containing the message
165
ts (str): Message timestamp
166
unfurls (dict): URL unfurling information
167
user_auth_message (str, optional): Authentication message
168
user_auth_required (bool): Whether user auth is required (default: False)
169
user_auth_url (str, optional): Authentication URL
170
171
Returns:
172
Response: Unfurling result
173
"""
174
```
175
176
### Permalink Generation
177
178
Generate permanent links to specific messages.
179
180
```python { .api }
181
def get_permalink(self, channel, message_ts):
182
"""
183
Get permalink URL for a message.
184
185
Args:
186
channel (str): Channel containing the message
187
message_ts (str): Message timestamp
188
189
Returns:
190
Response: Contains permalink URL
191
"""
192
```
193
194
## Types
195
196
```python { .api }
197
class Chat(BaseAPI):
198
"""Chat and messaging endpoint handler."""
199
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): ...
200
def me_message(self, channel, text): ...
201
def command(self, channel, command, text): ...
202
def update(self, channel, ts, text, attachments=None, parse=None, link_names=False, as_user=None, blocks=None): ...
203
def delete(self, channel, ts, as_user=False): ...
204
def post_ephemeral(self, channel, text, user, as_user=None, attachments=None, link_names=None, parse=None, blocks=None): ...
205
def unfurl(self, channel, ts, unfurls, user_auth_message=None, user_auth_required=False, user_auth_url=None): ...
206
def get_permalink(self, channel, message_ts): ...
207
```