Skip to content

andychuong/messenger_ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MessageAI - Intelligent Messaging Platform

An advanced iOS messaging application with AI-powered conversation intelligence, built with SwiftUI and Firebase.


🎯 Current Status

Latest Release: Phase 12 + LangChain Integration
Date: October 25, 2025
Platform: iOS 17.0+
Backend: Firebase + OpenAI GPT-4o + LangChain
Status: βœ… LangChain Agent Fully Operational


✨ Key Features

Core Messaging

  • πŸ’¬ Real-time messaging with delivery & read receipts
  • πŸ‘₯ Direct and group conversations with visual enhancements
  • 🎨 Colored avatars - Unique colors for each participant
  • πŸ‘€ Visual read receipts - See who viewed with colored circles
  • πŸ“Έ Image sharing with Firebase Storage (encrypted)
  • 🎀 Voice messages with AI transcription
  • 😊 Message reactions with emoji picker
  • ✏️ Edit messages within time window
  • 🧡 Threaded conversations

Communication

  • πŸ“ž Voice & video calls with WebRTC
  • 🌍 AI-powered message translation
  • πŸ”” Push notifications (configurable)

AI Intelligence (Phases 7-9 + LangChain)

  • πŸ€– AI Chat Assistant - Conversational interface to your messages
  • πŸ”— LangChain Agent - Intelligent tool orchestration for fluid conversations
  • πŸ” Semantic Search - Find messages by meaning, not keywords
  • βœ… Action Item Tracking - AI extracts and tracks tasks
  • πŸ’‘ Decision Logging - Automatic detection of important decisions
  • ⚠️ Priority Detection - AI identifies urgent messages
  • πŸ“Š Conversation Summaries - Get instant overviews of long chats
  • 🧠 RAG Pipeline - Question answering with context
  • 🎯 Multi-Step Reasoning - Agent chains tools for complex queries

🎨 Phase 12: Enhanced Group Chat UX (In Progress)

What's New:

Visual Identity System

  • 🎨 Unique User Colors - 10-color palette, consistent per user
  • πŸ‘€ Colored Avatar Bubbles - Initials on colored backgrounds
  • πŸ”„ Smart Color Generation - Based on user ID for uniqueness

Group Chat Enhancements

  • πŸ‘₯ Participant Header - Scrollable row showing all members
    • See who's online with green dot indicators
    • Current user appears first (labeled "You")
    • Tap header to view group info
  • πŸ’¬ Improved Message Display
    • Colored avatar circles next to sender names
    • Visual hierarchy with consistent colors

Read Receipt Redesign

  • βœ“ Gray Checkmark - Shows when sent, not everyone has read
  • 🎯 Colored Viewer Circles - See exactly who read the message
  • ✨ Progressive Display - Circles appear as people read
  • πŸŽ‰ Smart Completion - Checkmark disappears when all have read
  • πŸ“Š Overflow Handling - Shows 3 circles + "+X" for more viewers

Visual States:

Sent:          8:09 PM βœ“          (gray checkmark)
1 person read: 8:09 PM βœ“ πŸ”΅       (checkmark + circle)
2 people read: 8:09 PM βœ“ πŸ”΅πŸ”΄     (checkmark + 2 circles)
All read:      8:09 PM πŸ”΅πŸ”΄πŸŸ£     (only circles, checkmark gone!)

Bug Fixes

  • βœ… Fixed reactions deleting messages
  • βœ… Fixed image loading/display with encryption
  • βœ… Fixed online indicator in chat header
  • βœ… Improved group name display (truncation)

πŸš€ Phase 9: AI Chat Assistant

What's New:

  • Chat naturally with AI about your conversations
  • Ask questions like "What did we decide about the project?"
  • Get instant summaries: "Summarize my conversation with Sarah"
  • Find information: "Find messages about the deadline"
  • Track tasks: "What are my action items?"
  • Multi-turn conversations with context retention

Access:

  1. Global Assistant: AI tab (purple sparkles)
  2. Conversation Assistant: Sparkles button in any chat

Quick Actions:

  • πŸ“„ Summarize conversation
  • βœ… View action items
  • πŸ’‘ Review decisions
  • ⚠️ Check priority messages

πŸ”— LangChain AI Agent Enhancement

New Implementation: The AI Assistant now uses LangChain with an OpenAI Functions Agent for more intelligent, fluid conversations.

What is LangChain?

LangChain is a framework for building applications with Large Language Models. It provides:

  • Intelligent Agents: AI that reasons and uses tools automatically
  • Better Memory: Improved context management across conversations
  • Tool Orchestration: Seamlessly chains multiple tools together
  • Chain of Thought: More sophisticated reasoning patterns

Key Benefits

  1. Smarter Queries: Agent automatically decides which tools to use
  2. Multi-Step Tasks: Can perform complex workflows without manual chaining
  3. Natural Conversations: Better understanding of user intent and context
  4. Automatic Tool Selection: No need to explicitly specify actions

Example Queries

❓ "Who was the last person I said hello to?"
   β†’ Agent searches all conversations, finds the greeting, identifies sender

❓ "Translate my last message to Chinese and send it"
   β†’ Agent fetches recent messages, translates, and sends automatically

❓ "Find decisions about the budget and create action items"
   β†’ Agent searches for decisions, extracts actionable tasks, creates items

Available Tools

The agent has access to 8 intelligent tools:

  • πŸ” search_messages - Semantic search across conversations
  • πŸ“„ summarize_conversation - Extract key points and insights
  • βœ… get_action_items - Retrieve and filter tasks
  • πŸ’‘ get_decisions - Find important decisions
  • ⚠️ get_priority_messages - Identify urgent messages
  • 🌍 translate_text - AI-powered translation
  • πŸ“₯ get_recent_messages - Fetch recent chat history
  • πŸ“€ send_message - Send messages on your behalf

Technical Details

  • Model: GPT-4o via LangChain
  • Temperature: 0.7 (balanced creativity/accuracy)
  • Max Iterations: 10 (prevents infinite loops)
  • Context Window: Optimized for relevant history

Maintenance & Cleanup

  • Automated: scheduledEmbeddingCleanup runs daily at 2 AM UTC
  • Manual: Call cleanupInvalidEmbeddings function to remove invalid embeddings
  • Health Check: debugDatabase function to inspect system state

Documentation

  • Architecture: LANGCHAIN_ARCHITECTURE.md - Complete system design
  • Troubleshooting: docs/archive/LANGCHAIN_TROUBLESHOOTING.md
  • Cleanup Guide: docs/archive/CLEANUP_INSTRUCTIONS.md
  • Summary: docs/archive/LANGCHAIN_COMPLETE.md

πŸ—οΈ Architecture

πŸ“ See ARCHITECTURE.md for complete system architecture with detailed diagrams

Frontend (iOS)

Language: Swift 5.9+
UI: SwiftUI
Storage: SwiftData
State: Combine + @Observable
Authentication: Firebase Auth
Real-time: Firebase Firestore listeners
Calls: WebRTC
Security: AES-256-GCM E2E encryption

Backend (Firebase)

Functions: Node.js 18 (TypeScript)
Database: Cloud Firestore (NoSQL)
Storage: Firebase Cloud Storage
Auth: Firebase Authentication
AI: OpenAI GPT-4o
Embeddings: text-embedding-3-large (1536 dim)

AI Stack (LangChain)

Agent: OpenAI Functions Agent
LLM: GPT-4o with function calling
Vector Store: Firestore embeddings
Voice-to-Text: Whisper API
Translation: GPT-4o
Semantic Search: Cosine similarity on 1536-dim vectors
Tools: 8 intelligent tools (search, summarize, translate, etc.)

πŸ“¦ Project Structure

MessagingApp/
β”œβ”€β”€ ios/messagingapp/
β”‚   β”œβ”€β”€ Services/           # Backend integration
β”‚   β”‚   β”œβ”€β”€ AuthService.swift
β”‚   β”‚   β”œβ”€β”€ MessageService.swift
β”‚   β”‚   β”œβ”€β”€ AIService.swift
β”‚   β”‚   β”œβ”€β”€ RAGService.swift
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ ViewModels/         # State management
β”‚   β”‚   β”œβ”€β”€ ChatViewModel.swift
β”‚   β”‚   β”œβ”€β”€ AIAssistantViewModel.swift
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Views/              # SwiftUI views
β”‚   β”‚   β”œβ”€β”€ Conversations/
β”‚   β”‚   β”œβ”€β”€ Components/     # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ GroupParticipantHeader.swift
β”‚   β”‚   β”‚   β”œβ”€β”€ ReadReceiptAvatars.swift
β”‚   β”‚   β”‚   β”œβ”€β”€ UserAvatarView.swift
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ AI/
β”‚   β”‚   β”œβ”€β”€ Calls/
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Utilities/          # Helper utilities
β”‚   β”‚   β”œβ”€β”€ ColorGenerator.swift
β”‚   β”‚   └── ...
β”‚   └── Models/             # Data models
β”‚       β”œβ”€β”€ Message.swift
β”‚       β”œβ”€β”€ ActionItem.swift
β”‚       └── ...
β”‚
β”œβ”€β”€ firebase/
β”‚   β”œβ”€β”€ functions/src/
β”‚   β”‚   β”œβ”€β”€ ai/
β”‚   β”‚   β”‚   β”œβ”€β”€ assistant.ts    # AI Chat Assistant
β”‚   β”‚   β”‚   β”œβ”€β”€ intelligence.ts # Action items, decisions
β”‚   β”‚   β”‚   β”œβ”€β”€ embeddings.ts   # RAG pipeline
β”‚   β”‚   β”‚   └── translation.ts
β”‚   β”‚   └── messaging/
β”‚   β”‚       └── notifications.ts
β”‚   β”œβ”€β”€ firestore.rules
β”‚   └── storage.rules
β”‚
└── docs/                   # Comprehensive documentation
    β”œβ”€β”€ PHASE9_COMPLETE.md
    β”œβ”€β”€ PHASE9_QUICKSTART.md
    └── ...

πŸŽ“ Implementation Phases

Phase Feature Status
1 Setup & Authentication βœ… Complete
2 Friends System βœ… Complete
3 Core Messaging βœ… Complete
4 Rich Messaging βœ… Complete
4.5 Group Chat βœ… Complete
5 Voice/Video Calls βœ… Complete
6 End-to-End Encryption βœ… Complete
7 AI Translation βœ… Complete
8 RAG & Intelligence βœ… Complete
9 AI Chat Assistant βœ… Complete
10 Push Notifications πŸ“‹ Planned
11 Offline Support πŸ“‹ Planned
12 Polish & UX 🚧 In Progress

πŸš€ Quick Start

Prerequisites

# Install dependencies
- Xcode 15+
- Node.js 18+
- Firebase CLI
- CocoaPods or SPM

Setup

  1. Clone Repository
git clone <repository-url>
cd MessagingApp
  1. Firebase Setup
cd firebase/functions
npm install
npm run build

# Deploy functions
firebase deploy --only functions
  1. Configure Environment
# Set OpenAI API key
firebase functions:config:set openai.api_key="sk-..."
  1. iOS Setup
cd ios/messagingapp
# Open in Xcode
open messagingapp.xcodeproj
  1. Build & Run
  • Select target device/simulator
  • Press Cmd+R

πŸ“– Documentation

Latest Features

  • TRANSLATION_FEATURES.md - Auto-translation guide
  • Group Chat UX - Visual enhancements (Phase 12)
    • Colored avatar system
    • Participant header
    • Read receipt redesign

Phase 9 Documentation

Previous Phases

  • PHASE8_COMPLETE.md - RAG & Intelligence
  • PHASE7_COMPLETE.md - Translation
  • PHASE6_COMPLETE.md - Encryption
  • And more in /docs/archive

πŸ§ͺ Testing

Phase 12: Group Chat UX Testing

Visual Features:

1. Create/join a group chat (3+ members)
2. Verify participant header shows all members with:
   - Colored avatar bubbles (44x44px)
   - "You" label for current user
   - Green dot for online members
   - Horizontal scrolling
3. Send a message
4. Verify gray checkmark appears
5. Wait for 1 person to read
   - Verify checkmark + 1 colored circle
6. Wait for more to read
   - Verify checkmark + multiple circles
7. Wait for all to read
   - Verify checkmark disappears, only circles remain
8. Verify each user has unique color
9. Test message reactions (should not delete messages)
10. Test image sending/loading

Run AI Test Suite

# See docs/archive/PHASE9_TESTING_GUIDE.md for full suite

# Quick smoke test:
1. Open AI Assistant tab
2. Tap "Action Items" quick action
3. Verify response
4. Open a conversation
5. Tap sparkles icon
6. Tap "Summarize"
7. Verify summary

Test Coverage

  • Unit tests for services
  • Integration tests for AI features
  • UI tests for critical flows
  • Performance tests for response times
  • Visual regression tests for new UI

πŸ’‘ Usage Examples

Enhanced Group Chat (Phase 12)

Visual Read Receipts:

Your message: "Meeting at 3pm tomorrow?"
8:09 PM βœ“              ← Sent, no one read yet

[Alice reads it]
8:09 PM βœ“ πŸ”΅           ← Alice read (blue circle)

[Bob reads it]
8:09 PM βœ“ πŸ”΅πŸ”΄         ← Alice & Bob read

[Charlie reads it]
8:09 PM πŸ”΅πŸ”΄πŸŸ£         ← Everyone read! Checkmark gone

Participant Header:

  • Scroll horizontally to see all members
  • Green dot shows who's online
  • Tap any bubble to see details
  • Your avatar appears first

Color System:

  • Each person gets a unique color
  • Same color appears in:
    • Participant header
    • Message sender badge
    • Read receipt circles
  • Makes group conversations easy to follow

AI Chat Assistant

Get Conversation Summary:

You: "Summarize my conversation with John"
AI: "Based on your conversation with John:
     - Discussed Q4 project timeline
     - Decided to use React for frontend
     - Action items: Create wireframes by Thursday"

Find Information:

You: "Find messages about the database"
AI: "I found 3 relevant messages:
     1. Sarah (Oct 20): 'We should use PostgreSQL...'
     2. John (Oct 21): 'The schema needs foreign keys...'
     3. Mike (Oct 22): 'Don't forget indexes...'"

Track Tasks:

You: "What are my action items?"
AI: "You have 3 pending action items:
     1. Send report to Sarah (Due: Oct 25)
     2. Review budget proposal (Due: Oct 24)
     3. Schedule team meeting (No deadline)"

πŸ”§ Configuration

Firebase Functions Environment

# OpenAI API Key (required for AI features)
firebase functions:config:set openai.api_key="sk-..."

# Optional: Custom settings
firebase functions:config:set app.name="MessageAI"
firebase functions:config:set app.environment="production"

iOS Configuration

Edit GoogleService-Info.plist with your Firebase project details.


πŸ“Š Performance

Typical Response Times

  • Simple queries: 1-2 seconds
  • Conversation summaries: 2-4 seconds
  • Semantic search: 2-3 seconds
  • Multi-turn conversation: 1-2 seconds

Cost Estimates

  • ~$1.40/user/month for typical AI usage
  • 20 summaries, 10 action item queries, 15 searches, 30 multi-turn exchanges
  • Optimizable with caching and rate limiting

πŸ” Security

  • Firebase Authentication required for all operations
  • Firestore security rules enforce data access
  • Cloud Functions validate authentication
  • End-to-end encryption for messages (Phase 6)
  • API keys secured in Cloud Functions environment

🀝 Contributing

Development Workflow

  1. Create feature branch
  2. Implement feature
  3. Write tests
  4. Update documentation
  5. Submit pull request

Code Style

  • Swift: Follow Swift API Design Guidelines
  • TypeScript: ESLint with Firebase recommended config
  • Comments: Document complex logic
  • Tests: Aim for 80%+ coverage

πŸ“ Roadmap

Near-Term (Q4 2025)

  • Streaming responses for AI
  • Voice input for AI queries
  • Export summaries as PDF
  • Custom quick actions

Medium-Term (Q1 2026)

  • Proactive AI suggestions
  • Meeting summaries
  • Smart scheduling
  • Team analytics

Long-Term (2026+)

  • Multi-language support
  • GPT-4o vision for images
  • Advanced conversation insights
  • Cross-platform (Android)

πŸ“œ License

[Your License Here]


πŸ‘₯ Team

Developed by [Your Team/Name]


πŸ™ Acknowledgments

  • OpenAI for GPT-4o and Whisper
  • Firebase for backend infrastructure
  • Swift community for excellent resources

πŸ“ž Support

Documentation: See /docs folder
Issues: GitHub Issues
Email: your-email@example.com


πŸŽ‰ Highlights

What Makes MessageAI Special

  1. Truly Intelligent - Not just chat, but understanding
  2. Context-Aware - AI remembers and understands
  3. Productivity-Focused - Built for getting things done
  4. Privacy-Conscious - E2E encryption, user control
  5. Modern Stack - Latest tech, best practices
  6. Beautiful UX - Visual read receipts & colored identities (Phase 12)
  7. Group Chat Excellence - Best-in-class group messaging experience

Awards & Recognition

  • [Add your achievements here]

πŸ“ˆ Stats

  • Lines of Code: ~16,000+ Swift, ~3,000+ TypeScript
  • Cloud Functions: 15+
  • AI Models: GPT-4o, text-embedding-3-large, Whisper
  • Features: 45+
  • Phases Completed: 9/12 (Phase 12 in progress)
  • Color Palette: 10 unique colors for user identity

πŸ“š Documentation Index

Architecture & Design

  • ARCHITECTURE.md - Complete system architecture with detailed diagrams

    • Full stack visualization
    • All data flows (messaging, AI, calling, encryption)
    • Database schema & relationships
    • Security architecture
    • Performance characteristics
    • Technology stack
  • LANGCHAIN_ARCHITECTURE.md - LangChain AI Agent deep dive

    • Agent architecture & components
    • Tool implementations
    • Embedding system
    • Semantic search internals

Quick References

Implementation Guides

Troubleshooting & Maintenance

Historical Documentation

See docs/archive/ for phase-by-phase implementation history (Phases 1-12)


Built with ❀️ using Swift, SwiftUI, Firebase, and OpenAI


Last Updated: October 25, 2025
Version: 12.0.0-beta
Status: Phase 12 In Progress - Enhanced Group Chat UX

About

iOS app designed for international messaging. Featuring translations and encryption

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published