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)