flow_chat 0.5.2 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a04a5ad026a67e7ce71aa0a22a3b5522da80cf0da4552280853154e91bc1a27
4
- data.tar.gz: 515908f7a643eb53dd7ce542aa7005f54eb1127b640b4d3b834f1891137a2d16
3
+ metadata.gz: 7acb16ea89a86c4680cd499207fe48763bf91de4937b8ad3474ce22c27194ca7
4
+ data.tar.gz: fc79cb9fffa808baeb2abddf72119536e16661f54cb2644dc04d89f8983fe1b0
5
5
  SHA512:
6
- metadata.gz: 515db13100618aa0150672a08c960ef08c6661171e926694580c91d3a9d5dc1decf2b6698ae6beca128ae24b3ee314779e82fec3f37a16b97aa5a3e96157b04a
7
- data.tar.gz: a1846f20afce50943626bb5c0c617e4e7d5a6fa445d9cd0be4fdfaf5438ab29b3201b6e4c3e90cd9d73feef16bac2607017f0fa8cea5a6b472feb5213a25227a
6
+ metadata.gz: ae0c2b313390de0311fce7030f4577ea5ae127e8f6241fecd6d7e8c6bf1b210d1aa98a2878accf2ea5069f89dc8fd766ff0fb800e9cddf123ccd7c7aedfd374c
7
+ data.tar.gz: 462d4f8caeb6a1a9f11809c25195e439bb0ffff174343d07daf7407f765c62740ca40dff5fa9367e1ddb36775ce774d325076ad5ac9bbc3cfe2ef8b7b5e95b67
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::RailsSessionStore
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::RailsSessionStore
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::RailsSessionStore
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::RailsSessionStore
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