From 5e9b4b244c859a630c5dc8cfd83b782d3ac8aecb Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Sat, 25 Apr 2026 17:05:55 -0400 Subject: [PATCH] feat(addon): show AI bot online in Discuss when agent is healthy Extend cron_ping_all to upsert a bus.presence row for the activeblue_ai_bot user, mirroring the agent service's reachability: green dot when /health responds 200, offline otherwise. Drop the cron interval from 5m to 1m so the presence stays fresh (Odoo's presence client expects refreshes well under a minute). --- addons/activeblue_ai/data/ir_cron.xml | 2 +- addons/activeblue_ai/models/ab_ai_bot.py | 25 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/activeblue_ai/data/ir_cron.xml b/addons/activeblue_ai/data/ir_cron.xml index 757bb4f..4c2bf16 100644 --- a/addons/activeblue_ai/data/ir_cron.xml +++ b/addons/activeblue_ai/data/ir_cron.xml @@ -6,7 +6,7 @@ code model.cron_ping_all() - 5 + 1 minutes True diff --git a/addons/activeblue_ai/models/ab_ai_bot.py b/addons/activeblue_ai/models/ab_ai_bot.py index 3bfc2f7..20c373c 100644 --- a/addons/activeblue_ai/models/ab_ai_bot.py +++ b/addons/activeblue_ai/models/ab_ai_bot.py @@ -95,8 +95,33 @@ class AbAiBot(models.Model): @api.model def cron_ping_all(self): + any_online = False for bot in self.search([('active', '=', True)]): try: bot.action_ping() + if bot.status == 'online': + any_online = True except Exception as exc: _logger.warning('Ping failed for bot %s: %s', bot.id, exc) + # Mirror agent-service health to the bot user's Discuss presence so it + # shows a green dot when the agent is reachable. + self._sync_bot_user_presence(online=any_online) + + @api.model + def _sync_bot_user_presence(self, online): + bot_user = self.env['res.users'].sudo().search( + [('login', 'in', ('activeblue_ai_bot', 'activeblue_ai_bot@local'))], limit=1) + if not bot_user: + return + Presence = self.env.get('bus.presence') + if Presence is None: + return + status = 'online' if online else 'offline' + now = fields.Datetime.now() + rec = Presence.sudo().search([('user_id', '=', bot_user.id)], limit=1) + vals = {'status': status, 'last_poll': now, 'last_presence': now} + if rec: + rec.write(vals) + else: + vals['user_id'] = bot_user.id + Presence.sudo().create(vals)