flow_chat 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +44 -0
- data/.gitignore +2 -1
- data/README.md +84 -1229
- data/docs/configuration.md +337 -0
- data/docs/flows.md +320 -0
- data/docs/images/simulator.png +0 -0
- data/docs/instrumentation.md +216 -0
- data/docs/media.md +153 -0
- data/docs/testing.md +475 -0
- data/docs/ussd-setup.md +306 -0
- data/docs/whatsapp-setup.md +162 -0
- data/examples/multi_tenant_whatsapp_controller.rb +9 -37
- data/examples/simulator_controller.rb +9 -18
- data/examples/ussd_controller.rb +32 -38
- data/examples/whatsapp_controller.rb +32 -125
- data/examples/whatsapp_media_examples.rb +68 -336
- data/examples/whatsapp_message_job.rb +5 -3
- data/flow_chat.gemspec +6 -2
- data/lib/flow_chat/base_processor.rb +48 -2
- data/lib/flow_chat/config.rb +5 -0
- data/lib/flow_chat/context.rb +13 -1
- data/lib/flow_chat/instrumentation/log_subscriber.rb +176 -0
- data/lib/flow_chat/instrumentation/metrics_collector.rb +197 -0
- data/lib/flow_chat/instrumentation/setup.rb +155 -0
- data/lib/flow_chat/instrumentation.rb +70 -0
- data/lib/flow_chat/prompt.rb +20 -20
- data/lib/flow_chat/session/cache_session_store.rb +73 -7
- data/lib/flow_chat/session/middleware.rb +37 -4
- data/lib/flow_chat/session/rails_session_store.rb +36 -1
- data/lib/flow_chat/simulator/controller.rb +7 -7
- data/lib/flow_chat/ussd/app.rb +1 -1
- data/lib/flow_chat/ussd/gateway/nalo.rb +30 -0
- data/lib/flow_chat/ussd/gateway/nsano.rb +33 -0
- data/lib/flow_chat/ussd/middleware/choice_mapper.rb +109 -0
- data/lib/flow_chat/ussd/middleware/executor.rb +24 -2
- data/lib/flow_chat/ussd/middleware/pagination.rb +87 -7
- data/lib/flow_chat/ussd/processor.rb +14 -0
- data/lib/flow_chat/ussd/renderer.rb +1 -1
- data/lib/flow_chat/version.rb +1 -1
- data/lib/flow_chat/whatsapp/app.rb +1 -1
- data/lib/flow_chat/whatsapp/client.rb +99 -12
- data/lib/flow_chat/whatsapp/configuration.rb +35 -4
- data/lib/flow_chat/whatsapp/gateway/cloud_api.rb +128 -54
- data/lib/flow_chat/whatsapp/middleware/executor.rb +24 -2
- data/lib/flow_chat/whatsapp/processor.rb +8 -0
- data/lib/flow_chat/whatsapp/renderer.rb +4 -9
- data/lib/flow_chat.rb +23 -0
- metadata +22 -11
- data/.travis.yml +0 -6
- data/app/controllers/demo_controller.rb +0 -101
- data/app/flow_chat/demo_restaurant_flow.rb +0 -889
- data/config/routes_demo.rb +0 -59
- data/examples/initializer.rb +0 -86
- data/examples/media_prompts_examples.rb +0 -27
- data/images/ussd_simulator.png +0 -0
data/config/routes_demo.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# Demo Routes Configuration for FlowChat Comprehensive Demo
|
2
|
-
#
|
3
|
-
# Add these routes to your config/routes.rb file to enable the demo endpoints
|
4
|
-
#
|
5
|
-
# Example integration:
|
6
|
-
# Rails.application.routes.draw do
|
7
|
-
# # Your existing routes...
|
8
|
-
#
|
9
|
-
# # FlowChat Demo Routes
|
10
|
-
# scope :demo do
|
11
|
-
# post 'ussd' => 'demo#ussd_demo'
|
12
|
-
# match 'whatsapp' => 'demo#whatsapp_demo', via: [:get, :post]
|
13
|
-
# match 'whatsapp_custom' => 'demo#whatsapp_custom_demo', via: [:get, :post]
|
14
|
-
# match 'whatsapp_background' => 'demo#whatsapp_background_demo', via: [:get, :post]
|
15
|
-
# match 'whatsapp_simulator' => 'demo#whatsapp_simulator_demo', via: [:get, :post]
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
|
19
|
-
Rails.application.routes.draw do
|
20
|
-
# FlowChat Comprehensive Demo Routes
|
21
|
-
scope :demo do
|
22
|
-
# USSD Demo
|
23
|
-
# Endpoint: POST /demo/ussd
|
24
|
-
# Purpose: Demonstrates USSD integration with all features
|
25
|
-
# Features: Pagination, session management, complex workflows
|
26
|
-
post 'ussd' => 'demo#ussd_demo'
|
27
|
-
|
28
|
-
# WhatsApp Demo (Standard)
|
29
|
-
# Endpoint: GET/POST /demo/whatsapp
|
30
|
-
# Purpose: Standard WhatsApp integration with media support
|
31
|
-
# Features: Rich media, interactive elements, buttons/lists
|
32
|
-
match 'whatsapp' => 'demo#whatsapp_demo', via: [:get, :post]
|
33
|
-
|
34
|
-
# WhatsApp Demo (Custom Configuration)
|
35
|
-
# Endpoint: GET/POST /demo/whatsapp_custom
|
36
|
-
# Purpose: Shows multi-tenant configuration capabilities
|
37
|
-
# Features: Custom credentials, per-endpoint configuration
|
38
|
-
match 'whatsapp_custom' => 'demo#whatsapp_custom_demo', via: [:get, :post]
|
39
|
-
|
40
|
-
# WhatsApp Demo (Background Processing)
|
41
|
-
# Endpoint: GET/POST /demo/whatsapp_background
|
42
|
-
# Purpose: Demonstrates background job integration
|
43
|
-
# Features: Asynchronous response delivery, job queuing
|
44
|
-
match 'whatsapp_background' => 'demo#whatsapp_background_demo', via: [:get, :post]
|
45
|
-
|
46
|
-
# WhatsApp Demo (Simulator Mode)
|
47
|
-
# Endpoint: GET/POST /demo/whatsapp_simulator
|
48
|
-
# Purpose: Testing mode that returns response data as JSON
|
49
|
-
# Features: No actual WhatsApp API calls, perfect for testing
|
50
|
-
match 'whatsapp_simulator' => 'demo#whatsapp_simulator_demo', via: [:get, :post]
|
51
|
-
end
|
52
|
-
|
53
|
-
# Optional: Simulator interface for testing
|
54
|
-
# Uncomment if you want to add the simulator UI
|
55
|
-
# get '/simulator' => 'simulator#index'
|
56
|
-
|
57
|
-
# Optional: API documentation endpoint
|
58
|
-
# get '/demo' => 'demo#index'
|
59
|
-
end
|
data/examples/initializer.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# Example FlowChat Initializer
|
2
|
-
# Add this to your Rails application as config/initializers/flow_chat.rb
|
3
|
-
|
4
|
-
# Configure cache for session storage
|
5
|
-
# This is required when using FlowChat::Session::CacheSessionStore
|
6
|
-
FlowChat::Config.cache = Rails.cache
|
7
|
-
|
8
|
-
# Alternative cache configurations:
|
9
|
-
|
10
|
-
# Use a specific cache store
|
11
|
-
# FlowChat::Config.cache = ActiveSupport::Cache::MemoryStore.new
|
12
|
-
|
13
|
-
# Use Redis (requires redis gem)
|
14
|
-
# FlowChat::Config.cache = ActiveSupport::Cache::RedisCacheStore.new(url: "redis://localhost:6379/1")
|
15
|
-
|
16
|
-
# Use Memcached (requires dalli gem)
|
17
|
-
# FlowChat::Config.cache = ActiveSupport::Cache::MemCacheStore.new("localhost:11211")
|
18
|
-
|
19
|
-
# Configure logger (optional)
|
20
|
-
FlowChat::Config.logger = Rails.logger
|
21
|
-
|
22
|
-
# Configure simulator security (REQUIRED for simulator mode)
|
23
|
-
# This secret is used to authenticate simulator requests via signed cookies
|
24
|
-
case Rails.env
|
25
|
-
when 'development', 'test'
|
26
|
-
# Use Rails secret key with environment suffix for development
|
27
|
-
FlowChat::Config.simulator_secret = Rails.application.secret_key_base + "_#{Rails.env}"
|
28
|
-
when 'staging', 'production'
|
29
|
-
# Use environment variable for production security
|
30
|
-
FlowChat::Config.simulator_secret = ENV['FLOWCHAT_SIMULATOR_SECRET']
|
31
|
-
|
32
|
-
# Fail fast if simulator secret is not configured but might be needed
|
33
|
-
if FlowChat::Config.simulator_secret.blank?
|
34
|
-
Rails.logger.warn "FLOWCHAT_SIMULATOR_SECRET not configured. Simulator mode will be unavailable."
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Configure USSD pagination (optional)
|
39
|
-
FlowChat::Config.ussd.pagination_page_size = 140
|
40
|
-
FlowChat::Config.ussd.pagination_back_option = "0"
|
41
|
-
FlowChat::Config.ussd.pagination_back_text = "Back"
|
42
|
-
FlowChat::Config.ussd.pagination_next_option = "#"
|
43
|
-
FlowChat::Config.ussd.pagination_next_text = "More"
|
44
|
-
|
45
|
-
# Configure resumable sessions (optional)
|
46
|
-
FlowChat::Config.ussd.resumable_sessions_enabled = true
|
47
|
-
FlowChat::Config.ussd.resumable_sessions_timeout_seconds = 300 # 5 minutes
|
48
|
-
|
49
|
-
# Configure WhatsApp message handling mode based on environment
|
50
|
-
case Rails.env
|
51
|
-
when 'development'
|
52
|
-
# Development: Use simulator mode for easy testing
|
53
|
-
FlowChat::Config.whatsapp.message_handling_mode = :simulator
|
54
|
-
|
55
|
-
when 'test'
|
56
|
-
# Test: Use simulator mode for deterministic testing
|
57
|
-
FlowChat::Config.whatsapp.message_handling_mode = :simulator
|
58
|
-
|
59
|
-
when 'staging'
|
60
|
-
# Staging: Use inline mode for real WhatsApp testing
|
61
|
-
FlowChat::Config.whatsapp.message_handling_mode = :inline
|
62
|
-
|
63
|
-
when 'production'
|
64
|
-
# Production: Use background mode for high volume
|
65
|
-
FlowChat::Config.whatsapp.message_handling_mode = :background
|
66
|
-
FlowChat::Config.whatsapp.background_job_class = 'WhatsappMessageJob'
|
67
|
-
end
|
68
|
-
|
69
|
-
# Configure per-environment WhatsApp security
|
70
|
-
# Note: These are global defaults. You can override per-configuration in your controllers.
|
71
|
-
|
72
|
-
# Example of per-environment WhatsApp security configuration:
|
73
|
-
#
|
74
|
-
# For development/test: You might want to disable signature validation for easier testing
|
75
|
-
# For staging: Enable validation to match production behavior
|
76
|
-
# For production: Always enable validation for security
|
77
|
-
#
|
78
|
-
# Individual WhatsApp configurations can override these settings:
|
79
|
-
#
|
80
|
-
# config = FlowChat::Whatsapp::Configuration.new
|
81
|
-
# config.access_token = "your_token"
|
82
|
-
# config.app_secret = "your_app_secret" # Required for webhook validation
|
83
|
-
# config.skip_signature_validation = false # false = validate signatures (recommended)
|
84
|
-
#
|
85
|
-
# Development override example:
|
86
|
-
# config.skip_signature_validation = Rails.env.development? # Only skip in development
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# Media Prompts Examples
|
2
|
-
# This file demonstrates how to attach media to prompts in FlowChat
|
3
|
-
|
4
|
-
# ============================================================================
|
5
|
-
# BASIC MEDIA PROMPTS
|
6
|
-
# ============================================================================
|
7
|
-
|
8
|
-
class MediaPromptFlow < FlowChat::Flow
|
9
|
-
def main_page
|
10
|
-
# ✅ Simple text input with attached image
|
11
|
-
# The prompt text becomes the image caption
|
12
|
-
app.screen(:feedback) do |prompt|
|
13
|
-
prompt.ask "What do you think of our new product?",
|
14
|
-
media: {
|
15
|
-
type: :image,
|
16
|
-
url: "https://cdn.example.com/products/new_product.jpg"
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
# ✅ Send media message with say
|
21
|
-
app.say "Thank you for your feedback! Here's what's coming next:",
|
22
|
-
media: {
|
23
|
-
type: :video,
|
24
|
-
url: "https://videos.example.com/roadmap.mp4"
|
25
|
-
}
|
26
|
-
end
|
27
|
-
end
|
data/images/ussd_simulator.png
DELETED
Binary file
|