AI Cybersecurity Agent with Command Execution and Telegram Interface - n8n Workflow

Use this complex n8n workflow to deploy a GPT-4 powered AI agent via Telegram, capable of executing system commands, performing real-time searches, and managing Google Calendar.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Cybersecurity professionals and SOC analysts needing an instant, command-line-aware assistant.

  • n8n users interested in building advanced tool-using LLM agents (Langchain).

  • Developers looking for complex n8n templates integrating external APIs and system execution.

  • Security researchers automating routine analysis tasks via a chat interface.

Overview

This cutting-edge n8n workflow transforms a standard Telegram chat into a highly capable "QuantumDefender AI" cybersecurity assistant. By leveraging a GPT-4 class language model via the specialized Langchain n8n node, this solution provides real-time internet search capabilities, persistent conversational memory, Google Calendar management, and, critically, the ability to execute terminal commands on the host system.

This complex n8n automation is perfect for automating red teaming tasks, performing quick system checks, or instantly retrieving deep cybersecurity knowledge, making it a highly valuable n8n template for technical operations. The workflow uses a meticulous structure that ensures robust conversational flow and high responsiveness, starting every interaction by employing the send_typing tool via a dedicated n8n node.

How it Works


  1. Trigger Initiation: The process starts with the chatbot n8n trigger (a Telegram Trigger n8n node), which listens for any incoming message from an authorized user ID.

  2. Memory Management: The Telegram user ID is immediately passed to the Simple Memory n8n node, establishing a unique conversational context to maintain chat history throughout the session.

  3. AI Orchestration: The message is routed to the Agent n8n node. This Langchain Agent uses a custom system prompt defining its role as an elite cybersecurity AI.

  4. Tool Selection: Before generating a final response, the Agent first triggers the sendtyping n8n node via Telegram to provide instant feedback. Based on the user's input, the Agent intelligently selects from a diverse set of available tools:

Research: The Searchtool (an HTTP Request n8n node) is used for real-time internet research and RAG capabilities.
System Operations: If operational instructions are detected, the powerful Execute Command n8n node is invoked to run scripts or system utilities, a core feature of this n8n workflow.
Scheduling: The Agent utilizes the Google Calendar n8n nodes (create-event, Delete-event, update-events, Google Calendar) for scheduling and managing professional commitments.
Calculation: The Calculator n8n node handles complex mathematical queries.

  1. Final Response: Once the Agent has processed the request and utilized any necessary tools, it compiles a complete answer.

  2. Delivery: The final text output is securely sent back to the user's Telegram chat via the final Telegram n8n node, concluding the cycle of the n8n workflow.

Installation Guide

This n8n workflow requires setting up credentials for multiple services to function correctly:


  1. Import the n8n Workflow: Copy the provided JSON and import it into your n8n instance.

  2. Telegram Setup: Configure the Telegram Bot credentials for the chatbot (Telegram Trigger n8n trigger) and the final Telegram n8n node. Ensure you whitelist the specific Chat IDs allowed to interact with the bot. Important: Activate the webhooks for the chatbot n8n trigger and the sendtyping n8n node.

  3. OpenAI Integration: Update the credentials in the OpenAI Model n8n node with a valid OpenAI API key that has access to GPT-4 level models.

  4. Google Calendar Credentials: Provide OAuth2 credentials for the Google Calendar API to all four related Google Calendar n8n nodes.

  5. Search Tool Configuration: In the Searchtool (HTTP Request n8n node), locate the Authorization header under the body/headers parameters and replace the placeholder Bearer token with a valid API key for the Langsearch service (or substitute with your preferred search API setup).

  6. Activation: After configuring all necessary credentials in this n8n template, switch the entire n8n workflow to "Active" mode to enable the AI agent.

Node Details

chatbot (Telegram Trigger n8n trigger): Acts as the entry point, initiating the n8n workflow upon receiving messages from a whitelisted Telegram user.
Simple Memory (Langchain Memory n8n node): Crucial for maintaining conversation state by using the Telegram user's ID as a session key, allowing for multi-turn conversations within this n8n workflow.
OpenAI Model (Langchain Model n8n node): Connects to the LLM (GPT-4 class) service, providing the core intelligence needed for complex reasoning and tool usage.
Agent (Langchain Agent n8n node): The logic hub. It interprets user intent, manages the tool usage chain, and applies the "QuantumDefender AI" persona defined in its system prompt.
sendtyping (Telegram Tool n8n node): Used by the Agent to send the "typing..." indicator to Telegram, significantly enhancing the perceived responsiveness of the n8n automation.
Search
tool (HTTP Request Tool n8n node): Configured as a tool accessible by the Agent for performing real-time web searches by calling an external search API.
Execute Command (n8n node): A powerful, security-focused tool that allows the Agent to run commands on the machine hosting n8n, enabling automated operational tasks.
Google Calendar Tools (4 n8n nodes): A suite of tools that gives the Agent control over Google Calendar operations (CRUD), turning natural language requests into calendar actions within this n8n workflow.


  • Telegram (n8n node): The final communication n8n node, delivering the Agent's generated response back to the Telegram chat.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

An Opensource Enthusiast specializing in detection engineering, threat hunting, and automating security operations to accelerate threat detection and response.

Featured*