{
  "id": "qRoag4rvcWiquEix",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI-Powered Live Cricket Score Commentary using SerpAPI, GPT-4o-mini, and Telegram",
  "tags": [],
  "nodes": [
    {
      "id": "3e221697-8448-4bbf-a0ca-f5b0633a188a",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        -528
      ],
      "parameters": {
        "width": 568,
        "height": 508,
        "content": "## \ud83c\udfcf Live Cricket Score Commentator Bot\n\n### How it works\nThis workflow runs every 10 seconds, fetches live cricket scores for India matches via SerpAPI, extracts the latest match details, and passes them to an AI agent. The agent generates a short, commentary-style match summary and sends it directly to a Telegram chat. If the AI step fails, an error email is dispatched automatically.\n\n### Setup steps\n1. **SerpAPI** \u2014 Connect your SerpAPI credential and confirm the search query targets your preferred match/team.\n2. **OpenAI** \u2014 Add your OpenAI API key under the `OpenAI Chat Model` node.\n3. **Telegram** \u2014 Set up your Telegram Bot token and replace the `chatId` with your target chat or group ID.\n4. **Gmail** \u2014 Connect a Gmail OAuth2 account for error alert emails. Update the recipient address.\n5. **Slack (optional)** \u2014 Link a Slack credential for the `Alert on Workflow Failure` node and select the right channel.\n6. Activate the workflow and monitor the first few executions to confirm data flows correctly."
      },
      "typeVersion": 1
    },
    {
      "id": "de46536d-6e46-4868-a60d-b704efe2f81c",
      "name": "Section: Trigger & Fetch",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 444,
        "height": 336,
        "content": "## \u23f1 Trigger & Live Data Fetch\nFires every 10 seconds and queries Google (via SerpAPI) for real-time India cricket scores. Adjust the interval or search query here if you want less frequent updates or a different team."
      },
      "typeVersion": 1
    },
    {
      "id": "f468336d-08f2-4b8e-bb92-d71aa4011aac",
      "name": "Section: Extract & Validate",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 492,
        "height": 352,
        "content": "## \ud83d\udd0d Extract & Validate Match Data\nParses the raw SerpAPI response to pull the latest match \u2014 team names, scores, result, and tournament. The `If` node skips execution entirely when no match result is present, preventing empty AI prompts."
      },
      "typeVersion": 1
    },
    {
      "id": "afd2786f-f8d9-4c42-b657-5b4903f847b9",
      "name": "Section: AI Agent",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 412,
        "height": 592,
        "content": "## \ud83e\udd16 AI Commentary Generator\nThe AI Agent uses GPT-4o-mini to turn raw match data into a structured, expert-tone summary \u2014 covering match result, key turning point, standout performer, and a tactical insight. Edit the prompt inside the `AI Agent` node to adjust tone or output format."
      },
      "typeVersion": 1
    },
    {
      "id": "f2eb33f4-603f-428c-88ea-7c8256ba7e11",
      "name": "Section: Deliver & Alert",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1200,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 476,
        "height": 608,
        "content": "## \ud83d\udcf2 Deliver & Alert\nOn success, the formatted commentary is sent to a Telegram chat using Markdown. On AI failure, a Gmail alert is dispatched so you can follow up manually. A separate error trigger also posts to a Slack channel for any workflow-level failures."
      },
      "typeVersion": 1
    },
    {
      "id": "b65bc9ad-253a-491e-9a52-509e21f411ef",
      "name": "Section: Security",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1712,
        608
      ],
      "parameters": {
        "color": 3,
        "width": 316,
        "height": 178,
        "content": "## \ud83d\udd10 Credentials & Security\nUse named credentials for SerpAPI, OpenAI, Telegram, Gmail, and Slack. Never hardcode API keys or tokens directly in node parameters. Replace any personal emails or workspace IDs with placeholders before sharing this template."
      },
      "typeVersion": 1
    },
    {
      "id": "61929665-a8d0-4b0d-a585-1f84618bd41c",
      "name": "Every 10 Seconds Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -224,
        176
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "seconds",
              "secondsInterval": 10
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "fae55871-defa-40ff-8a21-23e64bba1757",
      "name": "Fetch Live Cricket Score",
      "type": "n8n-nodes-serpapi.serpApi",
      "position": [
        0,
        176
      ],
      "parameters": {
        "q": "cricket live score india match",
        "location": "India",
        "requestOptions": {},
        "additionalFields": {}
      },
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "acb3f5de-5a8a-45f7-8186-88a73a75996c",
      "name": "Extract Latest Match Data",
      "type": "n8n-nodes-base.function",
      "position": [
        272,
        176
      ],
      "parameters": {
        "functionCode": "const games = $json.sports_results?.games || [];\n\n// take latest match\nconst match = games[0];\n\nreturn [{\n  json: {\n    team1: match.teams[0].name,\n    team2: match.teams[1].name,\n    score1: match.teams[0].score,\n    score2: match.teams[1].score,\n    result: match.status,\n    tournament: match.tournament\n  }\n}];"
      },
      "typeVersion": 1
    },
    {
      "id": "e6a0650c-be4a-4ee5-a999-9d9e4c5ab015",
      "name": "Skip If No Match Result",
      "type": "n8n-nodes-base.if",
      "position": [
        544,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1fa7e787-e894-4fb7-90c1-a59e3a179a88",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.result }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "9b255df1-17f5-42f0-8296-4ad41ef760f3",
      "name": "Generate AI Match Commentary",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueErrorOutput",
      "position": [
        864,
        160
      ],
      "parameters": {
        "text": "=You are an expert cricket analyst and commentator.\n\nAnalyze the following cricket match data and generate a short, engaging insight like a professional commentator.\n\nMatch: {{$json.team1}} vs {{$json.team2}}\nTournament: {{$json.tournament}}\n\nScores:\n{{$json.team1}}: {{$json.score1}}\n{{$json.team2}}: {{$json.score2}}\n\nResult:\n{{$json.result}}\n\n---\n\nGive output in this format:\n\n\ud83c\udfcf Match Summary:\n(1\u20132 lines explaining what happened)\n\n\ud83d\udd25 Key Turning Point:\n(what changed the game)\n\n\ud83c\udf1f Best Performance:\n(top player or highlight moment)\n\n\ud83e\udde0 Tactical Insight:\n(strategy or learning from the match)\n\n---\n\nRules:\n- Keep it short and crisp\n- Sound like a real cricket expert\n- No generic AI phrases\n- Make it engaging (like commentary)",
        "options": {},
        "promptType": "define"
      },
      "retryOnFail": false,
      "typeVersion": 3
    },
    {
      "id": "cd50b514-305e-4adc-85cc-4f5cf006a671",
      "name": "OpenAI GPT-4o-mini Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        784,
        384
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "d8f10921-8829-449b-a5db-8a91b151ba5c",
      "name": "Send Commentary to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1376,
        64
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=YOUR_TELEGRAM_CHAT_ID",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "ead4ae8c-4ab3-4482-84f7-6cb7109c943b",
      "name": "Email Alert on AI Failure",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1360,
        368
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=:warning: *AI Commentary Generation Failed*\n\nThe AI agent encountered an error. Please check the n8n execution log and follow up manually if needed.",
        "options": {},
        "subject": "Error occurred in Cricket Score Workflow"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "21a02a10-b4b1-4867-a160-998534f49f91",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        608
      ],
      "parameters": {
        "color": 7,
        "width": 492,
        "height": 400,
        "content": "## \u26a0\ufe0f Error Monitoring\n\nCatches any workflow failures and sends alerts to Slack's general-information channel. Helps maintain reliability and enables quick troubleshooting."
      },
      "typeVersion": 1
    },
    {
      "id": "99937587-f311-4ee3-b5d9-7e349849def2",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -288,
        800
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "e5e83fef-991d-477d-ab16-b82e82809037",
      "name": "Alert on Workflow Failure",
      "type": "n8n-nodes-base.slack",
      "position": [
        -32,
        800
      ],
      "parameters": {
        "text": "\u26a0\ufe0f Hotel Pre-Arrival Workflow Error Detected\n\nPlease check the execution log for details.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09GNB90TED",
          "cachedResultName": "workflow-errors"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f51fcbae-2de7-4ee0-8f3a-58134657da7f",
  "connections": {
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Alert on Workflow Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip If No Match Result": {
      "main": [
        [
          {
            "node": "Generate AI Match Commentary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every 10 Seconds Trigger": {
      "main": [
        [
          {
            "node": "Fetch Live Cricket Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Live Cricket Score": {
      "main": [
        [
          {
            "node": "Extract Latest Match Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4o-mini Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate AI Match Commentary",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Email Alert on AI Failure": {
      "main": [
        [
          {
            "node": "Fetch Live Cricket Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Latest Match Data": {
      "main": [
        [
          {
            "node": "Skip If No Match Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate AI Match Commentary": {
      "main": [
        [
          {
            "node": "Send Commentary to Telegram",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email Alert on AI Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}