Reads every document that arrives by email, logs a short summary of each in a Google Doc and emails you what came in.

UsesGmailGoogle DocsOpenAI

Summarise the documents people email you

GmailGmailWhen an email arrives.When an email arrives.
ValuesSet documentSearch to blank.Set documentSearch to blank.
ValuesSet logDocumentUrl to blank.Set logDocumentUrl to blank.
ValuesSet notifyEmail to blank.Set notifyEmail to blank.
ValuesSet processedLabel to Document summaries.Set processedLabel to Document summaries.
ValuesSet maxDocumentsPerRun to 5.Set maxDocumentsPerRun to 5.
MathSet documentCap to maxDocumentsPerRun multiplied by 1.Set documentCap to maxDocumentsPerRun multiplied by 1.
Decisions & LoopsIf documentCap is greater than 25If documentCap is greater than 25
Yes
Decisions & LoopsStop and report a problem: The 'maxDocumentsPerRun' step needs a whole number between 1 and 25 - it is how many documents one run is allowed to handle.Stop and report a problem: The 'maxDocumentsPerRun' step needs a whole number between 1 and 25 - it is how many documents one run is allowed to handle.
No
No steps
Decisions & LoopsIf documentCap is less than 1If documentCap is less than 1
Yes
Decisions & LoopsStop and report a problem: The 'maxDocumentsPerRun' step needs a whole number between 1 and 25 - it is how many documents one run is allowed to handle.Stop and report a problem: The 'maxDocumentsPerRun' step needs a whole number between 1 and 25 - it is how many documents one run is allowed to handle.
No
No steps
ValuesSet logDocumentId to blank.Set logDocumentId to blank.
Decisions & LoopsIf logDocumentUrl contains /d/ (ignoring case)If logDocumentUrl contains /d/ (ignoring case)
Yes
TextTrim the first item of the last item of logDocumentUrl split by /d/ split by / and save it as logDocumentId.Trim the first item of the last item of logDocumentUrl split by /d/ split by / and save it as logDocumentId.
No
No steps
Decisions & LoopsIf logDocumentId is emptyIf logDocumentId is empty
Yes
Decisions & LoopsStop and report a problem: The 'logDocumentUrl' step needs the address of a Google Doc - open the document and copy the address bar, which contains '/d/'.Stop and report a problem: The 'logDocumentUrl' step needs the address of a Google Doc - open the document and copy the address bar, which contains '/d/'.
No
No steps
GmailGmailList emails matching '@documentSearch has:attachment -label:@processedLabel'. Save it as found.List emails matching '@documentSearch has:attachment -label:@processedLabel'. Save it as found.
ValuesSet summarisedCount to 0.Set summarisedCount to 0.
ValuesSet digestLines to an empty list.Set digestLines to an empty list.
Decisions & LoopsFor each message in found.emails:For each message in found.emails:
Decisions & LoopsIf summarisedCount is greater than or equal to documentCapIf summarisedCount is greater than or equal to documentCap
Yes
Decisions & LoopsStop repeating.Stop repeating.
No
No steps
Decisions & LoopsIf a step below fails, save the error as messageErrorIf a step below fails, save the error as messageError
Try
ValuesSet messageId to blank.Set messageId to blank.
Decisions & LoopsIf a step below fails, save the error as idErrorIf a step below fails, save the error as idError
Try
TextTrim message.id and save it as messageId.Trim message.id and save it as messageId.
On error
No steps
Decisions & LoopsIf messageId is emptyIf messageId is empty
Yes
ValuesShow in the output: Skipped a message Gmail returned without an id..Show in the output: Skipped a message Gmail returned without an id..
Decisions & LoopsSkip to the next item.Skip to the next item.
No
No steps
ValuesSet rawFrom to blank.Set rawFrom to blank.
Decisions & LoopsIf a step below fails, save the error as fromErrorIf a step below fails, save the error as fromError
Try
TextTrim message.from and save it as rawFrom.Trim message.from and save it as rawFrom.
On error
No steps
ValuesSet senderAddress to rawFrom.Set senderAddress to rawFrom.
Decisions & LoopsIf rawFrom contains < (ignoring case)If rawFrom contains < (ignoring case)
Yes
TextTrim the first item of the last item of rawFrom split by < split by > and save it as senderAddress.Trim the first item of the last item of rawFrom split by < split by > and save it as senderAddress.
No
No steps
Decisions & LoopsIf senderAddress doesn't contain @ (ignoring case)If senderAddress doesn't contain @ (ignoring case)
Yes
ValuesShow in the output: Skipped a message whose sender could not be read: rawFrom.Show in the output: Skipped a message whose sender could not be read: rawFrom.
Decisions & LoopsSkip to the next item.Skip to the next item.
No
No steps
ValuesSet subject to (no subject).Set subject to (no subject).
Decisions & LoopsIf a step below fails, save the error as subjectErrorIf a step below fails, save the error as subjectError
Try
TextTrim message.subject and save it as subjectText.Trim message.subject and save it as subjectText.
Decisions & LoopsIf subjectText isn't emptyIf subjectText isn't empty
Yes
ValuesChange subject to subjectText.Change subject to subjectText.
No
No steps
On error
No steps
ValuesSet latestId to blank.Set latestId to blank.
Decisions & LoopsIf a step below fails, save the error as latestErrorIf a step below fails, save the error as latestError
Try
GmailGmailFind email matching 'from:senderAddress'. Save it as latestFromSender.Find email matching 'from:senderAddress'. Save it as latestFromSender.
TextTrim latestFromSender.email.id and save it as latestId.Trim latestFromSender.email.id and save it as latestId.
On error
No steps
Decisions & LoopsIf latestId is not messageIdIf latestId is not messageId
Yes
ValuesShow in the output: Left alone: '@subject' from senderAddress. Only a sender's newest message in the inbox can be opened, and a newer one has arrived - forward this message to yourself to have it read.Show in the output: Left alone: '@subject' from senderAddress. Only a sender's newest message in the inbox can be opened, and a newer one has arrived - forward this message to yourself to have it read.
Decisions & LoopsSkip to the next item.Skip to the next item.
No
No steps
GmailGmailDownload the attachments on the latest email from senderAddress. Save it as downloaded.Download the attachments on the latest email from senderAddress. Save it as downloaded.
ValuesSet messageDocuments to 0.Set messageDocuments to 0.
Decisions & LoopsFor each attachment in downloaded.documents:For each attachment in downloaded.documents:
Decisions & Loops If summarisedCount is greater than or equal to documentCap If summarisedCount is greater than or equal to documentCap
Yes
Decisions & LoopsStop repeating.Stop repeating.
No
No steps
Values Set fileName to blank. Set fileName to blank.
Decisions & Loops If a step below fails, save the error as nameError If a step below fails, save the error as nameError
Try
TextTrim attachment.filename and save it as fileName.Trim attachment.filename and save it as fileName.
On error
No steps
Values Set attachmentLabel to (unnamed attachment). Set attachmentLabel to (unnamed attachment).
Decisions & Loops If fileName isn't empty If fileName isn't empty
Yes
ValuesChange attachmentLabel to fileName.Change attachmentLabel to fileName.
No
No steps
Decisions & Loops If fileName in lowercase doesn't end with .pdf (ignoring case) If fileName in lowercase doesn't end with .pdf (ignoring case)
Yes
ValuesShow in the output: Skipped attachmentLabel: only PDF attachments are treated as documents.Show in the output: Skipped attachmentLabel: only PDF attachments are treated as documents.
Decisions & LoopsSkip to the next item.Skip to the next item.
No
No steps
Values Set documentRef to blank. Set documentRef to blank.
Decisions & Loops If a step below fails, save the error as refError If a step below fails, save the error as refError
Try
TextTrim attachment.document_ref and save it as documentRef.Trim attachment.document_ref and save it as documentRef.
On error
No steps
Decisions & Loops If documentRef is empty If documentRef is empty
Yes
ValuesShow in the output: Could not open attachmentLabel; it was left alone.Show in the output: Could not open attachmentLabel; it was left alone.
Decisions & LoopsSkip to the next item.Skip to the next item.
No
No steps
Values Set detailLines to an empty list. Set detailLines to an empty list.
Values Set documentKind to not stated in the document. Set documentKind to not stated in the document.
Decisions & Loops If a step below fails, save the error as readError If a step below fails, save the error as readError
Try
AI AgentRun an AI agent: Read the attached document and pull out each of these fields, in this order: - What kind… and save it as reading.Run an AI agent: Read the attached document and pull out each of these fields, in this order: - What kind… and save it as reading.
Decisions & LoopsFor each answer in reading.output.fields:For each answer in reading.output.fields:
Values Set answerName to blank. Set answerName to blank.
Decisions & Loops If a step below fails, save the error as answerNameError If a step below fails, save the error as answerNameError
Try
TextTrim answer.name and save it as answerName.Trim answer.name and save it as answerName.
On error
No steps
Values Set answerValue to blank. Set answerValue to blank.
Decisions & Loops If a step below fails, save the error as answerValueError If a step below fails, save the error as answerValueError
Try
TextTrim answer.value and save it as answerValue.Trim answer.value and save it as answerValue.
On error
Decisions & LoopsIf a step below fails, save the error as answerListErrorIf a step below fails, save the error as answerListError
Try
TextJoin answer.value with , and save it as answerValue.Join answer.value with , and save it as answerValue.
On error
No steps
Decisions & Loops If answerValue is empty If answerValue is empty
Yes
ValuesChange answerValue to not stated in the document.Change answerValue to not stated in the document.
Else if @answerName is "What kind of document this is"
ValuesChange documentKind to answerValue.Change documentKind to answerValue.
Otherwise
No steps
Lists Add answerName: answerValue truncated to 300 characters using … as the ellipsis to the end of detailLines and save it as detailLines. Add answerName: answerValue truncated to 300 characters using … as the ellipsis to the end of detailLines and save it as detailLines.
On error
No steps
Decisions & Loops If detailLines is empty If detailLines is empty
Yes
ValuesShow in the output: Could not read attachmentLabel; nothing was written to the log and the mail was left alone.Show in the output: Could not read attachmentLabel; nothing was written to the log and the mail was left alone.
Decisions & LoopsSkip to the next item.Skip to the next item.
No
No steps
Values Set summaryBrief to: Set summaryBrief to:Write a short plain summary of a document for the person who received it. These are the only details that were read out of the document. Use nothing but these. Do not add anything, do not work anything out, and do not guess. Where a detail says it is not stated in the document, either say so plainly or leave it out - never fill it in.
Values Set summaryRules to: Set summaryRules to:Write at most three sentences, describing only what the document says. Do not give advice, do not say what should be done about it, and do not comment on whether it is good, bad, risky or urgent.
Values Set summaryText to blank. Set summaryText to blank.
Decisions & Loops If a step below fails, save the error as summaryError If a step below fails, save the error as summaryError
Try
OpenAIOpenAIAsk OpenAI: '@summaryBrief plus detailLines joined by a new line plus summaryRules'. Save it as written.Ask OpenAI: '@summaryBrief plus detailLines joined by a new line plus summaryRules'. Save it as written.
TextTrim written.response_text and save it as summaryText.Trim written.response_text and save it as summaryText.
On error
No steps
Decisions & Loops If summaryText is empty If summaryText is empty
Yes
TextJoin detailLines with a new line and save it as summaryText.Join detailLines with a new line and save it as summaryText.
ValuesShow in the output: No summary could be written for attachmentLabel; the log has the document's own answers instead.Show in the output: No summary could be written for attachmentLabel; the log has the document's own answers instead.
No
No steps
Values Set entryHeading to attachmentLabel - from senderAddress - the current date and time. Set entryHeading to attachmentLabel - from senderAddress - the current date and time.
Values Set entryText to Set entryText to entryHeading summaryText .
Google DocsGoogle Docs Add text to logDocumentId. Add text to logDocumentId.entryText
Values Add 1 to summarisedCount. Add 1 to summarisedCount.
Values Add 1 to messageDocuments. Add 1 to messageDocuments.
Lists Add attachmentLabel from senderAddress - documentKind to the end of digestLines and save it as digestLines. Add attachmentLabel from senderAddress - documentKind to the end of digestLines and save it as digestLines.
GmailGmailAdd label processedLabel to email messageId.Add label processedLabel to email messageId.
Decisions & LoopsIf messageDocuments is 0If messageDocuments is 0
Yes
ValuesShow in the output: Nothing to summarise on '@subject' - it carried no readable PDF.Show in the output: Nothing to summarise on '@subject' - it carried no readable PDF.
No
No steps
On error
ValuesShow in the output: Could not read one document email: messageError as text.Show in the output: Could not read one document email: messageError as text.
Decisions & LoopsIf summarisedCount is greater than 0If summarisedCount is greater than 0
Yes
ValuesSet digestBody to digestLines joined by a new lineSet digestBody to digestLines joined by a new line The summaries are in your log: https://docs.google.com/document/d/@logDocumentId/edit.
GmailGmailSend an email to notifyEmail.Send an email to notifyEmail. Subject: Documents read from your mail: summarisedCountdigestBody
No
ValuesShow in the output: No new documents arrived to summarise..Show in the output: No new documents arrived to summarise..