Version: Main/Unreleased

rasa.core.channels.slack

SlackBot Objects

class SlackBot(OutputChannel)

A Slack communication channel.

send_text_message

async def send_text_message(recipient_id: Text, text: Text,
**kwargs: Any) -> None

Send text message to Slack API.

send_attachment

async def send_attachment(recipient_id: Text, attachment: Dict[Text, Any],
**kwargs: Any) -> None

Sends message with attachment.

SlackInput Objects

class SlackInput(InputChannel)

Slack input channel implementation. Based on the HTTPInputChannel.

__init__

def __init__(slack_token: Text,
slack_channel: Optional[Text] = None,
proxy: Optional[Text] = None,
slack_retry_reason_header: Optional[Text] = None,
slack_retry_number_header: Optional[Text] = None,
errors_ignore_retry: Optional[List[Text]] = None,
use_threads: Optional[bool] = False,
slack_signing_secret: Text = "",
conversation_granularity: Optional[Text] = "sender") -> None

Create a Slack input channel.

Needs a couple of settings to properly authenticate and validate messages. Details to setup:

https://github.com/slackapi/python-slackclient

Arguments:

  • slack_token - Your Slack Authentication token. You can create a Slack app and get your Bot User OAuth Access Token here <https://api.slack.com/slack-apps>_.
  • slack_channel - the string identifier for a channel to which the bot posts, or channel name (e.g. 'bot-test') If not set, messages will be sent back to the "App" DM channel of your bot's name.
  • proxy - A Proxy Server to route your traffic through
  • slack_retry_reason_header - Slack HTTP header name indicating reason that slack send retry request.
  • slack_retry_number_header - Slack HTTP header name indicating the attempt number.
  • errors_ignore_retry - Any error codes given by Slack included in this list will be ignored. Error codes are listed here <https://api.slack.com/events-api#errors>_.
  • use_threads - If set to here <https://api.slack.com/slack-apps>0, your bot will send responses in Slack as a threaded message. Responses will appear as a normal Slack message if set to here <https://api.slack.com/slack-apps>1.
  • here <https://api.slack.com/slack-apps>2 - Slack creates a unique string for your app and shares it with you. This allows us to verify requests from Slack with confidence by verifying signatures using your signing secret.
  • here <https://api.slack.com/slack-apps>3 - conversation granularity for slack conversations. sender allows 1 conversation per user (across channels) channel allows 1 conversation per user per channel thread allows 1 conversation per user per thread

process_message

async def process_message(request: Request,
on_new_message: Callable[[UserMessage],
Awaitable[Any]], text: Text,
sender_id: Optional[Text],
metadata: Optional[Dict]) -> Any

Slack retries to post messages up to 3 times based on failure conditions defined here: https://api.slack.com/events-api#failure_conditions.

get_metadata

def get_metadata(request: Request) -> Dict[Text, Any]

Extracts the metadata from a slack API event.

Slack Documentation: https://api.slack.com/types/event

Arguments:

  • request - A Request object that contains a slack API event in the body.

Returns:

Metadata extracted from the sent event payload. This includes the output channel for the response, and users that have installed the bot.

is_request_from_slack_authentic

def is_request_from_slack_authentic(request: Request) -> bool

Validate a request from Slack for its authenticity.

Checks if the signature matches the one we expect from Slack. Ensures we don't process request from a third-party disguising as slack.

Arguments:

  • request - incoming request to be checked

Returns:

True if the request came from Slack.