dm_mac.slack_handler module

class dm_mac.slack_handler.Message(text: str, user_id: str, user_name: str, user_handle: str, channel_id: str, channel_name: str)

Bases: object

Represent an incoming message.

property as_dict: Dict[str, Any]
class dm_mac.slack_handler.SlackHandler(quart_app: Quart)

Bases: object

Handle Slack integration.

HELP_RESPONSE: str = 'Hi, I\'m the Machine Access Control slack bot.\nMention my username followed by one of these commands:\n"status" - list all machines and their status\n"oops <machine name>" - set Oops state on this machine immediately\n"lock <machine name>" - set maintenance lockout on this machine\n"clear <machine name>" - clear oops and/or maintenance lockout on this machine\n\nI am Free and Open Source software:\nhttps://github.com/jantman/machine-access-control'
async admin_log(message: str) None

Log a string to the admin channel only.

This uses asyncio.create_task() to fire-and-forget the Slack postMessage call, so that we don’t block on communication with Slack. Otherwise, updates to the relay/LCD/LED would be delayed by at least the timeout trying to post to Slack.

async app_mention(body: Dict[str, Any], say: AsyncSay) None

Handle an at-mention of our app in Slack.

Body is a dict with string keys, which is documented at <https://api.slack.com/events/app_mention>. The important bits are in the event nested dict.

The parts of the event dict within body that are of interest to us are:

  • user - the user ID (string beginning with “U”) of the person who mentioned us.

  • text - the string text of the message that mentioned us.

  • channel - the channel ID (string beginning with “C”) of the channel that the message was in.

async clear(msg: Message, say: AsyncSay) None

Clear oops and lock status on a machine.

async handle_command(msg: Message, say: AsyncSay) None

Handle a command sent to the bot.

async lock(msg: Message, say: AsyncSay) None

Set lock status on a machine.

async log_lock(machine: Machine, source: str) None

Log when a machine is locked.

This uses asyncio.create_task() to fire-and-forget the Slack postMessage call, so that we don’t block on communication with Slack. Otherwise, updates to the relay/LCD/LED would be delayed by at least the timeout trying to post to Slack.

async log_oops(machine: Machine, source: str, user_name: str | None = 'unknown user') None

Log when a machine is oopsed.

This uses asyncio.create_task() to fire-and-forget the Slack postMessage call, so that we don’t block on communication with Slack. Otherwise, updates to the relay/LCD/LED would be delayed by at least the timeout trying to post to Slack.

async log_unlock(machine: Machine, source: str) None

Log when a machine is un-locked.

This uses asyncio.create_task() to fire-and-forget the Slack postMessage call, so that we don’t block on communication with Slack. Otherwise, updates to the relay/LCD/LED would be delayed by at least the timeout trying to post to Slack.

async log_unoops(machine: Machine, source: str) None

Log when a machine is un-oopsed.

This uses asyncio.create_task() to fire-and-forget the Slack postMessage call, so that we don’t block on communication with Slack. Otherwise, updates to the relay/LCD/LED would be delayed by at least the timeout trying to post to Slack.

async machine_status(say: AsyncSay) None

Respond with machine status.

async oops(msg: Message, say: AsyncSay) None

Set oops status on a machine.