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
@@ -1,101 +0,0 @@
|
|
1
|
-
# Demo Controller - Showcases FlowChat comprehensive features
|
2
|
-
#
|
3
|
-
# This controller demonstrates how to use the DemoRestaurantFlow
|
4
|
-
# across both USSD and WhatsApp platforms, showing off all FlowChat features.
|
5
|
-
#
|
6
|
-
# Features demonstrated:
|
7
|
-
# - Cross-platform compatibility
|
8
|
-
# - Media support with graceful degradation
|
9
|
-
# - Complex workflows with session management
|
10
|
-
# - Input validation and transformation
|
11
|
-
# - Rich interactive elements
|
12
|
-
|
13
|
-
class DemoController < ApplicationController
|
14
|
-
skip_forgery_protection
|
15
|
-
|
16
|
-
# USSD Demo Endpoint
|
17
|
-
# Usage: POST /demo/ussd
|
18
|
-
def ussd_demo
|
19
|
-
processor = FlowChat::Ussd::Processor.new(self) do |config|
|
20
|
-
config.use_gateway FlowChat::Ussd::Gateway::Nalo
|
21
|
-
config.use_session_store FlowChat::Session::RailsSessionStore
|
22
|
-
|
23
|
-
# Optional: Enable resumable sessions for better UX
|
24
|
-
config.use_resumable_sessions
|
25
|
-
|
26
|
-
# Optional: Custom pagination settings for large menus
|
27
|
-
FlowChat::Config.ussd.pagination_page_size = 120 # Slightly larger for demo
|
28
|
-
end
|
29
|
-
|
30
|
-
processor.run DemoRestaurantFlow, :main_page
|
31
|
-
end
|
32
|
-
|
33
|
-
# WhatsApp Demo Endpoint
|
34
|
-
# Usage: GET/POST /demo/whatsapp
|
35
|
-
def whatsapp_demo
|
36
|
-
processor = FlowChat::Whatsapp::Processor.new(self, enable_simulator: Rails.env.development?) do |config|
|
37
|
-
config.use_gateway FlowChat::Whatsapp::Gateway::CloudApi
|
38
|
-
config.use_session_store FlowChat::Session::CacheSessionStore
|
39
|
-
end
|
40
|
-
|
41
|
-
processor.run DemoRestaurantFlow, :main_page
|
42
|
-
end
|
43
|
-
|
44
|
-
# Alternative WhatsApp Demo with Custom Configuration
|
45
|
-
# Usage: GET/POST /demo/whatsapp_custom
|
46
|
-
def whatsapp_custom_demo
|
47
|
-
# Custom configuration for multi-tenant demo
|
48
|
-
custom_config = FlowChat::Whatsapp::Configuration.new
|
49
|
-
custom_config.access_token = ENV['DEMO_WHATSAPP_ACCESS_TOKEN']
|
50
|
-
custom_config.phone_number_id = ENV['DEMO_WHATSAPP_PHONE_NUMBER_ID']
|
51
|
-
custom_config.verify_token = ENV['DEMO_WHATSAPP_VERIFY_TOKEN']
|
52
|
-
custom_config.app_secret = ENV['DEMO_WHATSAPP_APP_SECRET']
|
53
|
-
custom_config.skip_signature_validation = Rails.env.development?
|
54
|
-
|
55
|
-
processor = FlowChat::Whatsapp::Processor.new(self, enable_simulator: true) do |config|
|
56
|
-
config.use_gateway FlowChat::Whatsapp::Gateway::CloudApi, custom_config
|
57
|
-
config.use_session_store FlowChat::Session::CacheSessionStore
|
58
|
-
end
|
59
|
-
|
60
|
-
processor.run DemoRestaurantFlow, :main_page
|
61
|
-
end
|
62
|
-
|
63
|
-
# Background Mode Demo
|
64
|
-
# Usage: GET/POST /demo/whatsapp_background
|
65
|
-
def whatsapp_background_demo
|
66
|
-
# Configure for background processing
|
67
|
-
original_mode = FlowChat::Config.whatsapp.message_handling_mode
|
68
|
-
FlowChat::Config.whatsapp.message_handling_mode = :background
|
69
|
-
FlowChat::Config.whatsapp.background_job_class = 'DemoWhatsappJob'
|
70
|
-
|
71
|
-
processor = FlowChat::Whatsapp::Processor.new(self) do |config|
|
72
|
-
config.use_gateway FlowChat::Whatsapp::Gateway::CloudApi
|
73
|
-
config.use_session_store FlowChat::Session::CacheSessionStore
|
74
|
-
end
|
75
|
-
|
76
|
-
processor.run DemoRestaurantFlow, :main_page
|
77
|
-
|
78
|
-
ensure
|
79
|
-
# Restore original mode
|
80
|
-
FlowChat::Config.whatsapp.message_handling_mode = original_mode
|
81
|
-
end
|
82
|
-
|
83
|
-
# Simulator Mode Demo (for testing)
|
84
|
-
# Usage: GET/POST /demo/whatsapp_simulator
|
85
|
-
def whatsapp_simulator_demo
|
86
|
-
# Force simulator mode for testing
|
87
|
-
original_mode = FlowChat::Config.whatsapp.message_handling_mode
|
88
|
-
FlowChat::Config.whatsapp.message_handling_mode = :simulator
|
89
|
-
|
90
|
-
processor = FlowChat::Whatsapp::Processor.new(self, enable_simulator: true) do |config|
|
91
|
-
config.use_gateway FlowChat::Whatsapp::Gateway::CloudApi
|
92
|
-
config.use_session_store FlowChat::Session::CacheSessionStore
|
93
|
-
end
|
94
|
-
|
95
|
-
processor.run DemoRestaurantFlow, :main_page
|
96
|
-
|
97
|
-
ensure
|
98
|
-
# Restore original mode
|
99
|
-
FlowChat::Config.whatsapp.message_handling_mode = original_mode
|
100
|
-
end
|
101
|
-
end
|