1313# Notes: Telegram inline button callbacks are handled here and mapped to BearClaw commands.
1414# Notes: Inbound Telegram handling enforces user_id + chat_id allowlists from secrets CSV values.
1515# Notes: Reply webhook writes JOANNA activity entries to logbook for traceability.
16+ # Notes: Non-urgent autonomous Joanna Telegram replies are suppressed during quiet hours (23:00-08:00) unless the appliance marks `quiet_hours_bypass`; urgent levels and Telegram-initiated conversations still deliver immediately.
1617# Notes: Status telemetry polling expects !secret bearclaw_status_url (token header stays !secret bearclaw_token).
1718# Notes: Nightly Duplicati verification calls a codex_appliance admin endpoint and returns structured health to HA via response_variable.
1819# Notes: Telegram freeform input now includes LLM-first routing context to improve intent understanding before entity lookups.
@@ -501,6 +502,17 @@ automation:
501502 {% endif %}
502503 telegram_disable_preview : " {{ trigger.json.disable_web_page_preview | default(true, true) }}"
503504 level : " {{ trigger.json.level | default('active') | lower }}"
505+ reply_source : " {{ trigger.json.source | default('', true) | string | lower | trim }}"
506+ quiet_hours_bypass : >-
507+ {{ trigger.json.quiet_hours_bypass | default(false, true) in [true, 'true', 'True', 'on', 'yes', 1, '1'] }}
508+ quiet_hours_active : >-
509+ {% set now_time = now().strftime('%H:%M:%S') %}
510+ {{ now_time >= '23:00:00' or now_time < '08:00:00' }}
511+ should_send_telegram : >-
512+ {% set user_initiated = reply_source in ['telegram_command', 'telegram_callback', 'telegram_text'] %}
513+ {% set urgent = level in ['warning', 'error', 'critical'] %}
514+ {% set quiet = quiet_hours_active in [true, 'true', 'True', 'on', 'yes', 1, '1'] %}
515+ {{ quiet_hours_bypass or user_initiated or urgent or not quiet }}
504516 inline_keyboard_payload : >-
505517 {% set kb = trigger.json.inline_keyboard if trigger.json.inline_keyboard is defined else none %}
506518 {% if kb is string %}
@@ -519,6 +531,8 @@ automation:
519531 {% endif %}
520532 - choose :
521533 - conditions :
534+ - condition : template
535+ value_template : " {{ should_send_telegram }}"
522536 - condition : template
523537 value_template : " {{ inline_keyboard_payload | length > 0 }}"
524538 sequence :
@@ -529,12 +543,15 @@ automation:
529543 parse_mode : " {{ telegram_parse_mode }}"
530544 disable_web_page_preview : " {{ telegram_disable_preview }}"
531545 inline_keyboard : " {{ inline_keyboard_payload }}"
532- default :
533- - service : script.joanna_send_telegram
534- data :
535- message : " {{ telegram_message }}"
536- parse_mode : " {{ telegram_parse_mode }}"
537- disable_web_page_preview : " {{ telegram_disable_preview }}"
546+ - conditions :
547+ - condition : template
548+ value_template : " {{ should_send_telegram }}"
549+ sequence :
550+ - service : script.joanna_send_telegram
551+ data :
552+ message : " {{ telegram_message }}"
553+ parse_mode : " {{ telegram_parse_mode }}"
554+ disable_web_page_preview : " {{ telegram_disable_preview }}"
538555 - service : script.send_to_logbook
539556 data :
540557 topic : JOANNA
0 commit comments