Souscrire au topic agents/register : notification XMPP à chaque agent en ligne
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -133,6 +133,24 @@ def on_mqtt_notification(client, userdata, msg):
|
||||
except Exception as e:
|
||||
print("[MQTT] Erreur parsing notification scheduler : {}".format(e))
|
||||
|
||||
def on_mqtt_register(client, userdata, msg):
|
||||
"""Reçoit les déclarations de mise en ligne des agents."""
|
||||
try:
|
||||
data = json.loads(msg.payload.decode(errors="replace"))
|
||||
agent = data.get("agent", "?")
|
||||
jid = data.get("jid", "?")
|
||||
mqtt_inbox = data.get("mqtt_inbox", "?")
|
||||
speciality = data.get("speciality", "")
|
||||
print("[REGISTER] {} en ligne (JID: {}, inbox: {})".format(agent, jid, mqtt_inbox))
|
||||
# Notifier sylvain via XMPP
|
||||
if xmpp_bot:
|
||||
notif = "[EN LIGNE] {}\n JID : {}\n MQTT : {}".format(agent, jid, mqtt_inbox)
|
||||
if speciality:
|
||||
notif += "\n Rôle : {}".format(speciality)
|
||||
xmpp_bot.send_message(mto=ADMIN_JID, mbody=notif, mtype='chat')
|
||||
except Exception as e:
|
||||
print("[MQTT] Erreur parsing register : {}".format(e))
|
||||
|
||||
def start_mqtt_listener():
|
||||
global mqtt_pub_client
|
||||
|
||||
@@ -145,14 +163,16 @@ def start_mqtt_listener():
|
||||
sub.message_callback_add("agents/agent1/inbox", on_mqtt_message)
|
||||
sub.message_callback_add("agents/errors", on_mqtt_error)
|
||||
sub.message_callback_add("agents/scheduler/notifications", on_mqtt_notification)
|
||||
sub.message_callback_add("agents/register", on_mqtt_register)
|
||||
sub.on_message = on_mqtt_message # fallback
|
||||
sub.connect(MQTT_HOST, MQTT_PORT)
|
||||
sub.subscribe([
|
||||
(MQTT_INBOX, 0),
|
||||
("agents/errors", 0),
|
||||
("agents/scheduler/notifications", 0),
|
||||
("agents/register", 0),
|
||||
])
|
||||
print("[MQTT] Agent1 écoute sur {}, agents/errors, agents/scheduler/notifications".format(MQTT_INBOX))
|
||||
print("[MQTT] Agent1 écoute sur {}, agents/errors, agents/scheduler/notifications, agents/register".format(MQTT_INBOX))
|
||||
sub.loop_forever()
|
||||
|
||||
# ── BOT XMPP ─────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user