{
  "id": "ODMETlbW2svWuXdX",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automated Invoice Creation & Team Notification with Jotform, Xero, Outlook, and Telegram",
  "tags": [],
  "nodes": [
    {
      "id": "61d97eb7-9e7a-4ec4-a567-c03180ccdd0f",
      "name": "Receive form submission",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -464,
        0
      ],
      "parameters": {
        "path": "1d06aca8-7d95-4394-8630-87450e7a2fbe",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "5ec3d9b8-46c4-41bc-98d6-bfb5bdfaf7a8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## Receive Submission\nReceives the product/service form submission from Jotform"
      },
      "typeVersion": 1
    },
    {
      "id": "afa3abe6-529e-4a78-8272-0fdaa32bbfc4",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1664,
        -400
      ],
      "parameters": {
        "width": 1072,
        "height": 1024,
        "content": "## Automated Invoice Creation & Team Notification with Jotform, Xero, Outlook, and Telegram\nThis workflow automates the entire process of receiving a product/service order, checking or creating a customer in **Xero**, generating an invoice, emailing it, and notifying the sales team for example after sometime if no action has been taken yet (via **Telegram**)  \u2014 all triggered by a form submission (via **Jotform**).\n\n## How It Works\n### 1- Receive Submission\n* Triggered when a user submits a form.\n* Collects data like customer details, selected product/service, etc.\n\n### 2- Check If Customer Exists\n* Searches Xero to determine if the customer already exists.\n* \u2705 **If Customer Exists:** **Update** customer details.\n* \u274c **If Customer Doesn\u2019t Exist:** **Create** a new customer in Xero.\n\n### 3- Create The Invoice\n* Generates a new invoice for the customer using the item selected.\n\n### 4- Send The Invoice\n* Automatically sends the invoice via email to the customer.\n\n### 5- Wait For Sometime\nNow we will wait for 30 seconds (by default, you can change it) and then get the invoice details from Xero\n\n### 6- Notify The Team\n* Notifies the sales team for example via Telegram in case no action has been taken on the invoice and thus the team can act fast.\n\n## Who Can Benefit from This Workflow?\n* **Freelancers**\n* **Service Providers**\n* **Consultants & Coaches**\n* **Small Businesses**\n* **E-commerce or Custom Product Sellers**\n\n## Requirements\n- Jotform webhook setup, more info [here](https://www.jotform.com/help/245-how-to-setup-a-webhook-with-jotform/)\n- Xero credentials, more info [here](https://docs.n8n.io/integrations/builtin/credentials/xero)\n- Make sure that products/services values in Jotform are exactly the same as your item `Code` in your Xero account\n- Email setup, update email node (`Send email`), more info about Outlook setup [here](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.microsoftoutlook)\n- LLM model credentials\n- Telegram credentials, more info [here](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.telegram)"
      },
      "typeVersion": 1
    },
    {
      "id": "6bcd36c0-d53f-4316-97e4-b39ec65f0f7b",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## Format Data\nFormats the data thus making it easier to be used in other nodes"
      },
      "typeVersion": 1
    },
    {
      "id": "e5a8345a-0044-443d-86bc-f7053bb8d9a0",
      "name": "Format data",
      "type": "n8n-nodes-base.code",
      "position": [
        -160,
        0
      ],
      "parameters": {
        "jsCode": "function extractAddressData(text) {\n  const regex = /Street Address:\\s*([^<]+)<br>Street Address Line 2:\\s*([^<]+)<br>City:\\s*([^<]+)<br>State \\/ Province:\\s*([^<]+)<br>Postal \\/ Zip Code:\\s*([^<]+)<br>Country:\\s*([^<]+)<br>/;\n  const matches = text.match(regex);\n  \n  if (matches) {\n    return {\n      line1: matches[1].trim(),\n      line2: matches[2].trim(),\n      city: matches[3].trim(),\n      stateProvince: matches[4].trim(),\n      postalZipCode: matches[5].trim(),\n      country: matches[6].trim()\n    };\n  }\n  \n  return {\n    line1: null,\n    line2: null,\n    city: null,\n    stateProvince: null,\n    postalZipCode: null,\n    country: null\n  }\n}\n\nreturn {\n  address: extractAddressData($input.first().json.body.billingAddress),\n  customer: {\n    name: $input.first().json.body.name,\n    email: $input.first().json.body.email,\n    phone: $input.first().json.body.phone\n  },\n  item: {\n    name: $input.first().json.body.itemName\n  }\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "4c1db4b6-d961-4f5d-a691-4ac079848e20",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 320,
        "content": "## Create Contact\nCreates a new contact"
      },
      "typeVersion": 1
    },
    {
      "id": "02a78f6d-6ca5-43a9-b281-81e5192e0902",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        -96
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## Create The Invoice\nCreates a new invoice for that contact"
      },
      "typeVersion": 1
    },
    {
      "id": "c9b24758-5f94-49ee-9947-fc4e2b5ef674",
      "name": "Create the invoice",
      "type": "n8n-nodes-base.xero",
      "position": [
        928,
        16
      ],
      "parameters": {
        "type": "ACCREC",
        "contactId": "={{ $json.ContactID }}",
        "lineItemsUi": {
          "lineItemsValues": [
            {
              "taxType": "INPUT",
              "itemCode": "={{ $('Format data').item.json.item.name }}",
              "unitAmount": "10",
              "accountCode": "200"
            }
          ]
        },
        "organizationId": "bc9a44a6-eb14-4f81-b24c-ca676c506446",
        "additionalFields": {}
      },
      "credentials": {
        "xeroOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0dc36d70-24f7-4131-bf75-11227c591466",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1280,
        -352
      ],
      "parameters": {
        "text": "={{ $json }}",
        "options": {
          "systemMessage": "=You are an AI assistant that generates a professional invoice email that you get from an Xero response (newly created invoice), so you will recive an Xero invoice response and thus your job is to create a professional html email content because this html email content will be sent to the customer."
        },
        "promptType": "define"
      },
      "executeOnce": false,
      "typeVersion": 2.2
    },
    {
      "id": "31b485fd-94fa-489f-bb75-041686861752",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1280,
        -144
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "de5dee60-bf2b-4ec5-aad4-663da044dbef",
      "name": "Sticky Note19",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        -480
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 480,
        "content": "## Send The Invoice\nSends the newly created invoice for that customer(via email)"
      },
      "typeVersion": 1
    },
    {
      "id": "b4abfdca-dd13-4236-ae82-6ad9b9f54cba",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 320,
        "content": "## Check If Contact exists \nChecks if the contact exists in Xero or not"
      },
      "typeVersion": 1
    },
    {
      "id": "121a9b5c-577b-464d-a79a-9635d2431a29",
      "name": "Check if the customer exists",
      "type": "n8n-nodes-base.xero",
      "position": [
        128,
        0
      ],
      "parameters": {
        "limit": 1,
        "options": {
          "where": "=EmailAddress=\"{{ $json.customer.email }}\""
        },
        "resource": "contact",
        "operation": "getAll",
        "organizationId": "bc9a44a6-eb14-4f81-b24c-ca676c506446"
      },
      "credentials": {
        "xeroOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "5687d623-08ed-48a1-a63a-12fe1d55cccf",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        304,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "bfa24559-7702-4ebf-909d-c5c2a60ad817",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json }}",
              "rightValue": 0
            },
            {
              "id": "b4301cfe-a22a-490f-a72b-50d266bc1c5e",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.ContactID }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7048310b-d795-4d73-ae02-ba9532774c82",
      "name": "Create new contact",
      "type": "n8n-nodes-base.xero",
      "position": [
        608,
        192
      ],
      "parameters": {
        "name": "={{ $('Format data').item.json.customer.name }}",
        "resource": "contact",
        "organizationId": "bc9a44a6-eb14-4f81-b24c-ca676c506446",
        "additionalFields": {
          "phonesUi": {
            "phonesValues": [
              {
                "phoneType": "MOBILE",
                "phoneNumber": "={{ $('Format data').item.json.customer.phone }}"
              }
            ]
          },
          "addressesUi": {
            "addressesValues": [
              {
                "city": "={{ $('Format data').item.json.address.city }}",
                "type": "STREET",
                "line1": "={{ $('Format data').item.json.address.line1 }}",
                "line2": "={{ $('Format data').item.json.address.line2 }}",
                "region": "={{ $('Format data').item.json.address.stateProvince }}",
                "country": "={{ $('Format data').item.json.address.country }}",
                "postalCode": "={{ $('Format data').item.json.address.postalZipCode }}"
              }
            ]
          },
          "emailAddress": "={{ $('Format data').item.json.customer.email }}"
        }
      },
      "credentials": {
        "xeroOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "25318bf6-5212-4700-bb88-8f59e3fb685f",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        -304
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 320,
        "content": "## Update Contact\nUpdates the contact"
      },
      "typeVersion": 1
    },
    {
      "id": "021f77f0-f990-4fc9-8bfd-82a2a0fc6fb2",
      "name": "Update contact",
      "type": "n8n-nodes-base.xero",
      "position": [
        608,
        -192
      ],
      "parameters": {
        "resource": "contact",
        "contactId": "={{ $json.ContactID }}",
        "operation": "update",
        "updateFields": {
          "name": "={{ $('Format data').item.json.customer.name }}",
          "phonesUi": {
            "phonesValues": [
              {
                "phoneType": "MOBILE",
                "phoneNumber": "={{ $('Format data').item.json.customer.phone }}"
              }
            ]
          }
        },
        "organizationId": "bc9a44a6-eb14-4f81-b24c-ca676c506446"
      },
      "credentials": {
        "xeroOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f0631c6e-26fe-40c2-af37-1521f763fd7d",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        1264,
        240
      ],
      "parameters": {
        "amount": 30
      },
      "typeVersion": 1.1
    },
    {
      "id": "4b7e6aa3-fbf5-410f-951e-6c8ed9d95b19",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1376,
        672
      ],
      "parameters": {
        "text": "={{ $json }}",
        "options": {
          "systemMessage": "=You are an AI assistant that generates a telegram notification message for an invoice that has been created recently and no action/change has been done on it yet, the input that you will receive is an Xero invoice details response, so you will recive an Xero invoice response and thus your job is to create a telegram message that will notify the team about the invoice that has no actions on it yet so the team can act fast and accordingly."
        },
        "promptType": "define"
      },
      "executeOnce": false,
      "typeVersion": 2.2
    },
    {
      "id": "59f827be-d826-403c-8713-69bfbe4349e8",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1376,
        864
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4664b6f4-d9a4-4056-ae80-bebff70c14c5",
      "name": "Sticky Note20",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        544
      ],
      "parameters": {
        "color": 7,
        "width": 688,
        "height": 480,
        "content": "## Notify The Team To Act Fast\nNotifies the team (sales team for example) about the invoice since after 30 seconds no change has been done on the invoice and thus the team will be notified to act fast"
      },
      "typeVersion": 1
    },
    {
      "id": "59351848-8223-47a3-9dfc-27aeedfa8cda",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 320,
        "content": "## Wait For Sometime\nNow we will wait for 30 seconds"
      },
      "typeVersion": 1
    },
    {
      "id": "2c7f5651-eb52-441b-9475-927ef22c4763",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1504,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 320,
        "content": "## Get The Invoice\nGets the invoice details that has been just created in Xero"
      },
      "typeVersion": 1
    },
    {
      "id": "9ba91ea8-ab1c-4927-b638-d8cbafaf534b",
      "name": "Get the invoice",
      "type": "n8n-nodes-base.xero",
      "position": [
        1600,
        240
      ],
      "parameters": {
        "invoiceId": "={{ $json.InvoiceID }}",
        "operation": "get",
        "organizationId": "bc9a44a6-eb14-4f81-b24c-ca676c506446"
      },
      "credentials": {
        "xeroOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "531f53e7-ebec-417b-9e46-cc5e5894af53",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        1216,
        672
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "no change",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c8ceadc4-e291-4cf2-8577-20263a8014ed",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Create the invoice').item.json.Status }}",
                    "rightValue": "={{ $json.Status }}"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.3
    },
    {
      "id": "78a0a705-1fc4-463f-b889-882b039fa6c8",
      "name": "Notify the team",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1680,
        672
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=",
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "83413816-6a78-475c-8b51-15e2153475bd",
      "name": "Send email",
      "type": "n8n-nodes-base.microsoftOutlook",
      "position": [
        1568,
        -352
      ],
      "parameters": {
        "subject": "New Invoice",
        "bodyContent": "={{ $json.output }}",
        "toRecipients": "={{ $('Create the invoice').item.json.Contact.EmailAddress }}",
        "additionalFields": {}
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "22162ab7-5bd4-47e2-ae4e-f12d91a01d11",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Update contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create new contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Get the invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Notify the team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format data": {
      "main": [
        [
          {
            "node": "Check if the customer exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update contact": {
      "main": [
        [
          {
            "node": "Create the invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get the invoice": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create new contact": {
      "main": [
        [
          {
            "node": "Create the invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create the invoice": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Receive form submission": {
      "main": [
        [
          {
            "node": "Format data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if the customer exists": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}