From 8522061e956f0e535f62980020480ec56bed781e Mon Sep 17 00:00:00 2001 From: David Grieser Date: Wed, 24 Jun 2026 06:13:48 +0200 Subject: [PATCH 01/42] feat(bot): add rule engine with schedule and interactive buttons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduced trigger, condition, and action concepts for configs, defaulting to classic message behavior. - Added support for schedule triggers (cron) with timezone handling and button timeout functionality. - Implemented Outlook calendar condition stub with environment‑based event source. - Expanded configuration schema with new fields: trigger, schedule_cron, schedule_timezone, condition, condition_negate, outlook patterns, action, action_target, buttons, button_timeout, button_timeout_target. - Added commands to set triggers, cron expressions, timezones, conditions, outlook patterns, actions, targets, button management, and immediate run. - Implemented interactive button blocks, pending button tracking, timeout handling, and persistence cache. - Developed scheduler to evaluate cron schedules, respect conditions, and execute actions. - Updated README with usage details for the new features. - Modified Helm chart deployment to expose new cache files via environment variables. - Updated requirements to include `croniter` and added new `outlook.py` stub module. - Extended tests to cover new setters, condition evaluation, actions, button handling, and scheduler behavior. --- README.md | 47 +- bot.py | 687 +++++++++++++++++++++++- charts/hutbot/templates/deployment.yaml | 4 + outlook.py | 64 +++ requirements.txt | 3 +- test_bot.py | 316 +++++++++++ 6 files changed, 1111 insertions(+), 10 deletions(-) create mode 100644 outlook.py diff --git a/README.md b/README.md index 6a27b4c..37c8ae0 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,42 @@ Opsgenie alert priority defaults to `P4` and can be configured per channel confi /hutbot [config] set opsgenie-priority ``` +## Triggers, conditions, and actions + +Beyond the classic "reply if a message goes unanswered" behavior, each named config is a **rule** +with a `trigger`, an optional `condition`, and an `action`. The trigger defaults to `message`, so +existing configs keep working unchanged. + +- **Triggers** (`/hutbot [config] set trigger `) + - `message` — the classic behavior (matches channel messages by pattern/teams/hours). + - `schedule` — fires on a cron schedule. Set it with `set cron ""` (5-field cron, e.g. + `0 9 * * 1-5`) and optionally `set schedule-timezone `. + - `manual` — never fires on its own; used as the target of a button or a button timeout. + +- **Conditions** (`/hutbot [config] set condition `) gate a `schedule` trigger. + - `outlook` — matches Outlook calendar entries by `set outlook-subject ` / + `set outlook-body `. Use `enable negate` to fire when *no* matching entry exists. + **Note:** the Outlook integration is currently a stub (events come from the + `HUTBOT_OUTLOOK_STUB_EVENTS` env var); the real implementation lands in a later task. + +- **Actions** (`/hutbot [config] set action `) decide what the + rule does, using `reply_message` (with the usual `{{variables}}`) as the body. + - `reply` — post in the rule's channel. + - `dm-user` — DM a single user. Set the recipient with `set target <@user>`. + - `group-dm` — open one group DM (mpim) with all members of a Slack user group and post once. + Set the group with `set target <@usergroup>` (Slack caps a group DM at 8 members). + - `post-channel` — post to another channel. Set it with `set target <#channel>`. + +- **Buttons** attach interactive buttons to the message a rule sends: + - `/hutbot [config] add button "