{
  "id": "9ElwM3xJyiw4my1L",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Airbnb Telegram Agent - Template",
  "tags": [],
  "nodes": [
    {
      "id": "380df1f8-7d7a-4c50-abd3-cf31b09084e1",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -540,
        320
      ],
      "parameters": {
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "209d3ae6-19c5-455a-88fd-72ebd2ee0807",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -660,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c04d2f36-b275-45de-850e-35046a0e21f0",
      "name": "Airbnb MCP Client - List Tools",
      "type": "n8n-nodes-mcp.mcpClientTool",
      "position": [
        -420,
        320
      ],
      "parameters": {},
      "credentials": {
        "mcpClientApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6d71b756-431e-4970-a7bf-b5f7f190cc5f",
      "name": "Airbnb MCP Client - Execute Tools",
      "type": "n8n-nodes-mcp.mcpClientTool",
      "position": [
        -300,
        320
      ],
      "parameters": {
        "toolName": "={{ $fromAI(\"tool\", \"Das ausgew\u00e4hlte Tool\") }}",
        "operation": "executeTool",
        "toolParameters": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Tool_Parameters', `Die Parameter f\u00fcr das Tool`, 'json') }}"
      },
      "credentials": {
        "mcpClientApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3103776d-b39e-431e-a72d-cbaf5dc70ef7",
      "name": "Airbnb Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -568,
        100
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=<system_prompt>\nYOU ARE A HIGHLY SPECIALIZED **AIRBNB EXPERT AGENT** INTEGRATED INTO **n8n**. YOUR TASK IS TO ANSWER AIRBNB ACCOMMODATION QUERIES PRECISELY BY USING THE **MCP (Modular Command Platform)** AND PRESENTING THE INFORMATION IN **MOBILE-FRIENDLY FORMAT FOR TELEGRAM**.\n\nCURRENT DATE AND TIME: {{ $now }}\n\n---\n\n###TOOL USAGE###\n\nYOU HAVE ACCESS TO TWO MCP TOOLS:\n\n- `Airbnb MCP Client - List Tools` \u2192 SHOWS ALL AVAILABLE MCP FUNCTIONS\n- `Airbnb MCP Client - Execute Tools` \u2192 EXECUTES THE SELECTED TOOL WITH PARAMETERS\n\n\u26a0\ufe0f **IMPORTANT**: ALWAYS RUN `LIST TOOLS` FIRST \u2192 THEN `EXECUTE TOOLS` WITH THE APPROPRIATE TOOL!\n\n---\n\n###CHAIN OF THOUGHTS \u2013 WORK STEPS###\n\n1. **UNDERSTAND**: ANALYZE THE QUERY (e.g., location, time period, price limit, special requirements)\n2. **BASICS**: CLARIFY WHETHER IT'S ABOUT A LIST, DETAILS, OR COMPARISON\n3. **BREAK DOWN**: PARSE RELEVANT PARAMETERS FROM THE QUERY\n4. **ANALYZE**: CALL `LIST TOOLS` TO GET ALL AVAILABLE OPTIONS\n5. **BUILD**: SELECT THE RIGHT TOOL AND USE `EXECUTE TOOLS` WITH PRECISE PARAMETERS\n6. **FORMAT**: FORMAT THE OUTPUT FOR **MOBILE/TELEGRAM** \u2013 NO TABLES!\n7. **FINAL OUTPUT**: FOR EACH ACCOMMODATION, USE THIS FORMAT:\n\n\ud83c\udfe1 {Accommodation Name}\n\ud83d\udecf\ufe0f {Beds, Bedrooms}\n\ud83d\udcb6 {Price/Night} \u2013 Total: {Total Price}\n\u2728 {Special Feature, if available}\n\ud83d\udd17 [View]({URL to accommodation})\n\n\ud83d\udccc *IMPORTANT: THE URL MUST BE WITHIN THE BRACKETS, OTHERWISE THE LINK WON'T BE CLICKABLE ON TELEGRAM!*\n\n---\n\n###EXAMPLE OUTPUT FOR TELEGRAM###\n\nHere are accommodations in Allg\u00e4u for 2 people from May 28-30, 2025:\n\n\ud83c\udfe1 Sandra's apartment in the countryside\n\ud83d\udecf\ufe0f 2 beds\n\ud83d\udcb6 \u20ac82/night \u2013 Total: \u20ac164\n\u2728 Guest favorite\n\ud83d\udd17 View\n\n\ud83c\udfe1 Villa Kunterbunt in Allg\u00e4u\n\ud83d\udecf\ufe0f 2 single beds\n\ud83d\udcb6 \u20ac137/night \u2013 Total: \u20ac274\n\u2728 Guest favorite\n\ud83d\udd17 View\n\n\ud83d\udd0e More results & filters:\n\u2192 All accommodations for 2 people in Allg\u00e4u (May 28-30, 2025)\n\n\ud83d\udc49 Let me know if you want details about any accommodation like amenities, photos, or cancellation policies!\n</system_prompt>"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "3860e787-78a7-4211-a7c3-f4b3fcf4fb60",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1540,
        100
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "442e9229-5576-4193-a629-b7343eb62f1b",
      "name": "Text or Voice",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1320,
        100
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7c629699-9dd6-4a75-9b76-d796875f9ac9",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Voice",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "0e56bc7f-c754-4f5e-9ddd-7124e1f5d998",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.voice }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "6ecbc049-1c0d-4e93-886a-6a99f584dfd3",
      "name": "Get Voice Message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1100,
        200
      ],
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c88de1a5-d775-467d-99ba-ee2bba985109",
      "name": "Prepare Text Message for AI Agent",
      "type": "n8n-nodes-base.set",
      "position": [
        -880,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a5bcf087-7580-4904-88d3-ca29614fc923",
              "name": "text",
              "type": "string",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ffb9dfef-5b76-446f-9b4f-cb6ea1766375",
      "name": "Send Text Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -22,
        0
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "afbe65f9-8576-4217-8eea-4413a8aa8657",
      "name": "Send Voice Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        496,
        200
      ],
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "operation": "sendAudio",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e1171f41-47e0-4821-80fa-d1350c6b6d99",
      "name": "Create Voice Response",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        276,
        200
      ],
      "parameters": {
        "input": "={{ $json.text }}",
        "options": {},
        "resource": "audio"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "c31a642c-068f-4b63-ac89-4530377f8a52",
      "name": "Summarize Response for Voice",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -100,
        200
      ],
      "parameters": {
        "text": "=Summarize the given input briefly and clearly for voice output. The text should be well-structured and understandable when listened to.\n\n## Input\nYou receive structured information about Airbnb accommodations containing emojis, links, formatting, and detailed descriptions.\n\n## Output Guidelines\n\n### Structure & Format\n- **Remove all emojis** and visual formatting\n- **No links** or URLs mentioned\n- Use **natural, spoken language**\n- Structure information **logically and chronologically**\n- Keep sentences **short and concise**\n\n### Content Priorities\n\n#### For Accommodation Lists:\n1. **Mention number of found accommodations**\n2. **Price range** (cheapest to most expensive option)\n3. **2-3 most interesting options** with name, price, and key feature\n4. Brief note about **additional available options**\n\n#### For Accommodation Details:\n1. **Name and basic data** (guest count, room type)\n2. **Price per night**\n3. **3-4 most important amenities**\n4. **Key house rules** (check-in/out, guest limit)\n5. **Location highlights** (distance to important points)\n\n#### For Cancellation Policies:\n1. **Type of cancellation policy** (flexible/moderate/strict)\n2. **Deadlines for free cancellation**\n3. **Refund rates** after cancellation deadlines\n4. **Important note** that final conditions are shown at booking\n\n### Language Style\n- Use **\"you\"** as address form\n- **Direct, friendly language**\n- **No technical terms** without explanation\n- **Spell out numbers** up to twenty\n- **Time references** in natural form (\"seven days before\" instead of \"7 days\")\n\n### Length\n- **Maximum 150 words** for lists\n- **Maximum 100 words** for single objects\n- **Maximum 80 words** for cancellation policies\n\n## Example Transformation\n\n**Input:** Long formatted list with 7 accommodations, emojis, links\n**Output:** \"I found seven accommodations in Scheveningen for May thirty-first. Prices range from seventy-three to two hundred nine euros per night. Particularly interesting are the affordable room near TU Delft for seventy-three euros, the cozy room near beach and center for ninety-one euros, and the studio apartment with Superhost status for two hundred nine euros. All accommodations offer various amenities and locations to choose from.\"\n\n## Technical Implementation in n8n\n\n### Node Configuration\n- **Node Type:** Basic LLM Chain\n- **Model:** GPT-4 or comparable\n- **Temperature:** 0.3 (for consistent, factual outputs)\n- **Max Tokens:** 200\n\n### Prompt Template\n```\nSummarize the following Airbnb information briefly and understandably for voice output. \n\nConsider:\n- No emojis, links, or formatting\n- Natural, spoken language\n- Maximum 150 words\n- Most important information first\n- Friendly, informative tone\n\nInput: {{ $json.output }}\n\nSummary:\n```\n\n### Input Mapping\n- Connect the output of the previous node with the `input` parameter\n- Use the `output` property of the JSON array as input\n\n### Output Processing\n- The summarized text can be passed directly to Text-to-Speech services\n- Or for further processing in downstream nodes",
        "batching": {},
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "598891da-ece9-4ef1-a3a7-bcc11ab31d19",
      "name": "Transcribe Voice Message",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -880,
        200
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "5b9a2516-4b8e-42c2-869d-1f8d85d279ba",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2620,
        -480
      ],
      "parameters": {
        "width": 1040,
        "height": 1280,
        "content": "# Welcome to my Airbnb Telegram Agent Workflow!\n\n## This workflow has the following sequence:\n\n1. **Telegram Trigger** - Receives incoming messages (text or voice) from Telegram users\n2. **Text or Voice Switch** - Routes the workflow based on message type (text vs. voice)\n3. **Voice Processing Path** (if voice message):\n   - Get Voice Message - Downloads the voice file from Telegram\n   - Transcribe Voice Message - Converts speech to text using OpenAI Whisper\n4. **Text Processing Path** - Prepares text messages for the AI agent\n5. **Airbnb Agent (Core Logic)** - LangChain agent that:\n   - Uses conversation memory to maintain context\n   - Lists available MCP tools for Airbnb data access\n   - Executes appropriate tools with parsed parameters\n   - Formats results for mobile/Telegram display\n6. **Response Generation**:\n   - Send Text Response - Sends formatted text back to Telegram\n   - Summarize Response for Voice - Creates voice-friendly summary\n   - Create Voice Response - Converts summary to speech using OpenAI TTS\n   - Send Voice Response - Sends audio message back to Telegram\n\n## The following accesses are required for the workflow:\n\n- **Telegram Bot API**: [Documentation](https://docs.n8n.io/integrations/builtin/credentials/telegram/) \n  - Create a bot via @BotFather on Telegram\n  - Get bot token and configure webhook\n- **OpenAI API**: [Documentation](https://docs.n8n.io/integrations/builtin/credentials/openai/)\n  - Used for speech transcription (Whisper)\n  - Used for chat completion (GPT-4)\n  - Used for text-to-speech generation\n- **MCP Community Client Node**: [Documentation](https://github.com/nerding-io/n8n-nodes-mcp)\n  - Custom integration for Airbnb data\n  - Requires MCP server setup with Airbnb/Airtable connection\n  - Provides tools for accommodation search and details\n\n## Key Features:\n\n- **Multimodal Support**: Handles both text and voice messages\n- **Conversation Memory**: Maintains context across multiple messages\n- **Mobile-Optimized Output**: Formats results specifically for Telegram mobile viewing\n- **Tool Integration**: Uses MCP platform to access real Airbnb data\n- **Voice Capabilities**: Full speech-to-text and text-to-speech support\n\n## Configuration Notes:\n\n- Uses GPT-4.1 model for enhanced reasoning capabilities\n- Includes comprehensive system prompts for Airbnb-specific responses\n- Voice responses are automatically summarized for better audio experience\n\nYou can contact me via LinkedIn, if you have any questions: https://www.linkedin.com/in/friedemann-schuetz"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b2664114-a335-4dbb-a47b-0feebed5807d",
  "connections": {
    "Airbnb Agent": {
      "main": [
        [
          {
            "node": "Send Text Response",
            "type": "main",
            "index": 0
          },
          {
            "node": "Summarize Response for Voice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Airbnb Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Text or Voice": {
      "main": [
        [
          {
            "node": "Prepare Text Message for AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Voice Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Text or Voice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Voice Message": {
      "main": [
        [
          {
            "node": "Transcribe Voice Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Airbnb Agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Summarize Response for Voice",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create Voice Response": {
      "main": [
        [
          {
            "node": "Send Voice Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Voice Message": {
      "main": [
        [
          {
            "node": "Airbnb Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize Response for Voice": {
      "main": [
        [
          {
            "node": "Create Voice Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airbnb MCP Client - List Tools": {
      "ai_tool": [
        [
          {
            "node": "Airbnb Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Airbnb MCP Client - Execute Tools": {
      "ai_tool": [
        [
          {
            "node": "Airbnb Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Text Message for AI Agent": {
      "main": [
        [
          {
            "node": "Airbnb Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}