Skip to content

Commit fd874fb

Browse files
committed
Enhance BearClaw Telegram integration by adding callback handling for inline button actions. Updated automation sequences for improved message delivery and user interaction. Removed deprecated APT service and timer sample scripts to streamline configuration.
1 parent 09ad097 commit fd874fb

File tree

4 files changed

+138
-44
lines changed

4 files changed

+138
-44
lines changed

config/packages/bearclaw.yaml

Lines changed: 138 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Notes: Keep BearClaw transport + bridge logic centralized in this package.
1010
# Notes: Most BearClaw decision logic runs in docker_17/codex_appliance (server.js).
1111
# Notes: GitHub capture behavior (issue creation/labels/research flow) belongs in codex_appliance, not HA YAML.
12+
# Notes: Telegram inline button callbacks are handled here and mapped to BearClaw commands.
1213
######################################################################
1314

1415
rest_command:
@@ -22,7 +23,8 @@ rest_command:
2223
{
2324
"text": {{ text | tojson }},
2425
"user": {{ user | default('carlo') | tojson }},
25-
"source": {{ source | default('home_assistant') | tojson }}
26+
"source": {{ source | default('home_assistant') | tojson }},
27+
"callback": {{ callback | default(none) | tojson }}
2628
}
2729
2830
bearclaw_ingest:
@@ -60,16 +62,124 @@ automation:
6062
- condition: template
6163
value_template: "{{ command_text == '' }}"
6264
sequence:
63-
- service: script.joanna_send_telegram
65+
- service: telegram_bot.send_message
6466
data:
65-
message: "Usage: /bear <message>"
67+
target: !secret telegram_allowed_chat_id_carlo
68+
message: "Choose a BearClaw action or send /bear <message>."
69+
parse_mode: plain_text
70+
disable_web_page_preview: true
71+
inline_keyboard:
72+
- "Status:/bear_status, Add to GitHub:/bear_github_help"
6673
default:
6774
- service: rest_command.bearclaw_command
6875
data:
6976
text: "{{ command_text }}"
7077
user: "{{ from_user }}"
7178
source: telegram_command
7279

80+
- id: bearclaw_telegram_callback_actions
81+
alias: BearClaw Telegram Callback Actions
82+
description: Handles BearClaw Telegram inline button callbacks.
83+
mode: queued
84+
trigger:
85+
- platform: event
86+
event_type: telegram_callback
87+
condition:
88+
- condition: template
89+
value_template: "{{ trigger.event.data.user_id is defined }}"
90+
- condition: template
91+
value_template: >-
92+
{% set cb = trigger.event.data.data | default('') %}
93+
{{ cb.startswith('/bear_') or cb.startswith('/bc_') }}
94+
action:
95+
- variables:
96+
callback_id: "{{ trigger.event.data.id | default('') }}"
97+
callback_data: "{{ trigger.event.data.data | default('') | trim }}"
98+
from_user: "{{ (trigger.event.data.from_first | default('carlo')) | lower }}"
99+
callback_payload: "{{ callback_data[6:] if callback_data.startswith('/bear_') else '' }}"
100+
callback_parts: "{{ callback_payload.split('_') if callback_payload | length > 0 else [] }}"
101+
action_name: "{{ callback_parts[0] if callback_parts | count > 0 else '' }}"
102+
job_id: "{{ callback_parts[1:] | join('_') if callback_parts | count > 1 else '' }}"
103+
- service: telegram_bot.answer_callback_query
104+
continue_on_error: true
105+
data:
106+
callback_query_id: "{{ callback_id }}"
107+
message: "Processing..."
108+
show_alert: false
109+
- choose:
110+
- conditions:
111+
- condition: template
112+
value_template: "{{ callback_data.startswith('/bc_') }}"
113+
sequence:
114+
- service: rest_command.bearclaw_command
115+
data:
116+
text: ""
117+
user: "{{ from_user }}"
118+
source: telegram_callback
119+
callback:
120+
token: "{{ callback_data[4:] }}"
121+
raw: "{{ callback_data }}"
122+
chat_id: "{{ trigger.event.data.chat_id | default('') }}"
123+
callback_id: "{{ callback_id }}"
124+
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 '' }}"
125+
- conditions:
126+
- condition: template
127+
value_template: "{{ action_name == 'status' }}"
128+
sequence:
129+
- service: rest_command.bearclaw_command
130+
data:
131+
text: "{{ 'status ' ~ job_id if job_id | length > 0 else 'status' }}"
132+
user: "{{ from_user }}"
133+
source: telegram_callback
134+
- conditions:
135+
- condition: template
136+
value_template: "{{ action_name == 'cancel' and job_id | length > 0 }}"
137+
sequence:
138+
- service: rest_command.bearclaw_command
139+
data:
140+
text: "{{ 'cancel ' ~ job_id }}"
141+
user: "{{ from_user }}"
142+
source: telegram_callback
143+
- conditions:
144+
- condition: template
145+
value_template: "{{ action_name == 'github_help' }}"
146+
sequence:
147+
- service: script.joanna_send_telegram
148+
data:
149+
message: >-
150+
To create a GitHub capture, send:
151+
add to github <short topic>
152+
Example: add to github Evaluate Smart Home Planner HACS app
153+
- conditions:
154+
- condition: template
155+
value_template: "{{ action_name == 'yes' }}"
156+
sequence:
157+
- service: script.joanna_send_telegram
158+
data:
159+
message: "Great, I received your confirmation."
160+
- conditions:
161+
- condition: template
162+
value_template: "{{ action_name == 'no' }}"
163+
sequence:
164+
- service: script.joanna_send_telegram
165+
data:
166+
message: "Understood. I did not get confirmation."
167+
default:
168+
- service: script.joanna_send_telegram
169+
data:
170+
message: "Unknown BearClaw button action. Try /bear to open the menu."
171+
- choose:
172+
- conditions:
173+
- condition: template
174+
value_template: "{{ trigger.event.data.message is defined and trigger.event.data.message.message_id is defined }}"
175+
sequence:
176+
- service: telegram_bot.edit_replymarkup
177+
continue_on_error: true
178+
data:
179+
chat_id: "{{ trigger.event.data.chat_id }}"
180+
message_id: "{{ trigger.event.data.message.message_id }}"
181+
inline_keyboard: []
182+
73183
- id: bearclaw_telegram_text_no_slash_needed
74184
alias: BearClaw Telegram Text No Slash Needed
75185
description: Treats plain Telegram text as BearClaw command input.
@@ -108,9 +218,31 @@ automation:
108218
- variables:
109219
message: "{{ trigger.json.message | default('Joanna: empty reply') }}"
110220
level: "{{ trigger.json.level | default('active') | lower }}"
111-
- service: script.joanna_send_telegram
112-
data:
113-
message: "{{ message }}"
221+
inline_keyboard_payload: >-
222+
{% set kb = trigger.json.inline_keyboard if trigger.json.inline_keyboard is defined else none %}
223+
{% if kb is string %}
224+
{{ kb | trim }}
225+
{% elif kb is sequence and kb is not string and (kb | count) > 0 %}
226+
{{ kb | map('string') | map('trim') | reject('equalto', '') | list | join('\n') }}
227+
{% else %}
228+
{{ '' }}
229+
{% endif %}
230+
- choose:
231+
- conditions:
232+
- condition: template
233+
value_template: "{{ inline_keyboard_payload | length > 0 }}"
234+
sequence:
235+
- service: telegram_bot.send_message
236+
data:
237+
target: !secret telegram_allowed_chat_id_carlo
238+
message: "{{ message }}"
239+
parse_mode: plain_text
240+
disable_web_page_preview: true
241+
inline_keyboard: "{{ inline_keyboard_payload }}"
242+
default:
243+
- service: script.joanna_send_telegram
244+
data:
245+
message: "{{ message }}"
114246
- choose:
115247
- conditions:
116248
- condition: template

config/shell_scripts/apt_reboot_report.service.sample

Lines changed: 0 additions & 13 deletions
This file was deleted.

config/shell_scripts/apt_weekly.service.sample

Lines changed: 0 additions & 16 deletions
This file was deleted.

config/shell_scripts/apt_weekly.timer.sample

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)