Dynamic data management with permission control
The system receives messages via a Telegram webhook, extracts the chat ID and queries Airtable to verify permissions. With this information, it generates a *prompt* that includes the write permission, the user's name, and their query. The agent responds according to
📚 Dynamic Data Management with Permission Control
🧩 Overview
The workflow receives user messages from a Telegram bot, retrieves the user’s permissions from an Airtable database, and constructs a prompt that embeds the permission level, user name, and original query. An advanced AI agent processes the prompt using a Gemini language model and a suite of Airtable tools (read, create, update, delete). The resulting answer is sent back to the user via Telegram. The system therefore automates data‑management tasks while ensuring that only authorized users can modify records.
⚙️ Main Features
- Handles incoming Telegram messages in real time through a webhook.
- Verifies user permissions by reading a dedicated Airtable table.
- Builds a dynamic prompt that includes the user’s write permission, name, and message content.
- Employs an AI agent capable of reading, creating, updating, and deleting Airtable records based on the prompt.
- Sends the agent’s plain‑text response back to the user’s Telegram chat.
🔄 Workflow Steps
| Component Name | Role in the Workflow | Key Inputs | Key Outputs |
|---|---|---|---|
| Telegram Webhook | Receives the HTTP payload from Telegram and extracts the raw message data. | bot_token, raw JSON payload |
message (Telegram message object), build_data (structured data for downstream parsing) |
| Parse Data (extract chat id) | Converts the webhook data into a plain‑text chat identifier. | data (structured from webhook) |
text (chat ID) |
| Airtable (Read User Permissions) | Reads the Usuarios table to retrieve the user’s name and write permission. |
chat_id (from Parse Data), table name “Usuarios”, filter formula {chatid}=… |
result (record data) |
| Parse Data (Permission) | Extracts the “Permisos de administrador” field from the Airtable record. | data (record from Airtable) |
text (permission value: “true” or “false”) |
| Parse Data (Username) | Extracts the “Nombre de usuario” field from the Airtable record. | data (record from Airtable) |
text (user’s name) |
| Prompt | Builds a prompt template that embeds the permission status, user name, and original message. | permiso, usuario, mensaje |
prompt (complete prompt text) |
| Advanced Agent | Processes the prompt using the Gemini language model, invoking the Airtable tools as needed, and generates a plain‑text reply. | arg_input (prompt), llm (Gemini model), tools (Airtable CRUD tools) |
response (agent’s answer) |
| Telegram Message | Sends the agent’s reply back to the user’s Telegram chat. | text (agent response) |
Telegram response (API confirmation) |
Note: The Airtable CRUD components (read, create, update, delete) are supplied to the agent as tools; they are not part of the linear data flow but are invoked on demand by the agent.
🧠 Notes
- The system prompt embedded in the agent enforces that users with write permission may execute create, update, or delete actions, while users without permission are restricted to read‑only queries.
- All interactions with the Gemini model are performed through the “Gemini 2.5 Flash” model, ensuring low latency and cost efficiency.
- The webhook component stores incoming messages, allowing the agent to reference conversation context if required.
- Streaming is disabled for both model output and agent thinking, providing a single, complete reply to the user.
- Tool usage is limited by the agent’s internal policy; redundant or conflicting actions are automatically resolved.
- The workflow logs all tool calls and responses, facilitating auditability and compliance with data‑privacy regulations.