xtr_slack_notifier ¶
Slack for xtr-notifier: chat messages posted, scheduled and updated in a channel.
Install it beside xtr-notifier and a slack://TOKEN@default?channel=CHANNEL DSN is
served by :class:SlackTransportFactory with no wiring. Build a message's options with
:class:SlackOptions and the blocks of :mod:.block; update a posted message through
the :class:SlackSentMessage the transport returns.
SlackOptions ¶
Bases: MessageOptionsInterface
The options of a Slack message, one fluent call at a time.
Each method sets a field of chat.postMessage, and :meth:to_options
renders them, in the order they were set, as the
:class:~xtr_notifier.message.MessageOptions a message carries. Setting
post_at schedules the message instead of posting it.
Not final: :class:~xtr_slack_notifier.UpdateMessageSlackOptions renders
the same fields as an update of a message already posted.
Start from options, the Web API's fields, plus recipient_id for the channel.
Raises:
-
LogicError–When
optionsholds more than 50 blocks.
recipient_id
property
¶
The channel the message goes to, or None for the transport's channel.
from_notification
classmethod
¶
Render notification: its emoji as the icon, its subject, content and exception.
The exception's traceback follows a divider, as a section of its own.
to_options ¶
Render the fields set so far — a copy, so later calls do not change it.
recipient ¶
Post to the channel or user recipient_id rather than the transport's channel.
post_at ¶
Schedule the message for timestamp instead of posting it now.
block ¶
thread_ts ¶
Reply in the thread of the message posted at thread_ts.
SlackSentMessage ¶
Bases: SentMessage
A posted message, with the channel and the ts that identify it for an update.
Record original, posted through transport to channel_id at message_id.
SlackTransport ¶
SlackTransport(access_token: str, channel: str | None, http_client: HttpClientInterface, event_dispatcher: EventDispatcherInterface | None = None)
Bases: AbstractTransport
Posts, schedules and updates messages through Slack's Web API.
The channel a message goes to is the one its options name, else its
recipient, else the channel the transport was built with. A message made
from a notification and carrying no options is rendered by
:meth:SlackOptions.from_notification. Options of the slack.update
kind call chat.update; a post_at field calls
chat.scheduleMessage; anything else chat.postMessage.
Post with access_token to channel unless a message names its own.
Parameters:
-
access_token(str) –A bot (
xoxb-), user (xoxp-) or app (xoxa-2) token; never shown. -
channel(str | None) –The channel posted to when a message names none, or
None. -
http_client(HttpClientInterface) –What the Web API is reached through.
-
event_dispatcher(EventDispatcherInterface | None, default:None) –Where the message events go;
Noneannounces nothing.
Raises:
-
InvalidArgumentError–When the token is not of a kind Slack issues.
supports ¶
Send chat messages carrying no options, Slack's, or Slack update options.
SlackTransportFactory ¶
SlackTransportFactory(http_client: HttpClientInterface, event_dispatcher: EventDispatcherInterface | None = None)
Bases: AbstractTransportFactory
Builds a :class:SlackTransport from slack://TOKEN@default?channel=CHANNEL.
default stands for slack.com; channel is the channel posted to
when a message names none; ssl=false reaches the host over plain HTTP.
create ¶
Build the transport dsn describes.
Raises:
-
UnsupportedSchemeError–If the scheme is not
slack. -
IncompleteDsnError–If the DSN carries no token.
-
InvalidArgumentError–If the token is not of a kind Slack issues, or
sslis not a boolean.
UpdateMessageSlackOptions ¶
UpdateMessageSlackOptions(channel_id: str, message_id: str, options: Mapping[str, object] | None = None)
Bases: SlackOptions
The options of an update to the message posted at ts in a channel.
They render with the kind slack.update: once rendered, options are
plain data that can cross a message bus, so the kind — not the builder's
class — is what tells the transport to call chat.update.
Update the message message_id (its ts) in channel_id, with options.