The Perry Webhook Addon is a custom Odoo module that listens to internal messages and triggers the AI processing pipeline. It ensures that Perry can "hear" and "respond" within Odoo’s native Discuss (chatter) interface without blocking the user experience.
The addon inherits from Odoo’s core messaging system (mail.message) to intercept communications. Its primary goal is to identify relevant messages in private chats and dispatch them to the Perry Ingest API for intelligent processing.
- Message Interception: Real-time monitoring of new messages created in the system.
- Intelligent Filtering: Ensuring Perry only responds to private chats where he is an active participant and ignoring his own automated replies.
- Asynchronous Dispatch: Utilizing background threading to call the AI engine, ensuring the Odoo UI remains responsive and the message input bar clears instantly.
- Response Integration: Receiving the AI's output and posting it back into the Odoo channel as a formal comment.
The module overrides the create method of the mail.message model. This is the entry point for every message sent in Odoo.
- Identity check: It searches for the internal "Perry" user via a hardcoded email (
perry@perry.com). - Constraint engine:
- Type: Only processes messages of type
comment. - Channel: Only triggers for
discuss.channelmodels of typechat(Direct Messages). - Participation: Only triggers if the "Perry" partner is a member of the specific channel.
- Anti-Recursion: Immediately ignores messages authored by Perry to avoid infinite loop conversations.
- Type: Only processes messages of type
Odoo typically operates in a synchronous request-response cycle. To prevent the user from waiting for the AI to "think," the addon spawns a Background Thread (send_webhook_threaded).
- Independent cursor: Because Odoo's database cursor is not thread-safe, the background process opens its own independent registry and cursor to interact with the database.
- Daemon threading: Uses
threading.Thread(daemon=True)to ensure the process doesn't hang the main server process on shutdown.
The background function performs a POST request to the AI Ingest API.
- Endpoint:
http://ingest-api-api-1:8000/clean/odoo - Payload: Includes the
session_id(Odoo Channel ID) and the message body/metadata. - Persistence: Upon receiving a successful (200 OK) response, it uses
Markupto ensure safe HTML rendering and callschannel.message_post()followed by a manualenv.cr.commit()to persist the AI's response.
- User sends message: The user types a message in an Odoo chat with Perry.
- Hook triggered:
MailMessage.create()intercepts the data. - Validation: The module confirms Perry is a participant and it's a private chat.
- Thread spawning: A background thread is kicked off with a 120s timeout.
- UI feedback: The user sees their message posted instantly; the input box clears.
- AI processing: The thread calls the FastAPI engine.
- Injection: The thread receives Perry's response and injects it back into the Odoo channel.
The addon is instrumented with Logfire to track the lifecycle of a message from the Odoo side:
- Spans: Captures the initial hook (
mail.message create hook) and the background API call (Send Odoo webhook to FastAPI). - Detailed Logging:
Odoo mail messages created: Tracks volume.Private chat message detected: Logs intent identification.FastAPI webhook response received: Tracks status codes and latency.Odoo channel response committed: Confirms the final delivery of Perry's reply.