{ "meta": { "instanceId": "a2434c94d549548a685cca39cc4614698e94f527bcea84eefa363f1037ae14cd" }, "nodes": [ { "id": "88c0f64c-a7cd-4f35-96dd-9eee4b1d6a1a", "name": "Generate reply", "type": "n8n-nodes-base.openAi", "position": [ -480, 2260 ], "parameters": { "prompt": "=From: {{ $json.from.value }}\nTo: {{ $json.to.value }}\nSubject: {{ $json.subject }}\nBody: {{ $json.reply }}\n\n\nReply: ", "options": { "maxTokens": "={{ $('Configure').first().json.replyTokenSize }}" } }, "credentials": { "openAiApi": { "id": "27", "name": "[UPDATE ME]" } }, "typeVersion": 1 }, { "id": "7105b689-9f9c-4354-aad9-8f1abb6c0a06", "name": "On email received", "type": "n8n-nodes-base.gmailTrigger", "position": [ -2460, 2680 ], "parameters": { "simple": false, "filters": {}, "options": {}, "pollTimes": { "item": [ { "mode": "everyMinute" } ] } }, "credentials": { "gmailOAuth2": { "id": "26", "name": "[UPDATE ME]" } }, "typeVersion": 1 }, { "id": "ea18ed9a-0158-45e1-ac1b-1993ace4ff2c", "name": "Only continue for specific emails", "type": "n8n-nodes-base.if", "position": [ -1360, 2460 ], "parameters": { "conditions": { "string": [ { "value1": "={{ $('Configure').first().json.recipients.split(',') }}", "value2": "*", "operation": "contains" }, { "value1": "={{ $('Configure').first().json.recipients.split(',') }}", "value2": "={{ $json.from.value[0].address }}", "operation": "contains" } ] }, "combineOperation": "any" }, "typeVersion": 1 }, { "id": "d1425dff-0fc1-4a4b-9202-418ce30d7cd9", "name": "Configure", "type": "n8n-nodes-base.set", "position": [ -1940, 2800 ], "parameters": { "values": { "number": [ { "name": "maxTokenSize", "value": 4000 }, { "name": "replyTokenSize", "value": 300 } ], "string": [ { "name": "spreadsheetId" }, { "name": "worksheetId" }, { "name": "spreadsheetName", "value": "ChatGPT responses" }, { "name": "worksheetName", "value": "Database" }, { "name": "recipients", "value": "[UPDATE ME]" } ] }, "options": {} }, "typeVersion": 1 }, { "id": "594f77e6-9e7e-4e93-b6e0-95fad57e42f0", "name": "Note5", "type": "n8n-nodes-base.stickyNote", "position": [ -2060, 2480 ], "parameters": { "width": 330.0279884670691, "height": 929.4540475960038, "content": "### Configuration\nIf you decide to use your own spreadsheet, it is up to you to ensure all columns are present before running this workflow. A good way to do this is to run this workflow once with **empty** `spreadsheetid` and `worksheetId` variables (see the `Configure` node). Then map the output from `Store spreadsheet ID` to this node.\n\nIt is recommended that you specify the `spreadsheetId` and `worksheetId`, since relying solely on a workflow's static data is considered bad practice.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n__`spreadsheetId`__: The ID of the spreadsheet where Pipedrive deals will be stored.\n__`worksheetId`__: The ID of the worksheet where Pipedrive deals will be stored.\n__`spreadsheetName`(required)__: The human readable name of the spreadsheet where Pipedrive deals will be stored.\n__`worksheetName`(required)__: The human readable name of the worksheet in the spreadsheet where Pipedrive deals will be stored.\n__`recipients`(required)__: Comma-separated list of email recipients to send ChatGPT emails to. Use `*` to send ChatGPT response to every email address.\n__`maxTokenSize`(required)__: The maximum token size for the model you choose. See possible models from OpenAI [here](https://platform.openai.com/docs/models/gpt-3).\n__`replyTokenSize`(required)__: The reply's maximum token size. Default is 300. This determines how much text the AI will reply with." }, "typeVersion": 1 }, { "id": "2dc3e403-f2a0-43c2-a1e4-187d901d692f", "name": "Send reply to recipient", "type": "n8n-nodes-base.gmail", "position": [ 360, 1860 ], "parameters": { "message": "={{ $json.html }}", "options": {}, "emailType": "html", "messageId": "={{ $node[\"On email received\"].json.id }}", "operation": "reply" }, "credentials": { "gmailOAuth2": { "id": "26", "name": "[UPDATE ME]" } }, "typeVersion": 2 }, { "id": "f845aa4d-5542-4126-a42d-4e5afa1893d1", "name": "Generate UUID", "type": "n8n-nodes-base.crypto", "position": [ -1140, 2360 ], "parameters": { "action": "generate", "dataPropertyName": "uuid" }, "typeVersion": 1 }, { "id": "3c468585-4546-439b-9e8a-efb7231277d8", "name": "Thanks for your response!", "type": "n8n-nodes-base.html", "position": [ -1140, 2980 ], "parameters": { "html": "\n\n\n\n \n Thanks for your response!\n\n\n
\n

Thanks for your response!

\n

You can safely close this window.

\n
\n\n\n\n\n\n" }, "typeVersion": 1 }, { "id": "6b0bfa33-84ca-4b9c-98ec-c1bc08a1230d", "name": "Extract message content (advanced)", "type": "n8n-nodes-base.code", "position": [ -920, 2360 ], "parameters": { "jsCode": "// source: https://gist.github.com/ikbelkirasan/2462073f6c7c760faa6fad7c6a0c4dc3\nvar EmailParser=function(t){var r={};function n(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=r,n.d=function(t,r,e){n.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:e})},n.r=function(t){\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},n.t=function(t,r){if(1&r&&(t=n(t)),8&r)return t;if(4&r&&\"object\"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,\"default\",{enumerable:!0,value:t}),2&r&&\"string\"!=typeof t)for(var o in t)n.d(e,o,function(r){return t[r]}.bind(null,o));return e},n.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(r,\"a\",r),r},n.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},n.p=\"\",n(n.s=59)}([function(t,r){var n=Array.isArray;t.exports=n},function(t,r,n){var e=n(31),o=\"object\"==typeof self&&self&&self.Object===Object&&self,u=e||o||Function(\"return this\")();t.exports=u},function(t,r,n){var e=n(74),o=n(79);t.exports=function(t,r){var n=o(t,r);return e(n)?n:void 0}},function(t,r){t.exports=function(t){return null!=t&&\"object\"==typeof t}},function(t,r){t.exports=function(t){var r=typeof t;return null!=t&&(\"object\"==r||\"function\"==r)}},function(t,r,n){var e=n(6),o=n(75),u=n(76),i=e?e.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?\"[object Undefined]\":\"[object Null]\":i&&i in Object(t)?o(t):u(t)}},function(t,r,n){var e=n(1).Symbol;t.exports=e},function(t,r,n){var e=n(35),o=n(99),u=n(14);t.exports=function(t){return u(t)?e(t):o(t)}},function(t,r,n){var e=n(64),o=n(65),u=n(66),i=n(67),c=n(68);function a(t){var r=-1,n=null==t?0:t.length;for(this.clear();++r-1&&t%1==0&&t<=9007199254740991}},function(t,r){t.exports=function(t){return function(r){return t(r)}}},function(t,r,n){(function(t){var e=n(31),o=r&&!r.nodeType&&r,u=o&&\"object\"==typeof t&&t&&!t.nodeType&&t,i=u&&u.exports===o&&e.process,c=function(){try{var t=u&&u.require&&u.require(\"util\").types;return t||i&&i.binding&&i.binding(\"util\")}catch(t){}}();t.exports=c}).call(this,n(13)(t))},function(t,r){var n=Object.prototype;t.exports=function(t){var r=t&&t.constructor;return t===(\"function\"==typeof r&&r.prototype||n)}},function(t,r,n){var e=n(41),o=n(42),u=Object.prototype.propertyIsEnumerable,i=Object.getOwnPropertySymbols,c=i?function(t){return null==t?[]:(t=Object(t),e(i(t),(function(r){return u.call(t,r)})))}:o;t.exports=c},function(t,r,n){var e=n(48);t.exports=function(t){var r=new t.constructor(t.byteLength);return new e(r).set(new e(t)),r}},function(t,r,n){var e=n(0),o=n(29),u=/\\.|\\[(?:[^[\\]]*|([\"'])(?:(?!\\1)[^\\\\]|\\\\.)*?\\1)\\]/,i=/^\\w*$/;t.exports=function(t,r){if(e(t))return!1;var n=typeof t;return!(\"number\"!=n&&\"symbol\"!=n&&\"boolean\"!=n&&null!=t&&!o(t))||(i.test(t)||!u.test(t)||null!=r&&t in Object(r))}},function(t,r,n){var e=n(5),o=n(3);t.exports=function(t){return\"symbol\"==typeof t||o(t)&&\"[object Symbol]\"==e(t)}},function(t,r,n){var e=n(5),o=n(4);t.exports=function(t){if(!o(t))return!1;var r=e(t);return\"[object Function]\"==r||\"[object GeneratorFunction]\"==r||\"[object AsyncFunction]\"==r||\"[object Proxy]\"==r}},function(t,r){var n=\"object\"==typeof global&&global&&global.Object===Object&&global;t.exports=n},function(t,r){var n=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return n.call(t)}catch(t){}try{return t+\"\"}catch(t){}}return\"\"}},function(t,r,n){var e=n(34),o=n(18),u=Object.prototype.hasOwnProperty;t.exports=function(t,r,n){var i=t[r];u.call(t,r)&&o(i,n)&&(void 0!==n||r in t)||e(t,r,n)}},function(t,r,n){var e=n(93);t.exports=function(t,r,n){\"__proto__\"==r&&e?e(t,r,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[r]=n}},function(t,r,n){var e=n(95),o=n(36),u=n(0),i=n(21),c=n(37),a=n(38),s=Object.prototype.hasOwnProperty;t.exports=function(t,r){var n=u(t),f=!n&&o(t),p=!n&&!f&&i(t),l=!n&&!f&&!p&&a(t),v=n||f||p||l,b=v?e(t.length,String):[],h=b.length;for(var y in t)!r&&!s.call(t,y)||v&&(\"length\"==y||p&&(\"offset\"==y||\"parent\"==y)||l&&(\"buffer\"==y||\"byteLength\"==y||\"byteOffset\"==y)||c(y,h))||b.push(y);return b}},function(t,r,n){var e=n(96),o=n(3),u=Object.prototype,i=u.hasOwnProperty,c=u.propertyIsEnumerable,a=e(function(){return arguments}())?e:function(t){return o(t)&&i.call(t,\"callee\")&&!c.call(t,\"callee\")};t.exports=a},function(t,r){var n=/^(?:0|[1-9]\\d*)$/;t.exports=function(t,r){var e=typeof t;return!!(r=null==r?9007199254740991:r)&&(\"number\"==e||\"symbol\"!=e&&n.test(t))&&t>-1&&t%1==0&&tf))return!1;var l=a.get(t);if(l&&a.get(r))return l==r;var v=-1,b=!0,h=2&n?new e:void 0;for(a.set(t,r),a.set(r,t);++v+$/,f=[/^\\s*(On(?:(?!.*On\\b|\\bwrote:)[\\s\\S])+wrote:)$/m,/^\\s*(Le(?:(?!.*Le\\b|\\bécrit:)[\\s\\S])+écrit :)$/m,/^\\s*(El(?:(?!.*El\\b|\\bescribió:)[\\s\\S])+escribió:)$/m,/^\\s*(Il(?:(?!.*Il\\b|\\bscritto:)[\\s\\S])+scritto:)$/m,/^\\s*(Op\\s[\\S\\s]+?schreef[\\S\\s]+:)$/m,/^\\s*((W\\sdniu|Dnia)\\s[\\S\\s]+?(pisze|napisał(\\(a\\))?):)$/mu,/^\\s*(Den\\s.+\\sskrev\\s.+:)$/m,/^\\s*(Am\\s.+\\sum\\s.+\\sschrieb\\s.+:)$/m,/^(在[\\S\\s]+写道:)$/m,/^(20[0-9]{2}\\..+\\s작성:)$/m,/^(20[0-9]{2}\\/.+のメッセージ:)$/m,/^(.+\\s<.+>\\sschrieb:)$/m,/^\\s*(From\\s?:.+\\s?(\\[|<).+(\\]|>))/mu,/^\\s*(De\\s?:.+\\s?(\\[|<).+(\\]|>))/mu,/^\\s*(Van\\s?:.+\\s?(\\[|<).+(\\]|>))/mu,/^\\s*(Da\\s?:.+\\s?(\\[|<).+(\\]|>))/mu,/^(20[0-9]{2}-(?:0?[1-9]|1[012])-(?:0?[0-9]|[1-2][0-9]|3[01]|[1-9])\\s[0-2]?[0-9]:\\d{2}\\s[\\S\\s]+?:)$/m,/^\\s*([a-z]{3,4}\\.[\\s\\S]+\\sskrev[\\s\\S]+:)$/m];\n/**\n * Represents a fragment that hasn't been constructed (yet)\n * @license MIT License\n */\nclass p{constructor(){this.lines=[],this.isHidden=!1,this.isSignature=!1,this.isQuoted=!1}toFragment(){var t=c.reverse(this.lines.join(\"\\n\")).replace(/^\\n/,\"\");return new o(t,this.isHidden,this.isSignature,this.isQuoted)}}t.exports=class{constructor(t,r,n){this._signatureRegex=t||a,this._quotedLineRegex=r||s,this._quoteHeadersRegex=n||f}parse(t){if(\"string\"!=typeof t)return new e([]);var r=[];for(var n of(t=t.replace(\"\\r\\n\",\"\\n\"),this._quoteHeadersRegex)){var o=t.match(n);o&&o.length>=2&&(t=t.replace(o[1],o[1].replace(/\\n/g,\" \")))}var i=null;for(var a of c.reverse(t).split(\"\\n\")){if(a=a.replace(/\\n+$/,\"\"),this._isSignature(a)||(a=a.replace(/^\\s+/,\"\")),i){var s=i.lines[i.lines.length-1];this._isSignature(s)?(i.isSignature=!0,this._addFragment(i,r),i=null):0===a.length&&this._isQuoteHeader(s)&&(i.isQuoted=!0,this._addFragment(i,r),i=null)}var f=this._isQuote(a);null!==i&&this._isFragmentLine(i,a,f)||(i&&this._addFragment(i,r),(i=new p).isQuoted=f),i.lines.push(a)}i&&this._addFragment(i,r);var l=[];for(var v of r)l.push(v.toFragment());return new e(u(l))}_addFragment(t,r){(t.isQuoted||t.isSignature||0===t.lines.join(\"\").length)&&(t.isHidden=!0),r.push(t)}_isFragmentLine(t,r,n){return t.isQuoted===n||!!t.isQuoted&&(this._isQuoteHeader(r)||0===r.length)}_isSignature(t){return this._signatureRegex.test(c.reverse(t))}_isQuote(t){return this._quotedLineRegex.test(t)}_isQuoteHeader(t){return i(this._quoteHeadersRegex,r=>r.test(c.reverse(t))).length>0}}},function(t,r,n){var e=n(62),o=n(49),u=n(157);t.exports=class{constructor(t){this._fragments=t}getFragments(){return e(this._fragments)}getVisibleText(){var t=o(this._fragments,t=>!t.isHidden());return u(t,t=>t.getContent()).join(\"\\n\")}}},function(t,r,n){var e=n(63);t.exports=function(t){return e(t,5)}},function(t,r,n){var e=n(17),o=n(92),u=n(33),i=n(94),c=n(101),a=n(104),s=n(105),f=n(106),p=n(107),l=n(46),v=n(108),b=n(15),h=n(113),y=n(114),x=n(119),d=n(0),j=n(21),_=n(121),g=n(4),m=n(123),O=n(7),w={};w[\"[object Arguments]\"]=w[\"[object Array]\"]=w[\"[object ArrayBuffer]\"]=w[\"[object DataView]\"]=w[\"[object Boolean]\"]=w[\"[object Date]\"]=w[\"[object Float32Array]\"]=w[\"[object Float64Array]\"]=w[\"[object Int8Array]\"]=w[\"[object Int16Array]\"]=w[\"[object Int32Array]\"]=w[\"[object Map]\"]=w[\"[object Number]\"]=w[\"[object Object]\"]=w[\"[object RegExp]\"]=w[\"[object Set]\"]=w[\"[object String]\"]=w[\"[object Symbol]\"]=w[\"[object Uint8Array]\"]=w[\"[object Uint8ClampedArray]\"]=w[\"[object Uint16Array]\"]=w[\"[object Uint32Array]\"]=!0,w[\"[object Error]\"]=w[\"[object Function]\"]=w[\"[object WeakMap]\"]=!1,t.exports=function t(r,n,F,A,S,D){var $,P=1&n,z=2&n,E=4&n;if(F&&($=S?F(r,A,S,D):F(r)),void 0!==$)return $;if(!g(r))return r;var k=d(r);if(k){if($=h(r),!P)return s(r,$)}else{var B=b(r),M=\"[object Function]\"==B||\"[object GeneratorFunction]\"==B;if(j(r))return a(r,P);if(\"[object Object]\"==B||\"[object Arguments]\"==B||M&&!S){if($=z||M?{}:x(r),!P)return z?p(r,c($,r)):f(r,i($,r))}else{if(!w[B])return S?r:{};$=y(r,B,P)}}D||(D=new e);var I=D.get(r);if(I)return I;D.set(r,$),m(r)?r.forEach((function(e){$.add(t(e,n,F,e,r,D))})):_(r)&&r.forEach((function(e,o){$.set(o,t(e,n,F,o,r,D))}));var C=E?z?v:l:z?keysIn:O,Q=k?void 0:C(r);return o(Q||r,(function(e,o){Q&&(e=r[o=e]),u($,o,t(e,n,F,o,r,D))})),$}},function(t,r){t.exports=function(){this.__data__=[],this.size=0}},function(t,r,n){var e=n(9),o=Array.prototype.splice;t.exports=function(t){var r=this.__data__,n=e(r,t);return!(n<0)&&(n==r.length-1?r.pop():o.call(r,n,1),--this.size,!0)}},function(t,r,n){var e=n(9);t.exports=function(t){var r=this.__data__,n=e(r,t);return n<0?void 0:r[n][1]}},function(t,r,n){var e=n(9);t.exports=function(t){return e(this.__data__,t)>-1}},function(t,r,n){var e=n(9);t.exports=function(t,r){var n=this.__data__,o=e(n,t);return o<0?(++this.size,n.push([t,r])):n[o][1]=r,this}},function(t,r,n){var e=n(8);t.exports=function(){this.__data__=new e,this.size=0}},function(t,r){t.exports=function(t){var r=this.__data__,n=r.delete(t);return this.size=r.size,n}},function(t,r){t.exports=function(t){return this.__data__.get(t)}},function(t,r){t.exports=function(t){return this.__data__.has(t)}},function(t,r,n){var e=n(8),o=n(19),u=n(20);t.exports=function(t,r){var n=this.__data__;if(n instanceof e){var i=n.__data__;if(!o||i.length<199)return i.push([t,r]),this.size=++n.size,this;n=this.__data__=new u(i)}return n.set(t,r),this.size=n.size,this}},function(t,r,n){var e=n(30),o=n(77),u=n(4),i=n(32),c=/^\\[object .+?Constructor\\]$/,a=Function.prototype,s=Object.prototype,f=a.toString,p=s.hasOwnProperty,l=RegExp(\"^\"+f.call(p).replace(/[\\\\^$.*+?()[\\]{}|]/g,\"\\\\$&\").replace(/hasOwnProperty|(function).*?(?=\\\\\\()| for .+?(?=\\\\\\])/g,\"$1.*?\")+\"$\");t.exports=function(t){return!(!u(t)||o(t))&&(e(t)?l:c).test(i(t))}},function(t,r,n){var e=n(6),o=Object.prototype,u=o.hasOwnProperty,i=o.toString,c=e?e.toStringTag:void 0;t.exports=function(t){var r=u.call(t,c),n=t[c];try{t[c]=void 0;var e=!0}catch(t){}var o=i.call(t);return e&&(r?t[c]=n:delete t[c]),o}},function(t,r){var n=Object.prototype.toString;t.exports=function(t){return n.call(t)}},function(t,r,n){var e,o=n(78),u=(e=/[^.]+$/.exec(o&&o.keys&&o.keys.IE_PROTO||\"\"))?\"Symbol(src)_1.\"+e:\"\";t.exports=function(t){return!!u&&u in t}},function(t,r,n){var e=n(1)[\"__core-js_shared__\"];t.exports=e},function(t,r){t.exports=function(t,r){return null==t?void 0:t[r]}},function(t,r,n){var e=n(81),o=n(8),u=n(19);t.exports=function(){this.size=0,this.__data__={hash:new e,map:new(u||o),string:new e}}},function(t,r,n){var e=n(82),o=n(83),u=n(84),i=n(85),c=n(86);function a(t){var r=-1,n=null==t?0:t.length;for(this.clear();++r\n \n \n Template for ChatGPT email\n \n \n \n
\n
\n

\n {{ $json.text }}\n

\n
\n \n

\n Was this message helpful? Yes No\n

\n

\n
\n
\n \n\n" }, "typeVersion": 1 }, { "id": "38e0f992-a461-4bc1-9f5c-2ceb0e461708", "name": "Record feedback", "type": "n8n-nodes-base.noOp", "position": [ -1360, 2980 ], "parameters": {}, "typeVersion": 1 }, { "id": "899a0c63-0333-4dc4-ba83-5615a38ae431", "name": "Fallback route", "type": "n8n-nodes-base.noOp", "position": [ -1360, 3280 ], "parameters": {}, "typeVersion": 1 }, { "id": "2fd5b109-8a54-4684-a8a3-3f7b2d961ae3", "name": "Identify trigger #2", "type": "n8n-nodes-base.set", "position": [ -2240, 2940 ], "parameters": { "values": { "string": [ { "name": "triggeredFrom", "value": "webhook" } ] }, "options": {} }, "typeVersion": 1 }, { "id": "8c27f798-d947-432c-bfc9-d22727d0159e", "name": "Identify trigger #1", "type": "n8n-nodes-base.set", "position": [ -2240, 2680 ], "parameters": { "values": { "string": [ { "name": "triggeredFrom", "value": "gmail" } ] }, "options": {} }, "typeVersion": 1 }, { "id": "bd8cc1dd-3643-4d2f-9527-cfd740a4072a", "name": "Do not send unfinished email reply", "type": "n8n-nodes-base.noOp", "position": [ -40, 2060 ], "parameters": {}, "typeVersion": 1 }, { "id": "c8b68fdb-c1c0-4f94-b712-e0570a3ad53c", "name": "If reply is complete", "type": "n8n-nodes-base.if", "position": [ -260, 1960 ], "parameters": { "conditions": { "string": [ { "value1": "={{ $json.finish_reason }}", "value2": "stop" } ] } }, "typeVersion": 1 }, { "id": "f9d56d42-aa4e-4394-8c83-8d39164a784e", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "position": [ -100, 2020 ], "parameters": { "width": 225.59802712700315, "height": 314.2786683107279, "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nIf your workflow reaches this stage, you will need to consider increasing the tokens in `Generate reply` node." }, "typeVersion": 1 }, { "id": "039714b3-88ac-4ca8-86fc-ec1c109110c3", "name": "Do not send email to this recipient", "type": "n8n-nodes-base.noOp", "position": [ -1140, 2560 ], "parameters": {}, "typeVersion": 1 }, { "id": "330c67dd-e538-414d-a144-e05dbf5effb3", "name": "Send reply to database", "type": "n8n-nodes-base.noOp", "position": [ -260, 2380 ], "parameters": {}, "typeVersion": 1 }, { "id": "6e7586db-f437-4450-a1c7-e5ea7e8767b0", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "position": [ -3060, 2520 ], "parameters": { "width": 516.6954377311955, "height": 680.5491163173024, "content": "## Send a ChatGPT email reply when email received and save responses to Google Sheets\nThis workflow sends a OpenAI GPT reply when an email is received from specific email recipients. It then saves the initial email and the GPT response to an automatically generated Google spreadsheet. Subsequent GPT responses will be added to the same spreadsheet. Additionally, when feedback is given for any of the GPT responses, it will be recorded to the spreasheet, which can then be used later to fine-tune the GPT model.\n\n### How it works\nThis workflow is essentially a two-in-one workflow. It triggers off from two different nodes and have very different functionality from each trigger.\n\n**`On email received`**:\n1. Triggers off on the `On email received` node.\n2. Extract the email body from the email.\n3. Generate a response from the email body using the `OpenAI` node.\n4. Reply to the email sender using the `Send reply to recipient` node. A feedback link is also included in the email body which will trigger the `On feedback given` node. This is used to fine-tune the GPT model.\n5. Save the email body and OpenAI response to a Google Sheet. If a sheet does not exist, it will be created.\n\n\n**`On feedback given`**:\n1. Triggers off when a feedback link is clicked in the emailed GPT response.\n2. The feedback, either positive or negative, for that specific GPT response is then recorded to the Google Sheet.\n" }, "typeVersion": 1 }, { "id": "9d5e780e-4282-4c7e-b083-3f769f7dc740", "name": "Determine which trigger ran", "type": "n8n-nodes-base.switch", "position": [ -1660, 2800 ], "parameters": { "rules": { "rules": [ { "value2": "gmail" }, { "output": 1, "value2": "webhook" } ] }, "value1": "={{ $json.triggeredFrom }}", "dataType": "string", "fallbackOutput": 3 }, "typeVersion": 1 }, { "id": "2c6c604c-7f59-42cc-9ed2-6d55f342f0ae", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "position": [ -1420, 3240 ], "parameters": { "width": 225.59802712700315, "height": 289.61775585696694, "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\nThis workflow should never reach this node. It is only here for extending the functionality of this workflow if needed." }, "typeVersion": 1 }, { "id": "3defbf98-0caa-49b1-9bfd-f4640b43d64b", "name": "Is text within token limit?", "type": "n8n-nodes-base.if", "position": [ -700, 2360 ], "parameters": { "conditions": { "boolean": [ { "value1": "={{ $json.reply.length() / 4 <= $('Configure').first().json.maxTokenSize - $('Configure').first().json.replyTokenSize }}", "value2": true } ] } }, "typeVersion": 1 }, { "id": "b268b8a3-6361-4515-a995-320cd0979688", "name": "Do nothing", "type": "n8n-nodes-base.noOp", "position": [ -480, 2460 ], "parameters": {}, "typeVersion": 1 }, { "id": "413588d1-ede0-4a51-85fa-c9035ec2e605", "name": "Sticky Note3", "type": "n8n-nodes-base.stickyNote", "position": [ -540, 2420 ], "parameters": { "width": 225.59802712700315, "height": 288.2949081608216, "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThe email that was received is too large to process, as it exceeds token limit. See more on [token limits](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them)." }, "typeVersion": 1 } ], "connections": { "Configure": { "main": [ [ { "node": "Determine which trigger ran", "type": "main", "index": 0 } ] ] }, "Format data": { "main": [ [ { "node": "If no spreadsheet in configuration #1", "type": "main", "index": 0 } ] ] }, "Generate UUID": { "main": [ [ { "node": "Extract message content (advanced)", "type": "main", "index": 0 } ] ] }, "Email template": { "main": [ [ { "node": "Send reply to recipient", "type": "main", "index": 0 } ] ] }, "Generate reply": { "main": [ [ { "node": "Send reply to database", "type": "main", "index": 0 }, { "node": "If reply is complete", "type": "main", "index": 0 } ] ] }, "Show HTML page": { "main": [ [ { "node": "If no spreadsheet in configuration #2", "type": "main", "index": 0 } ] ] }, "If no sheet IDs": { "main": [ [ { "node": "Create spreadsheet", "type": "main", "index": 0 } ], [ { "node": "Get data from `Format data`", "type": "main", "index": 0 } ] ] }, "Record feedback": { "main": [ [ { "node": "Thanks for your response!", "type": "main", "index": 0 } ] ] }, "Get sheet IDs #1": { "main": [ [ { "node": "If no sheet IDs", "type": "main", "index": 0 } ] ] }, "Get sheet IDs #2": { "main": [ [ { "node": "Send feedback for fine-tuned data", "type": "main", "index": 0 } ] ] }, "Send email reply": { "main": [ [ { "node": "Email template", "type": "main", "index": 0 } ] ] }, "On email received": { "main": [ [ { "node": "Identify trigger #1", "type": "main", "index": 0 } ] ] }, "On feedback given": { "main": [ [ { "node": "Identify trigger #2", "type": "main", "index": 0 } ] ] }, "Create spreadsheet": { "main": [ [ { "node": "Store spreadsheet ID", "type": "main", "index": 0 } ] ] }, "Identify trigger #1": { "main": [ [ { "node": "Configure", "type": "main", "index": 0 } ] ] }, "Identify trigger #2": { "main": [ [ { "node": "Configure", "type": "main", "index": 0 } ] ] }, "If reply is complete": { "main": [ [ { "node": "Send email reply", "type": "main", "index": 0 } ], [ { "node": "Do not send unfinished email reply", "type": "main", "index": 0 } ] ] }, "Store spreadsheet ID": { "main": [ [ { "node": "Get data from `Format data` node", "type": "main", "index": 0 } ] ] }, "Create or update rows": { "main": [ [ { "node": "If spreadsheet doesn't exist", "type": "main", "index": 0 } ] ] }, "Send reply to database": { "main": [ [ { "node": "Format data", "type": "main", "index": 0 } ] ] }, "Thanks for your response!": { "main": [ [ { "node": "Show HTML page", "type": "main", "index": 0 } ] ] }, "Determine which trigger ran": { "main": [ [ { "node": "Only continue for specific emails", "type": "main", "index": 0 } ], [ { "node": "Record feedback", "type": "main", "index": 0 } ], null, [ { "node": "Fallback route", "type": "main", "index": 0 } ] ] }, "Get data from `Format data`": { "main": [ [ { "node": "Create or update rows", "type": "main", "index": 0 } ] ] }, "Is text within token limit?": { "main": [ [ { "node": "Generate reply", "type": "main", "index": 0 } ], [ { "node": "Do nothing", "type": "main", "index": 0 } ] ] }, "Store specific sheet IDs #1": { "main": [ [ { "node": "If no sheet IDs", "type": "main", "index": 0 } ] ] }, "Store specific sheet IDs #2": { "main": [ [ { "node": "Send feedback for fine-tuned data", "type": "main", "index": 0 } ] ] }, "If spreadsheet doesn't exist": { "main": [ [ { "node": "Create spreadsheet", "type": "main", "index": 0 } ], [ { "node": "Successfully created or updated row", "type": "main", "index": 0 } ] ] }, "Get data from `Format data` node": { "main": [ [ { "node": "Paste data", "type": "main", "index": 0 } ] ] }, "Only continue for specific emails": { "main": [ [ { "node": "Generate UUID", "type": "main", "index": 0 } ], [ { "node": "Do not send email to this recipient", "type": "main", "index": 0 } ] ] }, "Extract message content (advanced)": { "main": [ [ { "node": "Is text within token limit?", "type": "main", "index": 0 } ] ] }, "If no spreadsheet in configuration #1": { "main": [ [ { "node": "Get sheet IDs #1", "type": "main", "index": 0 } ], [ { "node": "Store specific sheet IDs #1", "type": "main", "index": 0 } ] ] }, "If no spreadsheet in configuration #2": { "main": [ [ { "node": "Get sheet IDs #2", "type": "main", "index": 0 } ], [ { "node": "Store specific sheet IDs #2", "type": "main", "index": 0 } ] ] } } }