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

UsesClaudeGmailOdoo

Summarise customer emails onto their Odoo record

ScheduleRun every hour.Run every hour.
ValuesSet noteBrief to blank.Set noteBrief to blank.
ValuesSet filedLabel to Filed to Odoo.Set filedLabel to Filed to Odoo.
ValuesSet mailSearch to newer_than:2d.Set mailSearch to newer_than:2d.
ValuesSet maxEmails to 25.Set maxEmails to 25.
ValuesSet 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.
ValuesSet messages to inbox.emails.Set messages to inbox.emails.
ValuesSet filedCount to 0.Set filedCount to 0.
ValuesSet unmatchedCount to 0.Set unmatchedCount to 0.
Decisions & LoopsFor each email in messages:For each email in messages:
Decisions & LoopsIf a step below fails, save the error as emailErrorIf a step below fails, save the error as emailError
Try
TextTrim email.id and save it as messageId.Trim email.id and save it as messageId.
TextTrim email.from and save it as fromHeader.Trim email.from and save it as fromHeader.
ValuesSet senderAddress to fromHeader.Set senderAddress to fromHeader.
Decisions & LoopsIf fromHeader contains <If fromHeader contains <
Yes
TextTrim 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
Decisions & LoopsIf senderAddress contains @If senderAddress contains @
Yes
OdooOdooSearch crm.lead records. Save it as found.Search crm.lead records. Save it as found.
ValuesSet matches to found.records.Set matches to found.records.
Decisions & LoopsIf matches isn't emptyIf matches isn't empty
Yes
ListsGet the first item of matches and save it as record.Get the first item of matches and save it as record.
ValuesSet recordId to record.id.Set recordId to record.id.
TextTrim record.name and save it as recordName.Trim record.name and save it as recordName.
TextTrim email.subject and save it as subject.Trim email.subject and save it as subject.
TextTrim email.body and save it as emailBody.Trim email.body and save it as emailBody.
ValuesSet 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
TextTrim written.response_text and save it as summary.Trim written.response_text and save it as summary.
Decisions & LoopsIf summary isn't empty and summary is not noneIf summary isn't empty and summary is not none
Yes
ValuesSet noteSubject to Email from senderAddress.Set noteSubject to Email from senderAddress.
Decisions & LoopsIf subject isn't emptyIf subject isn't empty
Yes
ValuesChange noteSubject to Email: subject.Change noteSubject to Email: subject.
No
No steps
ValuesSet 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.
ValuesAdd 1 to filedCount.Add 1 to filedCount.
Decisions & LoopsIf 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
ValuesShow 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
ValuesShow 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
ValuesAdd 1 to unmatchedCount.Add 1 to unmatchedCount.
ValuesShow 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
ValuesShow 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
ValuesShow 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.
ValuesShow 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.