{
  "id": "kPEqMYdlMwW08JG1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "JiraAgent",
  "tags": [],
  "nodes": [
    {
      "id": "87eb83d5-fad5-45d1-bc23-3adcff7c8842",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -240,
        192
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "467060d3-80da-44c3-b52a-a1fb9d78fcd4",
      "name": "Try Again",
      "type": "n8n-nodes-base.set",
      "position": [
        672,
        48
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7ab380a2-a8d3-421c-ab4e-748ea8fb7904",
              "name": "response",
              "type": "string",
              "value": "Unable to perform task. Please try again."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b223b489-de88-412d-92dc-5ce5b5fa9093",
      "name": "Delete an issue in Jira Software",
      "type": "n8n-nodes-base.jiraTool",
      "position": [
        176,
        352
      ],
      "parameters": {
        "issueKey": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Issue_Key', ``, 'string') }}",
        "operation": "delete"
      },
      "typeVersion": 1
    },
    {
      "id": "9de0b6bf-bc56-4973-b8fd-35643034463d",
      "name": "Update an issue in Jira Software",
      "type": "n8n-nodes-base.jiraTool",
      "position": [
        448,
        320
      ],
      "parameters": {
        "issueKey": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Issue_Key', ``, 'string') }}",
        "operation": "update",
        "updateFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "282dd679-5d62-4b00-b9ab-5686da85fd9e",
      "name": "Jira Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueErrorOutput",
      "position": [
        16,
        -80
      ],
      "parameters": {
        "text": "={{ $json.text }}{{ $json.data }}",
        "options": {
          "systemMessage": "=You are a Jira assistant. Your responsibilities include creating, retrieving, updating, and managing Jira issues such as epics, stories, tasks, and bugs. You can also transition issues to the \"Done\" state.\n\nJira Management Tools\n\nUse \"Create Issue\" to create new tasks, stories, epics, or bugs. Specify the issue type and required fields (e.g., summary, project, and description).\n\nUse \"Get Issue\" to retrieve details about a specific issue. Requires the issue key (e.g., SCRUM-123) or the issue name.\n\nUse \"Update Issue\" to change fields like summary, description, priority, or assignee. Requires the issue key.\n\nUse \"Transition Issue\" to move an issue to another status (e.g., move to \"Done\"). Use \"Get Issue\" first to retrieve the list of available transitions.\n\nUse \"Search Issues\" to find issues using JQL (Jira Query Language). Useful for filtering by assignee, project, status, etc.\n\nFinal Notes\nHere is the current date/time: {{ $now }}\nIf the issue type isn\u2019t specified, default to Story.\nIf transitioning to \"Done\", ensure the issue is in a status that allows that transition."
        },
        "promptType": "define"
      },
      "typeVersion": 1.6
    },
    {
      "id": "c17f65ec-96ba-48a1-abfa-47d6a11aa301",
      "name": "Get many issues in Jira Software1",
      "type": "n8n-nodes-base.jiraTool",
      "position": [
        16,
        352
      ],
      "parameters": {
        "options": {},
        "operation": "getAll"
      },
      "typeVersion": 1
    },
    {
      "id": "a47f63fb-6a84-4f04-bae8-c100a9c43494",
      "name": "Create an issue in Jira Software",
      "type": "n8n-nodes-base.jiraTool",
      "position": [
        304,
        352
      ],
      "parameters": {
        "project": {
          "__rl": true,
          "mode": "list",
          "value": "10000",
          "cachedResultName": "HumbleTurtle"
        },
        "summary": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Summary', ``, 'string') }}",
        "issueType": {
          "__rl": true,
          "mode": "list",
          "value": "10003",
          "cachedResultName": "Story"
        },
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "963f8359-9548-4b17-b155-53b39855ae92",
      "name": "Get the status of an issue in Jira Software",
      "type": "n8n-nodes-base.jiraTool",
      "position": [
        592,
        240
      ],
      "parameters": {
        "issueKey": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Issue_Key', ``, 'string') }}",
        "operation": "transitions",
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "73c165c7-3014-41f1-8ed4-186d6efcd9a2",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -512
      ],
      "parameters": {
        "color": 6,
        "width": 248,
        "height": 388,
        "content": "## Jira Agent\nA smart assistant that manages Jira directly from messages from Telegram. Messages are interpreted using Open AI's GPT-4o model.\n\n- Create issues (Story by default): tasks, bugs, epics\n- Get issue details using key or name\n- Update issues: summary, description, priority, assignee\n- Transition issues (e.g., to \"Done\") \u2014 only if valid\n- Search issues using JQL for advanced filtering"
      },
      "typeVersion": 1
    },
    {
      "id": "42805ff0-5bc1-446b-8510-55f63fc42059",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        528
      ],
      "parameters": {
        "color": 6,
        "content": "## JIRA actions\n- Get all issues\n- Create new issues\n- Delete issues\n- Update issues\n- Get status of issues"
      },
      "typeVersion": 1
    },
    {
      "id": "0d5fbde7-c305-46ec-ab26-a017743713b5",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1024,
        -112
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "2502ad6c-98be-457c-ab58-8022d4a05c74",
      "name": "Set 'Text'",
      "type": "n8n-nodes-base.set",
      "position": [
        -864,
        -112
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fe7ecc99-e1e8-4a5e-bdd6-6fce9757b234",
              "name": "text",
              "type": "string",
              "value": "={{ $json.message.text }}"
            },
            {
              "id": "d5e3a384-033d-44d3-9c74-af9cecf90de1",
              "name": "chat_id",
              "type": "string",
              "value": "={{$json[\"message\"]?.chat?.id}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "337ac77d-3e8d-4bac-813b-0b5da3706d45",
      "name": "Extract Task",
      "type": "n8n-nodes-base.function",
      "position": [
        -704,
        -112
      ],
      "parameters": {
        "functionCode": "const input = $json[\"text\"]?.toLowerCase().trim() || \"\";\nconst chatId = $json[\"chat_id\"]; // you must ensure chat_id is passed in\n\nif ((input.startsWith(\"create story\"))) {\n  const parts = input.split(\" \");\n  const task = parts.slice(2).join(\" \").trim();\n  return [{\n    json: {\n      task,\n      type: parts[1],\n      chat_id: chatId,\n      should_respond: true,\n      form_prompt: `Let's create a new ${parts[1]}.\\n\\nPlease answer the following:\\n\\nTitle:\\nSummary:\\nDue date (YYYY-MM-DD):\\nDuration (in hours):`,\n      original_message: $json[\"text\"] || \"\"\n    }\n  }];\n}\n\nreturn [{\n  json: {\n    chat_id: chatId,\n    original_message: $json[\"text\"] || \"\",\n    should_respond: false\n  }\n}];\n"
      },
      "typeVersion": 1
    },
    {
      "id": "965604d0-75c4-4e37-8b4e-7eb226eb587a",
      "name": "Send a text message1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -352,
        -256
      ],
      "parameters": {
        "chatId": "={{ $json.chat_id }}",
        "message": "={{ $json.form_prompt }}",
        "options": {},
        "operation": "sendAndWait",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Title",
              "placeholder": "eg. create health dashboard",
              "requiredField": true
            },
            {
              "fieldLabel": "Summary",
              "placeholder": "eg. should contain the vpv percentage"
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "Due date",
              "fieldOptions": {
                "values": [
                  {
                    "option": "today"
                  },
                  {
                    "option": "tomorrow"
                  },
                  {
                    "option": "this week"
                  },
                  {
                    "option": "within 2 weeks"
                  },
                  {
                    "option": "this month"
                  },
                  {
                    "option": "this quarter"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Duration (in hours)",
              "placeholder": "1",
              "requiredField": true
            }
          ]
        },
        "responseType": "customForm"
      },
      "typeVersion": 1.2
    },
    {
      "id": "f0c799f8-751d-4d98-98c4-76ff67a0091b",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        -544,
        -112
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ca74ddb7-495e-4a29-97cc-8d568e16f728",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.should_respond }}",
              "rightValue": "True"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7547894f-50d0-4ade-b816-b9a3699c3af7",
      "name": "Set 'Text'1",
      "type": "n8n-nodes-base.set",
      "position": [
        -224,
        -80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fe7ecc99-e1e8-4a5e-bdd6-6fce9757b234",
              "name": "text",
              "type": "string",
              "value": "={{ $json.original_message }}"
            },
            {
              "id": "d5e3a384-033d-44d3-9c74-af9cecf90de1",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $json.chat_id }}"
            },
            {
              "id": "ba588e4a-bbf8-42a7-95a3-600f4bc12aa0",
              "name": "original_message",
              "type": "string",
              "value": "={{ $json.original_message }}"
            },
            {
              "id": "4298249a-f15a-4acf-ac49-72a884247373",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e6f05603-d69d-4241-b56c-7dc881e6a20e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        -1872
      ],
      "parameters": {
        "color": 5,
        "width": 2468,
        "height": 396,
        "content": "# Manage Jira Issues with Natural Language via Telegram and GPT-4o'\n### Overview\nThe Jira Agent is an AI-powered assistant that allows users to interact with Jira directly through messaging platform Telegram. It leverages OpenAI's GPT-4o model to interpret natural language commands and perform various Jira-related actions. On Telegram, it enables users to create Jira stories by triggering a guided form when prompted with \"create story.\" Additionally, it provides more extensive functionality, including creating, updating, searching, and transitioning Jira issues through natural language commands.\n\n### Requirements (*see instructions below for configuration steps*)\nTo use the Jira Agent effectively, users need access to:\n- A Telegram account, Telegram setup involves deploying the bot and starting a chat; story creation is triggered with a simple text command.\n- A connected Jira workspace\n- Permissions to create and modify Jira issue\n- Access to GPT-4o API-key\n\n\n### Setup Time\n<15 minutes"
      },
      "typeVersion": 1
    },
    {
      "id": "8ae99243-df7a-4279-b3c0-8af0f2c48da9",
      "name": "Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        672,
        -160
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f1639c04-f250-4517-b769-13a93ca257f6",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        80
      ],
      "parameters": {
        "color": 6,
        "width": 384,
        "height": 288,
        "content": "## Telegram Messages\n### Normal interaction \nusing messages as \"Please give all my issues\".\n\n### Standardized process of creating stories: \n1. Message: \"create story\"\n2. Open the Form that telegrams responds back to you\n3. Fill in the essential story information in the form\n4. The story automatically gets created in your backlog. "
      },
      "typeVersion": 1
    },
    {
      "id": "a8e099ed-c4aa-4e60-9b74-50012df4a686",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        -1456
      ],
      "parameters": {
        "color": 3,
        "width": 816,
        "height": 848,
        "content": "## Configuring the Telegram bot\n### Step 1: Create a New Telegram Bot\n1. Open Telegram and search for @BotFather.\n2. Start a chat and type: /newbot\n3. Follow the prompts:\n    * Give your bot a name (this can be anything).\n    * Choose a username ending in bot (e.g., my_n8n_bot).\n4. BotFather will reply with a Token like this: Use this token to access the HTTP API:\n123456789:ABCDefghIJKlmnoPQRstuVWXYZ1234567890\n5. Save this token \u2014 you\u2019ll need it in n8n. \n\n### Step 2: Allow the Bot to Receive Messages\n1. Your bot won\u2019t work until a user (you) sends it a message to \u201cactivate\u201d it.\n2. In Telegram, search for your new bot using the username you created (e.g., @my_n8n_bot).\n3. Click Start or send any message (e.g., Hi) to the bot.\n4. This step is required so that Telegram recognizes that the bot is \"in use.\"\n\n### Step 3: Set Up the Telegram Credentials in n8n\n1. Open your n8n instance.\n2. Go to Settings \u2192 Credentials or directly to the Telegram Trigger node and click \u201cCreate New\u201d under Telegram API.\n3. Fill in the following:\n4. Name: Choose a name like My Telegram Bot.\n5. Bot Token: Paste the token you got from BotFather.\n6. Click Save.\n\n### Step 4: Create the Telegram Trigger Node\n1. In your n8n workflow, add a Telegram Trigger node.\n2. Configure it:\n    - Resource: Message\n    - Operation: Update\n    - Event: Message\n    - Credentials: Select the Telegram credentials you just created.\n\n### Step 5: Activate the Webhook (Important!)\n1. Telegram bots use webhooks, which require an active URL.\n2. To activate the webhook:\n    - Ensure your n8n instance is accessible via HTTPS with a valid public URL.\n    - If testing locally, use ngrok or similar.\n- Activate the workflow by switching the toggle to Active.\n- n8n will automatically register the webhook URL with Telegram.\n\n### Step 6: Test the Bot\n1. In Telegram, send a message to your bot.\n2. You should see the message appear in n8n in the execution logs (or in the connected flow).\n"
      },
      "typeVersion": 1
    },
    {
      "id": "63704731-cba3-4123-9552-a9c6126dba80",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        -1456
      ],
      "parameters": {
        "color": 3,
        "width": 816,
        "height": 848,
        "content": "## Configuring Jira\n### Step 1: Generate Your Jira API Token (Jira Cloud only)\n1. Go to https://id.atlassian.com/manage/api-tokens\n2. Click Create API token\n3. Give your token a label (e.g., n8n integration)\n4. Click Create, then copy the token shown\n5. Store the token securely \u2014 you'll need it in n8n\n\n### Step 2: Create Jira Credentials in n8n\n1. Open your n8n instance\n2. Go to Settings \u2192 Credentials or directly open the Jira node and click \"Create New\" under credentials\n3. Choose the appropriate type:\n    - Jira Software (Cloud) \u2192 for Atlassian-hosted Jira\n    - Jira Software Server \u2192 for self-hosted Jira instances\n\n### Step 3: Add and Configure the Jira Node in Your Workflow\n1. In your n8n workflow (after the Telegram Trigger node), add a Jira node\n2. Choose the Jira Resource and Operation you need:\n    - For creating an issue:\n    Resource: Issue\n    Operation: Create\n    - For updating an issue:\n    Resource: Issue\n    Operation: Update\n3. Select your Jira credentials (created in Step 2)\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b1d42508-5d94-4cec-9674-009412b6506e",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        -1456
      ],
      "parameters": {
        "color": 3,
        "width": 816,
        "height": 848,
        "content": "## Setting up OpenAI API access\n### Step 1: Get Your OpenAI API Key\n1. Go to https://platform.openai.com/account/api-keys\n2. Click \u201cCreate new secret key\u201d\n3. Give it a name (e.g., n8n-access)\n4. Copy the API key shown (it will look like sk-...)\n5. Save this key securely \u2014 you won\u2019t be able to see it again from OpenAI\n\n### Step 2: Add OpenAI Credentials in n8n\n1. Open your n8n instance\n2. Go to Settings \u2192 Credentials\n3. Click \u201cNew Credential\u201d and select OpenAI\n4. In the credential setup form, enter the following:\n    * Name: (Any friendly name, e.g., My OpenAI API Key)\n    * API Key: Paste the API key you copied in Step 1\n5. Click Save\n\n### Step 3: Add and Configure the Jira Node in Your Workflow\n1. In your n8n workflow (after the Telegram Trigger node), add a Jira node\n2. Choose the Jira Resource and Operation you need:\n    * For creating an issue:\n    Resource: Issue\n    Operation: Create\n    * For updating an issue:\n    Resource: Issue\n    Operation: Update\n3. Select your Jira credentials (created in Step 2)\n\n### Step 4: Review Node Configuration\n1. In the Operation field, confirm what the node is doing:\n    - Chat, Completion, Moderation, etc.\n2. Confirm the Model selected (e.g., gpt-3.5-turbo, gpt-4)\n3. Review the Prompt or Messages section:\n    - Make sure required input is present\n    - If the prompt uses expressions, ensure they reference a valid previous node"
      },
      "typeVersion": 1
    },
    {
      "id": "18fb581d-f779-4b58-b7c1-d441c8cdd5fa",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        -576
      ],
      "parameters": {
        "color": 4,
        "width": 2480,
        "height": 1296,
        "content": "\n# Workflow"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "28435f91-fe15-4f0d-aae2-a5afb508c8d4",
  "connections": {
    "If1": {
      "main": [
        [
          {
            "node": "Send a text message1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set 'Text'1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Jira Agent": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Try Again",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set 'Text'": {
      "main": [
        [
          {
            "node": "Extract Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set 'Text'1": {
      "main": [
        [
          {
            "node": "Jira Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Task": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Set 'Text'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Jira Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message1": {
      "main": [
        [
          {
            "node": "Set 'Text'1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create an issue in Jira Software": {
      "ai_tool": [
        [
          {
            "node": "Jira Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Delete an issue in Jira Software": {
      "ai_tool": [
        [
          {
            "node": "Jira Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update an issue in Jira Software": {
      "ai_tool": [
        [
          {
            "node": "Jira Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many issues in Jira Software1": {
      "ai_tool": [
        [
          {
            "node": "Jira Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get the status of an issue in Jira Software": {
      "ai_tool": [
        [
          {
            "node": "Jira Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}