Task: Automate Hubspot lead status update with ChatGPT

n8n workflow:
{"meta":{"instanceId":"614e43e43c7daf5eb87090052168a9ac123a435b43bdd9312badd6e459da3d8a"},"nodes":[{"id":"7a636e63-8f54-4df6-b284-0988747e8944","name":"Gmail Trigger","type":"n8n-nodes-base.gmailTrigger","position":[-480,360],"parameters":{"filters":{},"pollTimes":{"item":[{"mode":"everyMinute"}]}},"credentials":{},"typeVersion":1},{"id":"c583fab1-cdd4-46a5-a871-b1dc94211940","name":"Merge","type":"n8n-nodes-base.merge","position":[1420,320],"parameters":{"mode":"combine","options":{"clashHandling":{"values":{"resolveClash":"preferInput2"}}},"combinationMode":"mergeByPosition"},"typeVersion":2},{"id":"ef02d115-4701-4180-b059-3d64eb71eec0","name":"OpenAI","type":"n8n-nodes-base.openAi","position":[920,120],"parameters":{"prompt":{"messages":[{"role":"system","content":"=You are an assistant that supports the seller in categorizing email replies.\n\nThe answers are in Netherlands and you must ONLY answer with one of the following categories: [“Interested”, “Bad Timing”, “Not Interested” “Out of office”, “Unsubscribe”, “Other”] "},{"content":"=- “Interested” is when the reply is positive. With positive reply I mean: Leads sent phone number to be called, lead ask for a meeting, lead ask interested based questions.\n- “Bad timing” is when asking to be contacted within a few months/years.\n- “Not interested” is when the lead replies that he is not interested right now.\n- “Out of office” is when a lead is not in the workplace (holiday or temporary) and says when he will be back.\n- “Unsubscribe” is when a lead asks to be removed from the email lists.\n\nIf you are unsure how to answer, you SHOULD answer with “Other”.\n\nEmails: \"\"\"\n\n{{ $('Gmail Trigger').item.json.snippet.replaceAll(/^\\s+|\\s+$/g, '').replace(/(\\r\\n|\\n|\\r)/gm, \"\") }}\n\n\"\"\"\nCategory:"}]},"options":{"maxTokens":1000,"temperature":0.5},"resource":"chat"},"credentials":{},"typeVersion":1},{"id":"f46daf3c-c379-466d-93bf-88a504444bcb","name":"Hubspot - Change Out of office status","type":"n8n-nodes-base.httpRequest","position":[2560,580],"parameters":{"url":"=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.id }}","options":{},"requestMethod":"PATCH","authentication":"predefinedCredentialType","jsonParameters":true,"bodyParametersJson":"={\n   \"properties\":{\n      \"hs_lead_status\":\"Out of office\"\n   }\n}","nodeCredentialType":"hubspotOAuth2Api"},"credentials":{},"typeVersion":2},{"id":"32102963-17c5-4383-b0af-e717b3c4665d","name":"Hubspot - Change Not Interested status","type":"n8n-nodes-base.httpRequest","position":[2560,840],"parameters":{"url":"=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.id }}","options":{},"requestMethod":"PATCH","authentication":"predefinedCredentialType","jsonParameters":true,"bodyParametersJson":"={\n   \"properties\":{\n      \"hs_lead_status\":\"Not Interested\"\n   }\n}","nodeCredentialType":"hubspotOAuth2Api"},"credentials":{},"typeVersion":2},{"id":"e3c37ef5-4c11-455e-b251-fddd3fc46db2","name":"Hubspot - Change Bad Timing status","type":"n8n-nodes-base.httpRequest","position":[2560,1100],"parameters":{"url":"=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.id }}","options":{},"requestMethod":"PATCH","authentication":"predefinedCredentialType","jsonParameters":true,"bodyParametersJson":"={\n   \"properties\":{\n      \"hs_lead_status\":\"Bad Timing\"\n   }\n}","nodeCredentialType":"hubspotOAuth2Api"},"credentials":{},"typeVersion":2},{"id":"df8dbb86-3909-407c-9cb9-ffbd0cd0a8bb","name":"Hubspot - Change Replied status","type":"n8n-nodes-base.httpRequest","position":[2560,1340],"parameters":{"url":"=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.id }}","options":{},"requestMethod":"PATCH","authentication":"predefinedCredentialType","jsonParameters":true,"bodyParametersJson":"={\n   \"properties\":{\n      \"hs_lead_status\":\"Replied\"\n   }\n}","nodeCredentialType":"hubspotOAuth2Api"},"credentials":{},"typeVersion":2},{"id":"6c1a2a50-9769-4c52-9560-65efa53b403b","name":"Hubspot - Change Interested status","type":"n8n-nodes-base.httpRequest","position":[2560,320],"parameters":{"url":"=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.id }}","options":{},"requestMethod":"PATCH","authentication":"predefinedCredentialType","jsonParameters":true,"bodyParametersJson":"={\n   \"properties\":{\n      \"hs_lead_status\":\"Interested\"\n   }\n}","nodeCredentialType":"hubspotOAuth2Api"},"credentials":{},"typeVersion":2},{"id":"93203f69-878b-4525-bfa8-35df1dba645a","name":"Hubspot - Change Opted Out status2","type":"n8n-nodes-base.httpRequest","position":[2560,60],"parameters":{"url":"=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.id }}","options":{},"requestMethod":"PATCH","authentication":"predefinedCredentialType","jsonParameters":true,"bodyParametersJson":"={\n   \"properties\":{\n      \"hs_lead_status\":\"Opted Out\"\n   }\n}","nodeCredentialType":"hubspotOAuth2Api"},"credentials":{},"typeVersion":2},{"id":"a4537b81-9e7a-4230-95c8-f6d855f7a1ab","name":"Extract email","type":"n8n-nodes-base.code","position":[-220,360],"parameters":{"mode":"runOnceForEachItem","jsCode":"const emailRegex = /<([^>]+)>/; \n\nconst match = emailRegex.exec($input.item.json?.From);\nif (match && match?.length > 1) {\n  const email = match?.[1];\n  return {\n    email: email\n  }\n} else {\n  return {\n    email: \"\"\n  }\n}"},"typeVersion":1},{"id":"f0958499-d40b-41ca-9bbc-3675a1d96655","name":"Hubspot Contact Search","type":"n8n-nodes-base.hubspot","position":[40,360],"parameters":{"operation":"search","authentication":"oAuth2","filterGroupsUi":{"filterGroupsValues":[{"filtersUi":{"filterValues":[{"value":"={{ $json.email }}","propertyName":"email|string"},{"value":"true","propertyName":"linkedin_premium|enumeration"}]}}]},"additionalFields":{}},"credentials":{},"typeVersion":2},{"id":"ec660f63-52c1-4e33-b913-49867a02325d","name":"Contact Exists?","type":"n8n-nodes-base.switch","position":[320,360],"parameters":{"rules":{"rules":[{"value2":"={{$node['Extract email'].json[\"email\"]}}"}]},"value1":"={{ $json.properties.email }}","dataType":"string","fallbackOutput":1},"typeVersion":1},{"id":"1f6c0db4-933f-44b7-947c-7038394aac83","name":"Interest Handler","type":"n8n-nodes-base.switch","position":[1760,320],"parameters":{"rules":{"rules":[{"value2":"unsubscribe"},{"output":1,"value2":"interested"},{"output":2,"value2":"out of office"}]},"value1":"={{ $json.message.content.trim().toLowerCase() }}","dataType":"string","fallbackOutput":3},"typeVersion":1},{"id":"6d1c598e-7b46-462b-a6e1-d26f6e015991","name":"Interest Handler - 2","type":"n8n-nodes-base.switch","position":[2120,1100],"parameters":{"rules":{"rules":[{"value2":"not interested"},{"output":1,"value2":"bad timing"}]},"value1":"={{ $json.message.content.trim().toLowerCase() }}","dataType":"string","fallbackOutput":2},"typeVersion":1}],"connections":{"Merge":{"main":[[{"node":"Interest Handler","type":"main","index":0}]]},"OpenAI":{"main":[[{"node":"Merge","type":"main","index":0}]]},"Extract email":{"main":[[{"node":"Hubspot Contact Search","type":"main","index":0}]]},"Gmail Trigger":{"main":[[{"node":"Extract email","type":"main","index":0}]]},"Contact Exists?":{"main":[[{"node":"Merge","type":"main","index":1},{"node":"OpenAI","type":"main","index":0}]]},"Interest Handler":{"main":[[{"node":"Hubspot - Change Opted Out status2","type":"main","index":0}],[{"node":"Hubspot - Change Interested status","type":"main","index":0}],[{"node":"Hubspot - Change Out of office status","type":"main","index":0}],[{"node":"Interest Handler - 2","type":"main","index":0}]]},"Interest Handler - 2":{"main":[[{"node":"Hubspot - Change Not Interested status","type":"main","index":0}],[{"node":"Hubspot - Change Bad Timing status","type":"main","index":0}],[{"node":"Hubspot - Change Replied status","type":"main","index":0}]]},"Hubspot Contact Search":{"main":[[{"node":"Contact Exists?","type":"main","index":0}]]}}}