{
  "name": "Northwind Studio bot",
  "nodes": [
    {
      "id": "c91fec10-b78f-45bd-9694-ad636dc725a6",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.5,
      "position": [
        0,
        300
      ],
      "parameters": {
        "updates": [
          "message",
          "callback_query"
        ],
        "additionalFields": {}
      }
    },
    {
      "id": "2dd56254-e779-4518-a472-2fd140d0d9fd",
      "name": "What came in?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "37c5d180-c6be-418d-b9c6-a9b40ba2e031",
                    "leftValue": "={{ $json.callback_query }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Button tap"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "3a3b5e1c-bd45-4b02-8896-f8e33e077a18",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "/start",
                    "operator": {
                      "type": "string",
                      "operation": "startsWith"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "/start"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "19ee2744-22fe-4a80-95f8-4fac9f2d4e93",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Text"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "d6dc9b91-2944-40cd-8245-8987f7310ab7",
      "name": "Answer the tap",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        480,
        60
      ],
      "parameters": {
        "resource": "callback",
        "queryId": "={{ $json.callback_query.id }}",
        "additionalFields": {}
      }
    },
    {
      "id": "1c194c4b-1c75-4990-96ef-51b499aaa9a7",
      "name": "Which button?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        700,
        60
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "10935003-ea83-480b-b536-cc9475684acf",
                    "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.data }}",
                    "rightValue": "ask",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Ask"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "35eb7b69-a445-4c4f-92ec-8affc4fcee41",
                    "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.data }}",
                    "rightValue": "quote",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Quote"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "4f242f50-5043-480d-8436-f0dde9cb64e0",
                    "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.data }}",
                    "rightValue": "back",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Back"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "27348ca2-0854-403c-8c4c-a86992d1e0bd",
                    "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.data }}",
                    "rightValue": "svc_",
                    "operator": {
                      "type": "string",
                      "operation": "startsWith"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Service"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "0b28fbe1-bde4-4906-a20e-0ca7993c1bcb",
      "name": "Invite a question",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        980,
        -180
      ],
      "parameters": {
        "operation": "editMessageText",
        "chatId": "={{ $('Telegram Trigger').item.json.callback_query.message.chat.id }}",
        "messageId": "={{ $('Telegram Trigger').item.json.callback_query.message.message_id }}",
        "text": "Sure. Type your question and I'll answer.",
        "additionalFields": {}
      }
    },
    {
      "id": "471feeb3-55a4-495f-801c-16f5fa41567d",
      "name": "Show services",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        980,
        -20
      ],
      "parameters": {
        "operation": "editMessageText",
        "chatId": "={{ $('Telegram Trigger').item.json.callback_query.message.chat.id }}",
        "messageId": "={{ $('Telegram Trigger').item.json.callback_query.message.message_id }}",
        "text": "What do you need a quote for?",
        "additionalFields": {},
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "Website",
                    "additionalFields": {
                      "callback_data": "svc_website"
                    }
                  },
                  {
                    "text": "Online store",
                    "additionalFields": {
                      "callback_data": "svc_store"
                    }
                  }
                ]
              }
            },
            {
              "row": {
                "buttons": [
                  {
                    "text": "Something else",
                    "additionalFields": {
                      "callback_data": "svc_other"
                    }
                  }
                ]
              }
            },
            {
              "row": {
                "buttons": [
                  {
                    "text": "← Back",
                    "additionalFields": {
                      "callback_data": "back"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    },
    {
      "id": "5368a9a1-fd25-4c49-aac8-4e904305b021",
      "name": "Back to main menu",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        980,
        140
      ],
      "parameters": {
        "operation": "editMessageText",
        "chatId": "={{ $('Telegram Trigger').item.json.callback_query.message.chat.id }}",
        "messageId": "={{ $('Telegram Trigger').item.json.callback_query.message.message_id }}",
        "text": "=Hi {{ $('Telegram Trigger').item.json.callback_query.from.first_name }}! I'm the Northwind Studio bot. What can I do for you?",
        "additionalFields": {},
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "💬 Ask a question",
                    "additionalFields": {
                      "callback_data": "ask"
                    }
                  }
                ]
              }
            },
            {
              "row": {
                "buttons": [
                  {
                    "text": "📋 Get a quote",
                    "additionalFields": {
                      "callback_data": "quote"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    },
    {
      "id": "811305c0-d914-4cb6-8be0-c9f9ee7e0dcc",
      "name": "Notify the team",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        980,
        300
      ],
      "parameters": {
        "chatId": "-1001234567890",
        "text": "=New quote request: {{ $('Telegram Trigger').item.json.callback_query.data }}\nFrom: {{ $('Telegram Trigger').item.json.callback_query.from.first_name }} (@{{ $('Telegram Trigger').item.json.callback_query.from.username }})",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "fb12aa5c-2713-4ae5-b66f-0fd5edd49e49",
      "name": "Confirm to the customer",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1200,
        300
      ],
      "parameters": {
        "operation": "editMessageText",
        "chatId": "={{ $('Telegram Trigger').item.json.callback_query.message.chat.id }}",
        "messageId": "={{ $('Telegram Trigger').item.json.callback_query.message.message_id }}",
        "text": "Thanks! We'll message you here within one working day.",
        "additionalFields": {}
      }
    },
    {
      "id": "2fa22fc5-666f-4cef-aa13-316182d27783",
      "name": "Send main menu",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        480,
        480
      ],
      "parameters": {
        "chatId": "={{ $json.message.chat.id }}",
        "text": "=Hi {{ $json.message.from.first_name }}! I'm the Northwind Studio bot. What can I do for you?",
        "additionalFields": {
          "appendAttribution": false
        },
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "💬 Ask a question",
                    "additionalFields": {
                      "callback_data": "ask"
                    }
                  }
                ]
              }
            },
            {
              "row": {
                "buttons": [
                  {
                    "text": "📋 Get a quote",
                    "additionalFields": {
                      "callback_data": "quote"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    },
    {
      "id": "eaf8005e-05ee-4fd3-a52e-3cddc219919d",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        480,
        680
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Telegram Trigger').item.json.message.text }}",
        "options": {
          "systemMessage": "You are the assistant of Northwind Studio, a small web design studio. Answer in two or three short sentences. If you do not know, say that a person from the team will follow up."
        }
      }
    },
    {
      "id": "5b8d4036-0927-461b-be08-23db8ac9f065",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        440,
        900
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "options": {}
      }
    },
    {
      "id": "f068857e-5953-46ab-bb23-0b6a60f74074",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        600,
        900
      ],
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "contextWindowLength": 10
      }
    },
    {
      "id": "e7c8d6f3-2ebf-4836-95ca-6f501897e69f",
      "name": "Send the answer",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        860,
        680
      ],
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "What came in?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "What came in?": {
      "main": [
        [
          {
            "node": "Answer the tap",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send main menu",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Answer the tap": {
      "main": [
        [
          {
            "node": "Which button?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Which button?": {
      "main": [
        [
          {
            "node": "Invite a question",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Show services",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Back to main menu",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify the team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify the team": {
      "main": [
        [
          {
            "node": "Confirm to the customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send the answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}