Skip to content

AI Assistant Agent: Chat Flow

This workflow provides a multi-modal AI assistant system that routes conversations to specialized AI agents based on user intent. It supports both text and voice interactions through WhatsApp and Telegram, offering expertise in financial codes, educational programs, bootcamp materials, and interactive AI training modules.

Purpose

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

This workflow serves as a comprehensive AI assistant platform that: - Routes users to specialized AI agents based on their selected topic - Manages chat sessions and conversation history - Provides both text and voice responses - Supports multiple messaging platforms (WhatsApp, Telegram) - Offers expertise across various educational and administrative domains

How It Works

  1. Session Initialization: When a user first interacts, they select from available AI assistant options (Financial Codes, Programs, SEED Bootcamp, etc.)
  2. Session Management: The system creates and tracks chat sessions in a PostgreSQL database
  3. Message Processing: Incoming messages are validated and checked for conversation-ending keywords
  4. Intent Routing: Based on the user's initial selection, messages are routed to the appropriate specialized AI assistant
  5. AI Processing: Each assistant uses OpenAI's API with specific knowledge bases and tools
  6. Response Generation: Responses are generated as text or converted to voice using ElevenLabs
  7. Message Delivery: Final responses are sent back through the TextIt platform to the user's preferred messaging app

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]
    D --> G[Success Response]

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

    R --> S1[Financial Codes Assistant]
    R --> S2[Programs Assistant]
    R --> S3[SEED Bootcamp Assistant]
    R --> S4[SkillUp Handbook Assistant]
    R --> S5[SkillUp Protocols Assistant]
    R --> S6[AI Trainer]

    S1 --> T[Response Processing]
    S2 --> T
    S3 --> T
    S4 --> T
    S5 --> T
    S6 --> T

    T --> U[If Audio]
    U --> V[Voice Generation]
    U --> W[Text Message]
    V --> X[Media Upload]
    X --> Y[Send Message]
    W --> Y
    Y --> Z[Output]

Trigger

The workflow is triggered by two webhook endpoints: - Textit Init: POST /webhook/b156b269-b5cd-4035-af14-99b6210c955b/init - For session initialization - Textit Webhook: POST /webhook/b156b269-b5cd-4035-af14-99b6210c955b - For ongoing conversations

Nodes Used

Node Type Purpose
Webhook Receives incoming messages from TextIt platform
PostgreSQL Manages chat sessions and retrieves budget/financial data
OpenAI Chat Model Powers various AI assistants with different specializations
OpenAI Assistant Pre-configured assistants for specific domains
AI Agent Custom agent for financial codes with tool access
Vector Store (Supabase) Knowledge base retrieval for document search
HTTP Request Sends messages back to TextIt and generates voice
Set Data transformation and field mapping
If/Switch Conditional routing and decision logic
AI Transform Text processing and keyword detection
Split Out Handles multiple response messages
Wait Manages timing for error responses

External Services & Credentials Required

Required Credentials

  • OpenAI API: For AI language models and assistants
  • PostgreSQL: Database for session management and financial data
  • Supabase: Vector database for document storage and retrieval
  • TextIt Token: For sending messages through the platform
  • ElevenLabs: Voice generation service
  • Telegram API: For Telegram bot functionality (disabled in current setup)

External Services

  • TextIt/RapidPro platform for message routing
  • WhatsApp Business API (via TextIt)
  • Telegram Bot API (via TextIt)

Environment Variables

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

Data Flow

Input

  • Webhook payload containing:
    • User message content
    • Contact information (UUID, URN)
    • Session/run ID
    • Platform type (WhatsApp, Telegram)

Processing

  • Session validation and creation
  • Message content analysis
  • AI assistant selection and processing
  • Response generation (text/voice)

Output

  • Text messages sent via TextIt API
  • Voice messages (audio files) uploaded and sent as attachments
  • Session data stored in PostgreSQL
  • Conversation history maintained in chat memory

Error Handling

The workflow includes several error handling mechanisms: - Invalid session detection: Returns HTTP 400 for missing sessions - Platform restrictions: SEED Bootcamp unavailable on WhatsApp - Voice generation fallback: Continues with text if voice generation fails - Option validation: Rejects invalid assistant selections - Conversation end detection: Properly terminates sessions on goodbye keywords

Known Limitations

Based on the workflow structure: - SEED Bootcamp assistant is restricted to Telegram only - Voice generation depends on ElevenLabs service availability - Session cleanup is disabled (week-old session deletion) - Some nodes are disabled (Telegram direct integration, session cleanup) - Message length is limited to 4090 characters

No related workflows are explicitly referenced in the current configuration.

Setup Instructions

  1. Import the workflow into your n8n instance
  2. Configure credentials:
    • Set up OpenAI API credentials for language models and assistants
    • Configure PostgreSQL connection for session management
    • Add Supabase credentials for vector store access
    • Set up TextIt API token for message sending
    • Configure ElevenLabs API for voice generation
  3. Database setup:
    • Create required tables: chat_sessions, budget_categories, budget_codes, budget_intents
    • Set up Supabase vector store with documents table
  4. Assistant configuration:
    • Ensure OpenAI assistants are created with proper IDs
    • Configure knowledge bases and document uploads
  5. Webhook configuration:
    • Set up TextIt flows to send webhooks to the provided endpoints
    • Configure platform routing (WhatsApp, Telegram)
  6. Test the workflow:
    • Send initialization message to create session
    • Test different assistant types
    • Verify voice generation functionality
  7. Enable production features:
    • Enable session cleanup if needed
    • Configure error workflow reference
    • Adjust message length limits as required