AI Email Automation for multiple items
Hey there! I built the AI Email Automation workflow, presented by Nate in his YT video. (Json data attached) It works well for one single email coming in from the trigger node ✅ But as soon as the trigger sends multiple items at once (which is the case when the workflow is active and you have received multiple emails before the next time the workflow execution starts), the emails get drafted in the same thread (see screenshot of inbox attached: Received 3 new emails and drafts of them being created in only the thread of the most recent one). ❌ Reason for problem: In the "createDraft" tool, the ThreadID is set to {{ $('Set Content').item.json.threadID }}, calling up the threadID, which has been set as a string parameter in the "Set Content" node. With the expression {{ $('Set Content').item.json.threadID }} the "createDraft" tool picks up only one thread ID, which is the threadID of the first email of all email items running through the workflow, so probably only referring to the first slot of the threadID parameter in "Set Content" node. Solution 1: 💡 Accessing the individual threadID of each itemIndex in the "Set Content" node by using the expression: {{$items("Set Content")[$itemIndex].json.threadID}} in the "createDraft" tool. Problem Solution 1: The ThreadID in the "createDraft" tool is for all the emails still the same & all drafts get put into one thread. And sometimes a draft gets created in all the email threads, but then the draft content is the same for all drafts. ❌ Solution 2: 💡 Creating a "loop over items(Split in batches)" node, which should send the items individually through the workflow while keeping the expression {{ $('Set Content').item.json.threadID }}. Problem for Solution 2: Exactly the same problem as for solution 1: Sometimes a draft gets created for all the required threadIDs, but then the draft is the same, so only one single email is matching. Or multiple drafts get created in one email thread. ❌