diff --git a/config/packages/bearclaw.yaml b/config/packages/bearclaw.yaml index 0d8bfd10..acc659aa 100644 --- a/config/packages/bearclaw.yaml +++ b/config/packages/bearclaw.yaml @@ -9,6 +9,7 @@ # Notes: Keep BearClaw transport + bridge logic centralized in this package. # Notes: Most BearClaw decision logic runs in docker_17/codex_appliance (server.js). # Notes: GitHub capture behavior (issue creation/labels/research flow) belongs in codex_appliance, not HA YAML. +# Notes: Telegram inline button callbacks are handled here and mapped to BearClaw commands. ###################################################################### rest_command: @@ -22,7 +23,8 @@ rest_command: { "text": {{ text | tojson }}, "user": {{ user | default('carlo') | tojson }}, - "source": {{ source | default('home_assistant') | tojson }} + "source": {{ source | default('home_assistant') | tojson }}, + "callback": {{ callback | default(none) | tojson }} } bearclaw_ingest: @@ -60,9 +62,14 @@ automation: - condition: template value_template: "{{ command_text == '' }}" sequence: - - service: script.joanna_send_telegram + - service: telegram_bot.send_message data: - message: "Usage: /bear " + target: !secret telegram_allowed_chat_id_carlo + message: "Choose a BearClaw action or send /bear ." + parse_mode: plain_text + disable_web_page_preview: true + inline_keyboard: + - "Status:/bear_status, Add to GitHub:/bear_github_help" default: - service: rest_command.bearclaw_command data: @@ -70,6 +77,109 @@ automation: user: "{{ from_user }}" source: telegram_command + - id: bearclaw_telegram_callback_actions + alias: BearClaw Telegram Callback Actions + description: Handles BearClaw Telegram inline button callbacks. + mode: queued + trigger: + - platform: event + event_type: telegram_callback + condition: + - condition: template + value_template: "{{ trigger.event.data.user_id is defined }}" + - condition: template + value_template: >- + {% set cb = trigger.event.data.data | default('') %} + {{ cb.startswith('/bear_') or cb.startswith('/bc_') }} + action: + - variables: + callback_id: "{{ trigger.event.data.id | default('') }}" + callback_data: "{{ trigger.event.data.data | default('') | trim }}" + from_user: "{{ (trigger.event.data.from_first | default('carlo')) | lower }}" + callback_payload: "{{ callback_data[6:] if callback_data.startswith('/bear_') else '' }}" + callback_parts: "{{ callback_payload.split('_') if callback_payload | length > 0 else [] }}" + action_name: "{{ callback_parts[0] if callback_parts | count > 0 else '' }}" + job_id: "{{ callback_parts[1:] | join('_') if callback_parts | count > 1 else '' }}" + - service: telegram_bot.answer_callback_query + continue_on_error: true + data: + callback_query_id: "{{ callback_id }}" + message: "Processing..." + show_alert: false + - choose: + - conditions: + - condition: template + value_template: "{{ callback_data.startswith('/bc_') }}" + sequence: + - service: rest_command.bearclaw_command + data: + text: "" + user: "{{ from_user }}" + source: telegram_callback + callback: + token: "{{ callback_data[4:] }}" + raw: "{{ callback_data }}" + chat_id: "{{ trigger.event.data.chat_id | default('') }}" + callback_id: "{{ callback_id }}" + message_id: "{{ trigger.event.data.message.message_id if trigger.event.data.message is defined and trigger.event.data.message.message_id is defined else '' }}" + - conditions: + - condition: template + value_template: "{{ action_name == 'status' }}" + sequence: + - service: rest_command.bearclaw_command + data: + text: "{{ 'status ' ~ job_id if job_id | length > 0 else 'status' }}" + user: "{{ from_user }}" + source: telegram_callback + - conditions: + - condition: template + value_template: "{{ action_name == 'cancel' and job_id | length > 0 }}" + sequence: + - service: rest_command.bearclaw_command + data: + text: "{{ 'cancel ' ~ job_id }}" + user: "{{ from_user }}" + source: telegram_callback + - conditions: + - condition: template + value_template: "{{ action_name == 'github_help' }}" + sequence: + - service: script.joanna_send_telegram + data: + message: >- + To create a GitHub capture, send: + add to github + Example: add to github Evaluate Smart Home Planner HACS app + - conditions: + - condition: template + value_template: "{{ action_name == 'yes' }}" + sequence: + - service: script.joanna_send_telegram + data: + message: "Great, I received your confirmation." + - conditions: + - condition: template + value_template: "{{ action_name == 'no' }}" + sequence: + - service: script.joanna_send_telegram + data: + message: "Understood. I did not get confirmation." + default: + - service: script.joanna_send_telegram + data: + message: "Unknown BearClaw button action. Try /bear to open the menu." + - choose: + - conditions: + - condition: template + value_template: "{{ trigger.event.data.message is defined and trigger.event.data.message.message_id is defined }}" + sequence: + - service: telegram_bot.edit_replymarkup + continue_on_error: true + data: + chat_id: "{{ trigger.event.data.chat_id }}" + message_id: "{{ trigger.event.data.message.message_id }}" + inline_keyboard: [] + - id: bearclaw_telegram_text_no_slash_needed alias: BearClaw Telegram Text No Slash Needed description: Treats plain Telegram text as BearClaw command input. @@ -108,9 +218,31 @@ automation: - variables: message: "{{ trigger.json.message | default('Joanna: empty reply') }}" level: "{{ trigger.json.level | default('active') | lower }}" - - service: script.joanna_send_telegram - data: - message: "{{ message }}" + inline_keyboard_payload: >- + {% set kb = trigger.json.inline_keyboard if trigger.json.inline_keyboard is defined else none %} + {% if kb is string %} + {{ kb | trim }} + {% elif kb is sequence and kb is not string and (kb | count) > 0 %} + {{ kb | map('string') | map('trim') | reject('equalto', '') | list | join('\n') }} + {% else %} + {{ '' }} + {% endif %} + - choose: + - conditions: + - condition: template + value_template: "{{ inline_keyboard_payload | length > 0 }}" + sequence: + - service: telegram_bot.send_message + data: + target: !secret telegram_allowed_chat_id_carlo + message: "{{ message }}" + parse_mode: plain_text + disable_web_page_preview: true + inline_keyboard: "{{ inline_keyboard_payload }}" + default: + - service: script.joanna_send_telegram + data: + message: "{{ message }}" - choose: - conditions: - condition: template diff --git a/config/shell_scripts/apt_reboot_report.service.sample b/config/shell_scripts/apt_reboot_report.service.sample deleted file mode 100644 index c503888c..00000000 --- a/config/shell_scripts/apt_reboot_report.service.sample +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Report boot completion for APT reboot tracking -After=network-online.target -Wants=network-online.target - -[Service] -Type=oneshot -ExecStart=/usr/local/sbin/apt_reboot_report.sh https://HOMEASSISTANT_HOST:8123/api/webhook/REPLACE_WITH_BOOT_WEBHOOK_ID docker_10 -User=root -Group=root - -[Install] -WantedBy=multi-user.target diff --git a/config/shell_scripts/apt_weekly.service.sample b/config/shell_scripts/apt_weekly.service.sample deleted file mode 100644 index 428ae3c7..00000000 --- a/config/shell_scripts/apt_weekly.service.sample +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Weekly APT maintenance (Home Assistant webhook) -After=network-online.target -Wants=network-online.target - -[Service] -Type=oneshot -ExecStart=/usr/local/sbin/apt_weekly.sh https://HOMEASSISTANT_HOST:8123/api/webhook/REPLACE_WITH_APT_WEBHOOK_ID docker_10 20 -User=root -Group=root -Nice=10 -IOSchedulingClass=best-effort -IOSchedulingPriority=7 - -[Install] -WantedBy=multi-user.target diff --git a/config/shell_scripts/apt_weekly.timer.sample b/config/shell_scripts/apt_weekly.timer.sample deleted file mode 100644 index 2e07756f..00000000 --- a/config/shell_scripts/apt_weekly.timer.sample +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Run APT maintenance weekly on Wednesday at 12:00 - -[Timer] -OnCalendar=Wed *-*-* 12:00:00 -Persistent=true - -[Install] -WantedBy=timers.target