Summarizes new customer email and logs the summary on the matching Odoo lead or opportunity.

UsesClaudeGmailOdoo

Summarize customer emails onto their Odoo record

Every hour, the recent mail in your Gmail inbox is read and each sender's address is looked up among the leads and opportunities in your Odoo CRM. When the address belongs to one, the AI writes a short note capturing what the email says, following the brief you give it, and the note is posted to that record's chatter. Mail from an address Odoo does not know is left completely alone.

You end up with a CRM that reflects the conversation without anyone copying it across by hand. No lead or opportunity is ever created, renamed or overwritten: the only thing written is a new chatter message on an existing record, so an unexpected match costs you a note you can delete rather than a bad record. An email with nothing worth recording is left unfiled. Each filed message gets a Gmail label and labeled mail is excluded from the next search, so the same email is never summarized twice; if the label cannot be applied the run says so and names the message.

Run every hour.Run every hour.
Set noteBrief to blank.Set noteBrief to blank.
Set filedLabel to “Filed to Odoo”.Set filedLabel to “Filed to Odoo”.
Set mailSearch to “newer_than:2d”.Set mailSearch to “newer_than:2d”.
Set maxEmails to 25.Set maxEmails to 25.
Set inboxQuery to “@mailSearch -label:“@filedLabel””.Set inboxQuery to “@mailSearch -label:“@filedLabel””.
GmailGmailList emails matching inboxQuery. Save it as inbox.List emails matching inboxQuery. Save it as inbox.
Set messages to inbox.emails.Set messages to inbox.emails.
Set filedCount to 0.Set filedCount to 0.
Set unmatchedCount to 0.Set unmatchedCount to 0.
For each email in messages:For each email in messages:
If a step below fails, save the error as emailErrorIf a step below fails, save the error as emailError
Try
Trim email.id and save it as messageId.Trim email.id and save it as messageId.
Trim email.from and save it as fromHeader.Trim email.from and save it as fromHeader.
Set senderAddress to fromHeader.Set senderAddress to fromHeader.
If fromHeader contains “<”If fromHeader contains “<”
Yes
Trim the first item of the last item of fromHeader split by “<” split by “>” and save it as senderAddress.Trim the first item of the last item of fromHeader split by “<” split by “>” and save it as senderAddress.
No
No steps
If senderAddress contains “@”If senderAddress contains “@”
Yes
OdooOdooSearch crm.lead records. Save it as found.Search crm.lead records. Save it as found.
Set matches to found.records.Set matches to found.records.
If matches isn't emptyIf matches isn't empty
Yes
Get the first item of matches and save it as record.Get the first item of matches and save it as record.
Set recordId to record.id.Set recordId to record.id.
Trim record.name and save it as recordName.Trim record.name and save it as recordName.
Trim email.subject and save it as subject.Trim email.subject and save it as subject.
Trim email.body and save it as emailBody.Trim email.body and save it as emailBody.
Set prompt to You are writing one short note for a CRM record about an email a customer has just sent.Set prompt to You are writing one short note for a CRM record about an email a customer has just sent. What the note should capture: noteBrief Rules: - Reply with the note text only. No greeting, no preamble, no sign-off, no heading. - Keep it under 120 words. - Say only what this email actually says. Do not guess at anything it does not state, and do not add advice. - If the email says nothing worth recording, reply with the single word none. CRM record: recordName From: senderAddress Subject: subject Email: emailBody.
ClaudeClaudeAsk Claude: prompt. Save it as written.Ask Claude: prompt. Save it as written. Maximum response length: 400
Trim written.response_text and save it as summary.Trim written.response_text and save it as summary.
If summary isn't empty and summary is not “none”If summary isn't empty and summary is not “none”
Yes
Set noteSubject to “Email from senderAddress”.Set noteSubject to “Email from senderAddress”.
If subject isn't emptyIf subject isn't empty
Yes
Change noteSubject to “Email: subject”.Change noteSubject to “Email: subject”.
No
No steps
Set noteBody to <p>summary with "Set noteBody to <p>summary with “ ” replaced by “<br/>”</p><p><i>Emailed by senderAddress &mdash; Gmail message messageId</i></p>.
OdooOdooCreate a mail.message record.Create a mail.message record.
Add 1 to filedCount.Add 1 to filedCount.
If a step below fails, save the error as labelErrorIf a step below fails, save the error as labelError
Try
GmailGmailAdd label filedLabel to email messageId.Add label filedLabel to email messageId.
On error
Show in the output: Filed a summary on '@recordName' but could not label Gmail message messageId, so the next run may file it again. Add the label by hand to stop that: filedLabel.Show in the output: Filed a summary on '@recordName' but could not label Gmail message messageId, so the next run may file it again. Add the label by hand to stop that: filedLabel.
No
Show in the output: Nothing worth recording in the email from senderAddress - left it unfiled.Show in the output: Nothing worth recording in the email from senderAddress - left it unfiled.
No
Add 1 to unmatchedCount.Add 1 to unmatchedCount.
Show in the output: No open Odoo lead or opportunity has the email senderAddress - nothing was created and the message was left unlabelled.Show in the output: No open Odoo lead or opportunity has the email senderAddress - nothing was created and the message was left unlabelled.
No
Show in the output: Could not read an email address out of the sender '@fromHeader' - skipped that message.Show in the output: Could not read an email address out of the sender '@fromHeader' - skipped that message.
On error
Show in the output: Could not file the email email.id as text: emailError as text.Show in the output: Could not file the email email.id as text: emailError as text.
Show in the output: Filed filedCount as text email summaries onto Odoo records; unmatchedCount as text sender(s) had no matching lead or opportunity.Show in the output: Filed filedCount as text email summaries onto Odoo records; unmatchedCount as text sender(s) had no matching lead or opportunity.