SlackSocket Client

To instantiate a SlackSocket object that will setup an RTM websocket:

from slacksocket import SlackSocket
s = SlackSocket('<slack-token>')

Likewise, SlackSocket can be used as a context:

from slacksocket import SlackSocket
with SlackSocket('<slack-token>') as s:
    s.send_msg(text='hello', channel_name='general')


  • slacktoken (str): token to authenticate with slack
  • translate (bool): yield events with human-readable user/channel names rather than id. default True
  • event_filter (list): Slack event type(s) to filter by. Excluding a filter returns all slack events. See for a listing of valid event types.



Return a single event object in the order received or block until an event is received and return it.

Returns (obj): SlackEvent object


Return a generator yielding SlackEvent objects

Returns (generator): A generator of SlackEvent objects


Send a message via Slack RTM socket and wait for confirmation it was received. One of either channel_name or channel_id params is required.


  • text (str): Message body to send
  • channel_name(str): Name of the channel to post message
  • channel_id(str): Slack ID of the channel to post message
  • confirm(bool): Boolean to toggle blocking until a reply back is received from slack. default True

Returns (obj): SlackMsg object


Get a direct message channel for a user. Open one if it does not already exist.


  • username (str): Display name of the user to message

Returns (dict): dictionary with the channel information


s = SlackSocket(<token>)
{'is_user_deleted': False, 'id': 'D0L7XNQCV', 'is_im': True, 'user': 'U071Y0CSZ', 'created': 1454542620}


Event object received from SlackSocket

Note: If slacksocket was instantiated with translate=True(default), user and channel IDs in the event will be replaced with their human-readable versions rather than ID.


  • type (str): The Slack API event type
  • time (int): UTC epoch time that the event was received by the client
  • event (dict): Dictionary of the event received from slack
  • json (str): Event encoded as JSON


Msg created and sent via Slack RTM websocket


  • time (int): UTC epoch time that the message was acknowledged as sent
  • sent (bool): Boolean for message being sent successfully
  • json (str): Message in JSON format