flow_chat 0.5.1 → 0.6.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/README.md +50 -5
- data/app/controllers/demo_controller.rb +101 -0
- data/app/flow_chat/demo_restaurant_flow.rb +889 -0
- data/config/routes_demo.rb +59 -0
- data/lib/flow_chat/base_processor.rb +1 -1
- data/lib/flow_chat/config.rb +3 -0
- data/lib/flow_chat/interrupt.rb +6 -5
- data/lib/flow_chat/prompt.rb +91 -0
- data/lib/flow_chat/simulator/views/simulator.html.erb +4 -4
- data/lib/flow_chat/ussd/app.rb +2 -2
- data/lib/flow_chat/ussd/gateway/nalo.rb +4 -4
- data/lib/flow_chat/ussd/middleware/executor.rb +2 -2
- data/lib/flow_chat/ussd/middleware/pagination.rb +35 -18
- data/lib/flow_chat/ussd/renderer.rb +28 -3
- data/lib/flow_chat/version.rb +1 -1
- data/lib/flow_chat/whatsapp/app.rb +3 -3
- data/lib/flow_chat/whatsapp/client.rb +22 -15
- data/lib/flow_chat/whatsapp/gateway/cloud_api.rb +36 -12
- data/lib/flow_chat/whatsapp/middleware/executor.rb +3 -3
- data/lib/flow_chat/whatsapp/renderer.rb +191 -0
- data/lib/flow_chat.rb +1 -0
- metadata +6 -3
- data/lib/flow_chat/ussd/prompt.rb +0 -102
- data/lib/flow_chat/whatsapp/prompt.rb +0 -247
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c175da6eda53d8aede833db06dd560278a8276254877c3a407230cc73f6db8bc
|
4
|
+
data.tar.gz: 631339558c79d26a6c1013e4946a23415fb31e45752f02ab4b0edad980afea8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6893e1040fb1c1e1316d1e242787c6616128a2c4be7c4c0f78b99d4e3b27567ff886d1c4035f35442e6dd6497d5a11da0f3564407bb0a2d2ee3ee33358527ed9
|
7
|
+
data.tar.gz: 0b32ee8a7e375758da178e0bb51411e4f980541ab37de7ddfb470a9abe3500141af81e0b0f02464a066675a7a18c3eced9e89b97f465b661e9b0297482edc846
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ class UssdController < ApplicationController
|
|
77
77
|
def process_request
|
78
78
|
processor = FlowChat::Ussd::Processor.new(self) do |config|
|
79
79
|
config.use_gateway FlowChat::Ussd::Gateway::Nalo
|
80
|
-
config.use_session_store FlowChat::Session::
|
80
|
+
config.use_session_store FlowChat::Session::CacheSessionStore
|
81
81
|
end
|
82
82
|
|
83
83
|
processor.run WelcomeFlow, :main_page
|
@@ -485,7 +485,7 @@ end
|
|
485
485
|
|
486
486
|
## Cross-Platform Compatibility
|
487
487
|
|
488
|
-
FlowChat provides a unified API that works across both USSD and WhatsApp platforms, with graceful degradation for platform-specific features
|
488
|
+
FlowChat provides a unified API that works across both USSD and WhatsApp platforms, with graceful degradation for platform-specific features. Under the hood, FlowChat uses a unified prompt architecture that ensures consistent behavior across platforms while optimizing the user experience for each channel.
|
489
489
|
|
490
490
|
### Shared Features (Both USSD & WhatsApp)
|
491
491
|
- ✅ `app.screen()` - Interactive screens with prompts
|
@@ -773,6 +773,46 @@ app.screen(:credit_card) do |prompt|
|
|
773
773
|
end
|
774
774
|
```
|
775
775
|
|
776
|
+
### Validation Error Display
|
777
|
+
|
778
|
+
Configure how validation errors are displayed to users:
|
779
|
+
|
780
|
+
```ruby
|
781
|
+
# config/initializers/flowchat.rb
|
782
|
+
|
783
|
+
# Default behavior: combine error with original message
|
784
|
+
FlowChat::Config.combine_validation_error_with_message = true
|
785
|
+
# User sees: "Card number must be 16 digits\n\nEnter credit card number:"
|
786
|
+
|
787
|
+
# Show only the error message
|
788
|
+
FlowChat::Config.combine_validation_error_with_message = false
|
789
|
+
# User sees: "Card number must be 16 digits"
|
790
|
+
```
|
791
|
+
|
792
|
+
**Use cases for each approach:**
|
793
|
+
|
794
|
+
- **Combined (default)**: Better for first-time users who need context about what they're entering
|
795
|
+
- **Error only**: Cleaner UX for experienced users, reduces message length for USSD character limits
|
796
|
+
|
797
|
+
**Example with both approaches:**
|
798
|
+
|
799
|
+
```ruby
|
800
|
+
# This validation code works the same way regardless of config
|
801
|
+
age = app.screen(:age) do |prompt|
|
802
|
+
prompt.ask "How old are you?",
|
803
|
+
convert: ->(input) { input.to_i },
|
804
|
+
validate: ->(input) { "You must be at least 18 years old" unless input >= 18 }
|
805
|
+
end
|
806
|
+
|
807
|
+
# With combine_validation_error_with_message = true (default):
|
808
|
+
# "You must be at least 18 years old
|
809
|
+
#
|
810
|
+
# How old are you?"
|
811
|
+
|
812
|
+
# With combine_validation_error_with_message = false:
|
813
|
+
# "You must be at least 18 years old"
|
814
|
+
```
|
815
|
+
|
776
816
|
### Background Job Support
|
777
817
|
|
778
818
|
For high-volume WhatsApp applications, use background response delivery:
|
@@ -861,7 +901,7 @@ processor = FlowChat::Ussd::Processor.new(self) do |config|
|
|
861
901
|
config.use_gateway FlowChat::Ussd::Gateway::Nalo
|
862
902
|
|
863
903
|
# Session storage (required)
|
864
|
-
config.use_session_store FlowChat::Session::
|
904
|
+
config.use_session_store FlowChat::Session::CacheSessionStore
|
865
905
|
|
866
906
|
# Add custom middleware (optional)
|
867
907
|
config.use_middleware MyLoggingMiddleware
|
@@ -906,7 +946,7 @@ FlowChat::Config.ussd.pagination_back_text = "Back" # Default: "Back"
|
|
906
946
|
```ruby
|
907
947
|
processor = FlowChat::Ussd::Processor.new(self) do |config|
|
908
948
|
config.use_gateway FlowChat::Ussd::Gateway::Nalo
|
909
|
-
config.use_session_store FlowChat::Session::
|
949
|
+
config.use_session_store FlowChat::Session::CacheSessionStore
|
910
950
|
config.use_resumable_sessions # Enable resumable sessions
|
911
951
|
end
|
912
952
|
```
|
@@ -933,7 +973,7 @@ end
|
|
933
973
|
# Use your custom middleware
|
934
974
|
processor = FlowChat::Ussd::Processor.new(self) do |config|
|
935
975
|
config.use_gateway FlowChat::Ussd::Gateway::Nalo
|
936
|
-
config.use_session_store FlowChat::Session::
|
976
|
+
config.use_session_store FlowChat::Session::CacheSessionStore
|
937
977
|
config.use_middleware LoggingMiddleware
|
938
978
|
end
|
939
979
|
```
|
@@ -1085,6 +1125,11 @@ FlowChat::Config.logger = Rails.logger
|
|
1085
1125
|
FlowChat::Config.cache = Rails.cache
|
1086
1126
|
FlowChat::Config.simulator_secret = "your_secure_secret_here"
|
1087
1127
|
|
1128
|
+
# Validation error display behavior
|
1129
|
+
# When true (default), validation errors are combined with the original message.
|
1130
|
+
# When false, only the validation error message is shown to the user.
|
1131
|
+
FlowChat::Config.combine_validation_error_with_message = true
|
1132
|
+
|
1088
1133
|
# USSD configuration
|
1089
1134
|
FlowChat::Config.ussd.pagination_page_size = 140
|
1090
1135
|
FlowChat::Config.ussd.pagination_next_option = "#"
|
@@ -0,0 +1,101 @@
|
|
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
|