plug.slack

exception immp.plug.slack.SlackAPIError

Bases: immp.core.error.PlugError

Generic error from the Slack API.

class immp.plug.slack.SlackUser(id_=None, plug=None, display_name=None, real_name=None, avatar=None, bot_id=None, app=False, raw=None)

Bases: immp.core.message.User

User present in Slack.

bot_id

str – Reference to the Slack integration app for a bot user.

classmethod from_member(slack, json)

Convert an API member dict to a User.

Parameters
  • slack (SlackPlug) – Related plug instance that provides the user.
  • json (dict) – Slack API user object.
Returns

Parsed user object.

Return type

SlackUser

classmethod from_bot(slack, json)

Convert an API bot dict to a User.

Parameters
  • slack (SlackPlug) – Related plug instance that provides the user.
  • json (dict) – Slack API bot object.
Returns

Parsed user object.

Return type

SlackUser

class immp.plug.slack.SlackRichText(segments=None)

Bases: immp.core.message.RichText

Wrapper for Slack-specific parsing of formatting.

classmethod from_mrkdwn(slack, text)

Convert a string of Slack’s Mrkdwn into a RichText.

Parameters
  • slack (SlackPlug) – Related plug instance that provides the text.
  • text (str) – Slack-style formatted text.
Returns

Parsed rich text container.

Return type

SlackRichText

classmethod to_mrkdwn(slack, rich)

Convert a RichText instance into a string of Slack’s Mrkdwn.

Parameters
  • slack (SlackPlug) – Related plug instance to cross-reference users.
  • rich (SlackRichText) – Parsed rich text container.
Returns

Slack-style formatted text.

Return type

str

class immp.plug.slack.SlackFile(slack, title=None, type_=None, source=None)

Bases: immp.core.message.File

File attachment originating from Slack.

classmethod from_file(slack, json)

Convert an API file dict to a File.

Parameters
  • slack (SlackPlug) – Related plug instance that provides the file.
  • json (dict) – Slack API file data.
Returns

Parsed file object.

Return type

SlackFile

class immp.plug.slack.SlackMessage(*, text=None, user=None, edited=False, action=False, reply_to=None, joined=None, left=None, title=None, attachments=None, raw=None)

Bases: immp.core.message.Message

Message originating from Slack.

classmethod from_event(slack, json, parent=True)

Convert an API event dict to a Message.

Parameters
  • slack (SlackPlug) – Related plug instance that provides the event.
  • json (dict) – Slack API message event data.
  • parent (bool) – True (default) to retrieve the thread parent if one exists.
Returns

Parsed message object.

Return type

SlackMessage

classmethod to_attachment(slack, msg, reply=False)

Convert a Message to a message attachment structure, suitable for embedding within an outgoing message.

Parameters
  • slack (SlackPlug) – Target plug instance for this attachment.
  • msg (Message) – Original message from another plug or hook.
  • reply (bool) – Whether to show a reply icon instead of a quote icon.
Returns.
dict:
Slack API attachment object.
class immp.plug.slack.SlackPlug(name, config, host)

Bases: immp.core.util.HTTPOpenable, immp.core.plug.Plug

Plug for a Slack team.

same_team(other)

Test if two Slack plugs represent the same team.

Parameters
other (SlackPlug) – Second plug instance to compare with.
Returns
True if both plugs are connected to the same team.
Return type
bool