PBA PL Demo - AI-Powered Educational Support Bot¶
An intelligent Telegram bot that helps students and educators discover project-based learning opportunities by providing contextual information about project titles and descriptions across different terms, senior years, and subjects. The bot uses AI to understand user queries and dynamically retrieves relevant project data from an educational database.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- User Interaction: A user sends a message to the Telegram bot asking about projects, subjects, or educational content
- Prompt Retrieval: The workflow pulls the latest approved AI prompt from PromptLayer using the "prod" tag, ensuring the bot always uses the most current instructions
- AI Processing: The Support Bot (AI agent) receives the user's message along with the system prompt and processes the request
- Data Lookup: If needed, the bot searches an Airtable database containing project titles and descriptions filtered by term, senior year, and subject
- Context Memory: The bot maintains conversation history (up to 20 interactions) to provide relevant, contextual responses
- Response Generation: The AI model generates an appropriate response based on the prompt, user query, project data, and conversation history
- User Response: The bot sends the generated response back to the user via Telegram
- Logging: The interaction is logged to PromptLayer for monitoring and analysis
Workflow Diagram¶
graph TD
A[Message to bot] --> B[Pull Prompt from PromptLayer]
B --> C[Support Bot]
D[OpenRouter Chat Model] --> C
E[Simple Memory] --> C
F[Get project titles and descriptions] --> C
C --> G[Send Bot's Response]
G --> H[HTTP Request - Log to PromptLayer]
Trigger¶
Telegram Trigger: Activates when a user sends a message to the configured Telegram bot. The trigger captures the message content and user information.
Nodes Used¶
| Node Type | Purpose |
|---|---|
| Telegram Trigger | Receives incoming messages from users |
| HTTP Request (PromptLayer) | Retrieves the current production prompt template |
| AI Agent (Support Bot) | Processes user queries using AI with tools and memory |
| OpenRouter Chat Model | Provides the AI language model (Mistral) for generating responses |
| Buffer Window Memory | Maintains conversation context for up to 20 interactions |
| Airtable Tool | Searches project database by term, grade, and subject |
| Telegram Send | Sends bot responses back to users |
| HTTP Request (Logging) | Logs interactions to PromptLayer for monitoring |
External Services & Credentials Required¶
PromptLayer¶
- Purpose: Prompt management and interaction logging
- Credentials: API key for accessing prompt templates and logging
- Configuration: Base URL for prompt retrieval and logging endpoints
Telegram Bot API¶
- Purpose: Receiving and sending messages
- Credentials: Bot token from BotFather
- Configuration: Bot webhook for message handling
OpenRouter¶
- Purpose: AI model access (Mistral AI)
- Credentials: API key for model access
- Configuration: Model selection and parameters
Airtable¶
- Purpose: Project database storage and retrieval
- Credentials: API key and base access permissions
- Configuration: Base ID and table ID for project data
Environment Variables¶
No environment variables are explicitly defined in this workflow. All configuration is handled through: - Node parameters (URLs, model settings) - Credential references (API keys stored in n8n credential manager) - Hard-coded values (PromptLayer API key visible in workflow)
Data Flow¶
Input¶
- User Message: Text message from Telegram user
- User Context: Chat ID, user ID for session management
- Prompt Template: Current production prompt from PromptLayer
Processing¶
- Query Analysis: AI interprets user intent and requirements
- Database Search: Filtered project lookup based on educational criteria
- Context Integration: Previous conversation history applied
- Response Generation: AI-generated contextual response
Output¶
- Bot Response: Formatted text response sent to user
- Interaction Log: Logged conversation data to PromptLayer
- Memory Update: Conversation history updated for future interactions
Error Handling¶
- Support Bot: Configured with retry on failure (2-second wait between attempts)
- HTTP Requests: Standard error handling for API calls
- No explicit error paths: Workflow relies on n8n's built-in error handling mechanisms
Known Limitations¶
- Hard-coded API key in PromptLayer requests (security concern)
- No explicit error handling for failed API calls
- Limited to 20 conversation interactions in memory
- Workflow is currently inactive (not in production)
Related Workflows¶
No related workflows identified in the current context.
Setup Instructions¶
1. Import Workflow¶
- Copy the workflow JSON
- Import into your n8n instance
- Review and update all node configurations
2. Configure Credentials¶
-
Telegram Bot API:
- Create bot via BotFather
- Add bot token to n8n credentials
- Configure webhook URL
-
PromptLayer:
- Sign up for PromptLayer account
- Generate API key
- Update API key in HTTP Request nodes (security: use credential manager instead)
-
OpenRouter:
- Create OpenRouter account
- Generate API key
- Configure in OpenRouter Chat Model node
-
Airtable:
- Set up Airtable base with project data
- Generate API key with base access
- Configure base and table IDs in Airtable Tool node
3. Configure PromptLayer¶
- Create prompt template named "pbapldemo"
- Tag desired prompt version as "prod"
- Ensure prompt includes appropriate system instructions
4. Set Up Project Database¶
- Create Airtable table with columns: Term, Grade, Subject, Project Title, Description
- Populate with project data
- Verify filter formula logic in Airtable Tool node
5. Test and Activate¶
- Test each node individually
- Verify end-to-end message flow
- Activate workflow when ready for production
- Monitor logs in PromptLayer for performance insights