FlowChat
FlowChat is a powerful Rails framework for building sophisticated conversational interfaces across multiple platforms with a pluggable gateway architecture. Create interactive flows with menus, prompts, validation, media support, and session management using a unified, intuitive API that works across USSD, WhatsApp, Telegram, HTTP, and any custom platforms you build.
โจ Key Features
- ๐ Unified API: Single codebase that works across all platforms
- ๐ Pluggable Gateways: Extensible architecture supporting multiple backends per platform
- ๐ฑ Multi-Platform: Out of the box support for USSD, WhatsApp, Telegram, HTTP, and more, with simulator for testing
- ๐ฏ Screen-Based Navigation: Intuitive screen() method for building conversational flows
- ๐พ Advanced Session Management: Flexible session boundaries and storage options
- ๐ง Middleware Architecture: Extensible middleware system for custom processing
- ๐จ Rich Prompts: Support for text, media, selections, yes/no prompts, validation, and transformations
- ๐ Built-in Instrumentation: Comprehensive logging and metrics collection
- ๐งช Testing Support: Built-in simulator for development and testing
- ๐ข Multi-Tenancy: In-built support for custom configuration per tenant and URL-based isolation
- ๐ Background Processing: Job queue support for WhatsApp messaging
๐ Quick Start
Installation
Add FlowChat to your Rails application:
# Gemfile
gem 'flow_chat'
bundle install
Define your flow
# app/flow_chat/welcome_flow.rb
class WelcomeFlow < FlowChat::Flow
def main_page
name = app.screen(:name) do |prompt|
prompt.ask "Welcome! What's your name?",
transform: ->(input) { input.strip.titleize }
end
choice = app.screen(:main_menu) do |prompt|
prompt.select "Hi #{name}! Choose:", {
"1" => "Account Info",
"2" => "Make Payment",
"3" => "Support"
}
end
case choice
when "1"
show_account_info
when "2"
make_payment
when "3"
app.say "Call us: 123-456-7890"
end
end
# ... implement your flow methods
end
Basic USSD Application
# app/controllers/ussd_controller.rb
class UssdController < ApplicationController
skip_forgery_protection
def process_request
processor = FlowChat::Processor.new(self) do |config|
config.use_gateway FlowChat::Ussd::Gateway::Nalo
config.use_session_store FlowChat::Session::CacheSessionStore
end
processor.run WelcomeFlow, :main_page
end
end
Basic WhatsApp Application
# app/controllers/whatsapp_controller.rb
class WhatsappController < ApplicationController
skip_forgery_protection
def webhook
processor = FlowChat::Processor.new(self) do |config|
config.use_gateway FlowChat::Whatsapp::Gateway::CloudApi
config.use_session_store FlowChat::Session::CacheSessionStore
end
processor.run WelcomeFlow, :main_page
end
end
Basic Telegram Application
# app/controllers/telegram_controller.rb
class TelegramController < ApplicationController
skip_forgery_protection
def webhook
processor = FlowChat::Processor.new(self) do |config|
config.use_gateway FlowChat::Telegram::Gateway::BotApi
config.use_session_store FlowChat::Session::CacheSessionStore
end
processor.run WelcomeFlow, :main_page
end
end
Basic HTTP API Application
# app/controllers/api_controller.rb
class ApiController < ApplicationController
def chat
processor = FlowChat::Processor.new(self) do |config|
config.use_gateway FlowChat::Http::Gateway::Simple
config.use_session_store FlowChat::Session::CacheSessionStore
end
processor.run WelcomeFlow, :main_page
end
end
Same WelcomeFlow works across ALL platforms!
๐๏ธ Architecture
FlowChat uses a composition-based architecture with these core components:
- Processor: Orchestrates request processing through middleware stack
- Gateway: Platform-specific request/response handling (Nalo, WhatsApp Cloud API)
- App: Unified application interface with screen-based navigation
- Session: Flexible session management with configurable boundaries
- Middleware: Extensible processing pipeline
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Gateway โ -> โ Session โ -> โ Custom โ
โ โ โ Middleware โ โ Middleware โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ
v
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Flow/Action โ <- โ Executor โ <- โ App โ
โ โ โ โ โ โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
๐ Pluggable Gateway Architecture
FlowChat's power comes from its pluggable gateway system. Each platform can have multiple gateway implementations:
# Create your own SMS gateway
class MyCompany::Sms::Gateway::Twilio
def initialize(app, config)
@app = app
@config = config
end
def call(context)
# Parse Twilio webhook, set context values
context["request.msisdn"] = params["From"]
context["request.platform"] = :sms
context.input = params["Body"]
# Process through middleware
type, prompt, choices, media = @app.call(context)
# Send response via Twilio API
send_sms_response(prompt, to: context["request.msisdn"])
end
# Optional: Configure platform-specific middleware
def self.configure_middleware_stack(builder, custom_middleware)
builder.use MyCompany::Sms::MessageTransformMiddleware
builder.use custom_middleware
end
end
# Use your custom gateway
processor = FlowChat::Processor.new(self) do |config|
config.use_gateway MyCompany::Sms::Gateway::Twilio, sms_config
end
๐ Documentation
Getting Started
- Getting Started Guide - Comprehensive setup and first app
- Architecture Overview - Deep dive into FlowChat's design
- Configuration - Complete configuration reference
Platform Guides
- USSD Development - USSD-specific features and examples
- WhatsApp Development - WhatsApp Business API integration
- Telegram Development - Telegram Bot API integration
- HTTP Development ๐ง - API endpoints and webhooks
- Multi-Platform Apps ๐ง - Building unified experiences
Advanced Topics
- Gateway Development - Creating custom gateways and platforms
- Session Management ๐ง - Session boundaries and storage
- Middleware Development ๐ง - Creating custom middleware
- Testing & Simulation - Testing strategies and simulator usage
- Background Jobs ๐ง - Async processing for WhatsApp
- Instrumentation - Monitoring, logging, and error tracking
API Reference
- Core API ๐ง - Processor, App, Flow classes
- Prompts & Validation ๐ง - Interactive prompts and validation
- Gateways ๐ง - Platform gateway interfaces
- Session Stores ๐ง - Session storage options
๐ฏ Core Concepts
Screen-Based Navigation
Build conversational flows using the intuitive screen() method:
def registration_flow
# Each screen automatically handles state and navigation
email = app.screen(:email) do |prompt|
prompt.ask "Enter your email:",
validate: ->(input) {
"Invalid email" unless input.include?("@")
}
end
name = app.screen(:name) do |prompt|
prompt.ask "Enter your full name:",
transform: ->(input) { input.strip.titleize }
end
# Confirmation screen with rich prompts
confirmed = app.screen(:confirm) do |prompt|
prompt.yes? "Confirm registration for #{name} (#{email})?"
end
if confirmed
create_user(name, email)
app.say "Welcome #{name}! Registration complete."
else
app.say "Registration cancelled."
end
end
Multi-Platform Compatibility
Write once, run everywhere:
class MenuFlow < FlowChat::Flow
def
choice = app.screen(:menu) do |prompt|
prompt.select "Choose an option:", {
"info" => "๐ Information", # Rich for WhatsApp
"help" => "โ Help", # Falls back to text for USSD
"exit" => "๐ Exit"
}
end
# Same logic works on both platforms
handle_choice(choice)
end
end
Flexible Session Management
Configure sessions for your use case:
# Durable sessions across timeouts
processor = FlowChat::Processor.new(self) do |config|
config.use_durable_sessions # Uses user identifier (usually phone number) for session ID
end
# Cross-platform sessions
processor = FlowChat::Processor.new(self) do |config|
config.use_cross_platform_sessions # Share sessions between platforms (e.g. USSD & WhatsApp)
end
# URL-based multi-tenancy
processor = FlowChat::Processor.new(self) do |config|
config.use_url_isolation # tenant1.app.com vs tenant2.app.com
end
๐ ๏ธ Supported Platforms & Gateways
| Platform | Available Gateways | Features |
|---|---|---|
| USSD | Nalo โ
, Custom |
Pagination, choice mapping, session management |
CloudApi โ
, Custom |
Rich media, buttons, lists, templates, background jobs | |
| Telegram | BotApi โ
, Custom |
Inline keyboards, rich media, callbacks, group chats |
| HTTP | Simple โ
, Custom |
Testing, webhooks, API endpoints, JSON responses |
| Simulator | Built-in โ | Development testing, conversation replay, flow debugging |
| Custom | Your Gateway | Implement any platform by creating a gateway class |
โ = Included with FlowChat
Gateway Examples
# Built-in gateways (included with FlowChat)
config.use_gateway FlowChat::Ussd::Gateway::Nalo
config.use_gateway FlowChat::Whatsapp::Gateway::CloudApi, whatsapp_config
config.use_gateway FlowChat::Telegram::Gateway::BotApi, telegram_config
config.use_gateway FlowChat::Http::Gateway::Simple
# Custom gateway examples (you would build these)
config.use_gateway MyCompany::Sms::Gateway::Twilio, twilio_config
config.use_gateway MyCompany::Slack::Gateway::BoltJS, slack_config
๐ฆ Example Applications
- USSD Banking App ๐ง - Complete banking flow with validation
- WhatsApp Customer Service ๐ง - Media support and templates
- HTTP API Chatbot ๐ง - JSON API for web/mobile integration
- Multi-Platform E-commerce ๐ง - Unified shopping across USSD, WhatsApp, and HTTP
- Multi-Tenant SaaS ๐ง - URL-based tenant isolation
- Custom Gateway Example ๐ง - Building a Telegram gateway
๐งช Testing & Development
FlowChat includes a built-in simulator interface for easy development and testing:
# Simulator is automatically enabled in development
processor = FlowChat::Processor.new(self) do |config|
config.use_gateway FlowChat::Ussd::Gateway::Nalo # or any gateway
end
# Explicitly control simulator mode if needed
processor = FlowChat::Processor.new(self, enable_simulator: false) do |config|
# Disable simulator even in development
end
The simulator provides a web interface for testing your flows during development. It works the same regardless of which gateway you're using, allowing you to test your conversational logic before deploying to actual platforms.
Learn more: Testing & Simulation Guide
๐ค Contributing
We welcome contributions!
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
FlowChat is released under the MIT License.
๐ Support
- Documentation: Comprehensive guides in the docs/ directory
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ข Commercial Support
FlowChat is developed by Radioactive Labs. Commercial support, custom development, and consulting services are available.
Ready to build amazing conversational experiences? Check out the Getting Started Guide to create your first FlowChat application.