Skip to content

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

  1. User Interaction: A user sends a message to the Telegram bot asking about projects, subjects, or educational content
  2. 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
  3. AI Processing: The Support Bot (AI agent) receives the user's message along with the system prompt and processes the request
  4. Data Lookup: If needed, the bot searches an Airtable database containing project titles and descriptions filtered by term, senior year, and subject
  5. Context Memory: The bot maintains conversation history (up to 20 interactions) to provide relevant, contextual responses
  6. Response Generation: The AI model generates an appropriate response based on the prompt, user query, project data, and conversation history
  7. User Response: The bot sends the generated response back to the user via Telegram
  8. 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)

No related workflows identified in the current context.

Setup Instructions

1. Import Workflow

  1. Copy the workflow JSON
  2. Import into your n8n instance
  3. Review and update all node configurations

2. Configure Credentials

  1. Telegram Bot API:

    • Create bot via BotFather
    • Add bot token to n8n credentials
    • Configure webhook URL
  2. PromptLayer:

    • Sign up for PromptLayer account
    • Generate API key
    • Update API key in HTTP Request nodes (security: use credential manager instead)
  3. OpenRouter:

    • Create OpenRouter account
    • Generate API key
    • Configure in OpenRouter Chat Model node
  4. 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

  1. Create prompt template named "pbapldemo"
  2. Tag desired prompt version as "prod"
  3. Ensure prompt includes appropriate system instructions

4. Set Up Project Database

  1. Create Airtable table with columns: Term, Grade, Subject, Project Title, Description
  2. Populate with project data
  3. Verify filter formula logic in Airtable Tool node

5. Test and Activate

  1. Test each node individually
  2. Verify end-to-end message flow
  3. Activate workflow when ready for production
  4. Monitor logs in PromptLayer for performance insights