Skip to content

AI Assistant Agent: Chat Flow

This workflow provides a comprehensive conversational AI system that integrates with TextIt/RapidPro to deliver intelligent, context-aware responses across multiple educational domains. It routes users to specialized AI assistants based on their selected topic, maintains conversation history, and supports both text and voice responses for an enhanced learning experience.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

This workflow serves as the backbone for an educational AI assistant platform that helps users access information across various domains including financial codes, educational programs, bootcamp materials, and AI training modules. The system is designed to provide personalized, contextual assistance while maintaining conversation continuity and supporting multiple communication channels (WhatsApp, Telegram).

How It Works

  1. Session Initialization: When a user first interacts with the system via TextIt, they select from available topics (Finance & Budget Codes, Programs, SEED Bootcamp, etc.)
  2. Session Management: The system creates or retrieves existing chat sessions from a PostgreSQL database, tracking user intent and platform
  3. Message Processing: Incoming messages are validated and routed to the appropriate specialized AI assistant based on the user's selected topic
  4. AI Response Generation: Each assistant uses OpenAI models with specific knowledge bases and tools to generate contextually relevant responses
  5. Voice Support: For certain assistants (like AI Trainer), responses can be converted to speech using ElevenLabs and delivered as audio attachments
  6. Response Delivery: Formatted responses are sent back through TextIt to the user's preferred platform
  7. Memory Management: Conversation history is maintained in PostgreSQL for context continuity across sessions

Workflow Diagram

graph TD
    A[TextIt Init Webhook] --> B[Available Options]
    B --> C[Validate Option]
    C --> D[Create Session]
    C --> E[Wrong Selection]
    E --> F[Send Error Message]

    G[TextIt Webhook] --> H[Contains Message?]
    H --> I[Get Session Info]
    I --> J[If WhatsApp and SEED]
    J --> K[Platform Restriction Check]
    J --> L[If No Session]
    L --> M[Mapping]
    M --> N[Chat Info]
    N --> O[Check End Keywords]
    O --> P[If Chat End]
    P --> Q[Session Routing]

    Q --> R[Financial Codes Assistant]
    Q --> S[Programs Assistant]
    Q --> T[SEED Bootcamp Assistant]
    Q --> U[SkillUp Handbook Assistant]
    Q --> V[SkillUp Protocols Assistant]
    Q --> W[AI Trainer]

    R --> X[Response Processing]
    S --> X
    T --> X
    U --> X
    V --> X
    W --> Y[Response1 - JSON Processing]
    Y --> Z[Split Out]
    Z --> AA[Edit Fields2]
    AA --> X

    X --> BB[If Audio]
    BB --> CC[Voice Generation]
    BB --> DD[Text Response]
    CC --> EE[Media Upload]
    EE --> FF[Send Message]
    DD --> FF
    FF --> GG[Output]

Trigger

This workflow has two webhook triggers: - TextIt Init: /webhook/b156b269-b5cd-4035-af14-99b6210c955b/init - Handles initial session setup - TextIt Webhook: /webhook/b156b269-b5cd-4035-af14-99b6210c955b - Processes ongoing chat messages

Nodes Used

Node Type Purpose
Webhook Receives incoming messages from TextIt platform
PostgreSQL Manages chat sessions, budget data, and conversation memory
OpenAI Assistant Provides specialized AI responses for different domains
LangChain Agent Powers the Financial Codes Agent with RAG capabilities
Supabase Vector Store Stores and retrieves document embeddings for knowledge base
HTTP Request Sends messages back to TextIt and handles voice generation
Set Data transformation and field mapping
If/Switch Conditional routing and decision logic
AI Transform Text processing and format conversion
Split Out Handles multi-response processing for AI Trainer

External Services & Credentials Required

  • TextIt/RapidPro: Chat platform integration (requires API token)
  • OpenAI: Language models and assistants (requires API key)
  • PostgreSQL: Database for sessions and knowledge data (requires connection credentials)
  • Supabase: Vector database for document storage (requires API credentials)
  • ElevenLabs: Text-to-speech conversion (requires API key)
  • Telegram: Optional notification channel (requires bot token)

Environment Variables

No specific environment variables are documented in the workflow configuration. Credentials are managed through n8n's credential system.

Data Flow

Input: TextIt webhook payload containing: - User message content - Contact information (UUID, platform URN) - Session/run ID - Message type (init/chat)

Processing: - Session validation and routing - AI model inference with context - Knowledge base retrieval - Response formatting

Output: TextIt API calls with: - Formatted text responses - Optional audio attachments - Contact targeting information

Error Handling

The workflow includes several error handling mechanisms: - Session Validation: Checks for existing sessions and handles missing data - Platform Restrictions: Blocks certain features (SEED Bootcamp) on WhatsApp - Option Validation: Ensures users select valid topics during initialization - Chat End Detection: Recognizes conversation termination keywords - Voice Generation Fallback: Continues with text if audio generation fails - Response Timeouts: Uses Wait nodes to handle processing delays

Known Limitations

Based on the workflow structure: - SEED Bootcamp is temporarily unavailable on WhatsApp - Voice responses are limited to specific assistants (AI Trainer) - Session cleanup occurs weekly, potentially losing long-term conversation history - Some nodes are disabled, indicating incomplete features

No related workflows are explicitly referenced in the current configuration.

Setup Instructions

  1. Import Workflow: Import the JSON configuration into your n8n instance

  2. Configure Credentials:

    • Set up OpenAI API credentials
    • Configure PostgreSQL database connection
    • Add Supabase API credentials
    • Set up TextIt API token
    • Configure ElevenLabs API key (for voice features)
  3. Database Setup:

    • Create required tables: chat_sessions, budget_categories, budget_codes, budget_intents
    • Set up Supabase vector store with documents table
  4. TextIt Configuration:

    • Configure webhook endpoints in your TextIt flow
    • Set up contact flows to trigger the appropriate webhooks
  5. OpenAI Assistants:

    • Create and configure the referenced OpenAI assistants
    • Update assistant IDs in the workflow nodes
  6. Test Setup:

    • Send test messages through TextIt
    • Verify database connections and session creation
    • Test voice generation functionality
    • Confirm response delivery to end users
  7. Activate Workflow: Enable the workflow to start processing incoming messages