Slack API client providing comprehensive Python interface for messaging, file sharing, user management, and team communication features.
—
Connect to Slack's Real Time Messaging API for live message streams and event handling.
Establish real-time connections to receive live events from Slack.
def start(self, simple_latest=False, no_unreads=False, mpim_aware=False):
"""
Start RTM connection with comprehensive workspace data.
Args:
simple_latest (bool): Return simple message format (default: False)
no_unreads (bool): Skip unread counts in initial data (default: False)
mpim_aware (bool): Include multi-party IM awareness (default: False)
Returns:
Response: WebSocket URL and complete workspace state including:
- WebSocket URL for connection
- User and team information
- Channel and group lists
- IM and MPIM conversations
- Bot information
"""
def connect(self):
"""
Connect to RTM with minimal initial data.
Returns:
Response: WebSocket URL and basic connection information
"""Usage:
# Full RTM start with complete workspace data
response = slack.rtm.start()
if response.successful:
ws_url = response.body['url']
users = response.body['users']
channels = response.body['channels']
# Connect to WebSocket URL to receive events
# Lightweight RTM connection
response = slack.rtm.connect()
ws_url = response.body['url']
# Connect to WebSocket for events onlyOnce connected to the WebSocket URL, you'll receive real-time events including:
The RTM API provides a WebSocket URL that you'll need to connect to using a WebSocket client library:
import websocket
import json
def on_message(ws, message):
event = json.loads(message)
if event['type'] == 'message':
print(f"New message: {event['text']}")
def on_error(ws, error):
print(f"WebSocket error: {error}")
# Get WebSocket URL from RTM
response = slack.rtm.start()
ws_url = response.body['url']
# Connect to WebSocket
ws = websocket.WebSocketApp(ws_url,
on_message=on_message,
on_error=on_error)
ws.run_forever()class RTM(BaseAPI):
"""Real-time messaging connection management."""
def start(self, simple_latest=False, no_unreads=False, mpim_aware=False): ...
def connect(self): ...Install with Tessl CLI
npx tessl i tessl/pypi-slacker