diff --git a/backend/open_webui/tools/builtin.py b/backend/open_webui/tools/builtin.py index ade93a9b3a..5c2fb3425a 100644 --- a/backend/open_webui/tools/builtin.py +++ b/backend/open_webui/tools/builtin.py @@ -4697,6 +4697,7 @@ async def update_automation( new_triggers = triggers + [t for t in new_triggers if t['type'] == 'webhook'] new_action = automation.data['action'] + chat_id = None if action is not None: action = TypeAdapter(AutomationActionForm).validate_python( action.model_dump(exclude_unset=True) if isinstance(action, BaseModel) else action @@ -4714,6 +4715,8 @@ async def update_automation( } if action.type == 'code' and 'args' not in action.model_fields_set: new_action['args'] = old.get('args') + if 'new_chat' in action.model_fields_set: + chat_id = (built['target'] or {}).get('chat_id') try: expires = automation.expires_at if expires_at is None else parse_timer_at(expires_at) if expires_at else None @@ -4734,6 +4737,10 @@ async def update_automation( except HTTPException as e: return JSONCodec.dumps({'error': e.detail}) updated = await Automations.update_by_id(automation_id, form, next_run) + if chat_id: + # A save keeps the chat the runner last used; point it at the one this was asked from. + await Automations.set_target_ref(automation_id, 'chat_id', chat_id) + updated = await Automations.get_by_id(automation_id) if next_run_at: try: await Automations.update_state_by_id(