flow_chat 0.8.0 → 0.8.2
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/docs/configuration.md +2 -2
- data/docs/http-gateway-protocol.md +432 -0
- data/docs/sessions.md +7 -7
- data/docs/ussd-setup.md +1 -1
- data/examples/http_controller.rb +154 -0
- data/examples/simulator_controller.rb +21 -1
- data/examples/ussd_controller.rb +1 -1
- data/lib/flow_chat/base_app.rb +86 -0
- data/lib/flow_chat/base_executor.rb +57 -0
- data/lib/flow_chat/base_processor.rb +7 -6
- data/lib/flow_chat/config.rb +17 -2
- data/lib/flow_chat/http/app.rb +6 -0
- data/lib/flow_chat/http/gateway/simple.rb +77 -0
- data/lib/flow_chat/http/middleware/executor.rb +24 -0
- data/lib/flow_chat/http/processor.rb +33 -0
- data/lib/flow_chat/http/renderer.rb +41 -0
- data/lib/flow_chat/instrumentation/setup.rb +0 -2
- data/lib/flow_chat/instrumentation.rb +2 -0
- data/lib/flow_chat/interrupt.rb +6 -0
- data/lib/flow_chat/phone_number_util.rb +47 -0
- data/lib/flow_chat/session/cache_session_store.rb +1 -17
- data/lib/flow_chat/session/middleware.rb +19 -18
- data/lib/flow_chat/simulator/controller.rb +17 -5
- data/lib/flow_chat/simulator/views/simulator.html.erb +220 -8
- data/lib/flow_chat/ussd/app.rb +1 -53
- data/lib/flow_chat/ussd/gateway/nalo.rb +3 -7
- data/lib/flow_chat/ussd/gateway/nsano.rb +0 -2
- data/lib/flow_chat/ussd/middleware/executor.rb +11 -37
- data/lib/flow_chat/version.rb +1 -1
- data/lib/flow_chat/whatsapp/app.rb +11 -46
- data/lib/flow_chat/whatsapp/gateway/cloud_api.rb +16 -14
- data/lib/flow_chat/whatsapp/middleware/executor.rb +11 -39
- data/lib/flow_chat.rb +1 -11
- metadata +12 -2
@@ -1,49 +1,21 @@
|
|
1
|
+
require_relative "../../base_executor"
|
2
|
+
|
1
3
|
module FlowChat
|
2
4
|
module Whatsapp
|
3
5
|
module Middleware
|
4
|
-
class Executor
|
5
|
-
|
6
|
-
@app = app
|
7
|
-
FlowChat.logger.debug { "Whatsapp::Executor: Initialized WhatsApp executor middleware" }
|
8
|
-
end
|
9
|
-
|
10
|
-
def call(context)
|
11
|
-
flow_class = context.flow
|
12
|
-
action = context["flow.action"]
|
13
|
-
session_id = context["session.id"]
|
14
|
-
|
15
|
-
FlowChat.logger.info { "Whatsapp::Executor: Executing flow #{flow_class.name}##{action} for session #{session_id}" }
|
6
|
+
class Executor < FlowChat::BaseExecutor
|
7
|
+
protected
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
flow = flow_class.new whatsapp_app
|
21
|
-
FlowChat.logger.debug { "Whatsapp::Executor: Flow instance created, invoking #{action} method" }
|
22
|
-
|
23
|
-
flow.send action
|
24
|
-
FlowChat.logger.warn { "Whatsapp::Executor: Flow execution failed to interact with user for #{flow_class.name}##{action}" }
|
25
|
-
raise FlowChat::Interrupt::Terminate, "Unexpected end of flow."
|
26
|
-
rescue FlowChat::Interrupt::Prompt => e
|
27
|
-
FlowChat.logger.info { "Whatsapp::Executor: Flow prompted user - Session: #{session_id}, Prompt: '#{e.prompt.truncate(100)}'" }
|
28
|
-
FlowChat.logger.debug { "Whatsapp::Executor: Prompt details - Choices: #{e.choices&.size || 0}, Has media: #{!e.media.nil?}" }
|
29
|
-
# Return the same triplet format as USSD for consistency
|
30
|
-
[:prompt, e.prompt, e.choices, e.media]
|
31
|
-
rescue FlowChat::Interrupt::Terminate => e
|
32
|
-
FlowChat.logger.info { "Whatsapp::Executor: Flow terminated - Session: #{session_id}, Message: '#{e.prompt.truncate(100)}'" }
|
33
|
-
FlowChat.logger.debug { "Whatsapp::Executor: Destroying session #{session_id}" }
|
34
|
-
# Clean up session and return terminal message
|
35
|
-
context.session.destroy
|
36
|
-
[:terminate, e.prompt, nil, e.media]
|
37
|
-
rescue => error
|
38
|
-
FlowChat.logger.error { "Whatsapp::Executor: Flow execution failed - #{flow_class.name}##{action}, Session: #{session_id}, Error: #{error.class.name}: #{error.message}" }
|
39
|
-
FlowChat.logger.debug { "Whatsapp::Executor: Stack trace: #{error.backtrace.join("\n")}" }
|
40
|
-
raise
|
9
|
+
def platform_name
|
10
|
+
"WhatsApp"
|
41
11
|
end
|
42
12
|
|
43
|
-
|
13
|
+
def log_prefix
|
14
|
+
"Whatsapp::Executor"
|
15
|
+
end
|
44
16
|
|
45
|
-
def
|
46
|
-
FlowChat.logger.debug { "
|
17
|
+
def build_platform_app(context)
|
18
|
+
FlowChat.logger.debug { "#{log_prefix}: Building WhatsApp app instance" }
|
47
19
|
FlowChat::Whatsapp::App.new(context)
|
48
20
|
end
|
49
21
|
end
|
data/lib/flow_chat.rb
CHANGED
@@ -15,7 +15,6 @@ module FlowChat
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.setup_instrumentation!
|
18
|
-
require_relative "flow_chat/instrumentation/setup"
|
19
18
|
FlowChat::Instrumentation::Setup.setup_instrumentation!
|
20
19
|
end
|
21
20
|
|
@@ -27,13 +26,4 @@ module FlowChat
|
|
27
26
|
def self.metrics
|
28
27
|
FlowChat::Instrumentation::Setup.metrics_collector
|
29
28
|
end
|
30
|
-
end
|
31
|
-
|
32
|
-
loader.eager_load
|
33
|
-
|
34
|
-
# Auto-setup instrumentation in Rails environments
|
35
|
-
if defined?(Rails)
|
36
|
-
Rails.application.config.after_initialize do
|
37
|
-
FlowChat.setup_instrumentation!
|
38
|
-
end
|
39
|
-
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow_chat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Froelich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-06-
|
11
|
+
date: 2025-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- bin/setup
|
105
105
|
- docs/configuration.md
|
106
106
|
- docs/flows.md
|
107
|
+
- docs/http-gateway-protocol.md
|
107
108
|
- docs/images/simulator.png
|
108
109
|
- docs/instrumentation.md
|
109
110
|
- docs/media.md
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- docs/testing.md
|
112
113
|
- docs/ussd-setup.md
|
113
114
|
- docs/whatsapp-setup.md
|
115
|
+
- examples/http_controller.rb
|
114
116
|
- examples/multi_tenant_whatsapp_controller.rb
|
115
117
|
- examples/simulator_controller.rb
|
116
118
|
- examples/ussd_controller.rb
|
@@ -119,15 +121,23 @@ files:
|
|
119
121
|
- examples/whatsapp_message_job.rb
|
120
122
|
- flow_chat.gemspec
|
121
123
|
- lib/flow_chat.rb
|
124
|
+
- lib/flow_chat/base_app.rb
|
125
|
+
- lib/flow_chat/base_executor.rb
|
122
126
|
- lib/flow_chat/base_processor.rb
|
123
127
|
- lib/flow_chat/config.rb
|
124
128
|
- lib/flow_chat/context.rb
|
125
129
|
- lib/flow_chat/flow.rb
|
130
|
+
- lib/flow_chat/http/app.rb
|
131
|
+
- lib/flow_chat/http/gateway/simple.rb
|
132
|
+
- lib/flow_chat/http/middleware/executor.rb
|
133
|
+
- lib/flow_chat/http/processor.rb
|
134
|
+
- lib/flow_chat/http/renderer.rb
|
126
135
|
- lib/flow_chat/instrumentation.rb
|
127
136
|
- lib/flow_chat/instrumentation/log_subscriber.rb
|
128
137
|
- lib/flow_chat/instrumentation/metrics_collector.rb
|
129
138
|
- lib/flow_chat/instrumentation/setup.rb
|
130
139
|
- lib/flow_chat/interrupt.rb
|
140
|
+
- lib/flow_chat/phone_number_util.rb
|
131
141
|
- lib/flow_chat/prompt.rb
|
132
142
|
- lib/flow_chat/session/cache_session_store.rb
|
133
143
|
- lib/flow_chat/session/middleware.rb
|