flow_chat 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6eba909e6ae38dfeb26be6f854b185ca2c8097397aa4eea8a094d47e1d3fcd56
4
- data.tar.gz: c47e6bf434684b87c7f0c8b2ebb9b6536c5bc17efe46fa3bec3876b976401f96
3
+ metadata.gz: 6c1e5cd739c50f112b6a5637e712756e0b96bdb18c2276c7d30db2b2a071cc23
4
+ data.tar.gz: f701ad5050599c06b87eba80841823b04eef156e7ea3e77527a0be91519b0d48
5
5
  SHA512:
6
- metadata.gz: f52ba0115aa8000f9de120d436c9800318c8635efa86979b17f2dc01104d6ae65f66dcc193ada68a0a36ff238e9b6a87ef9ee66e00581ca4b5faa72a31fb25a0
7
- data.tar.gz: 508138465e83f318e8e889f4e11ea19a709fc06c310b76c44388f56b84c94521fa44b45cc734fcfc07acf3b1cf38bbc764614e1d7252ee7b40ab4e0a20c55877
6
+ metadata.gz: ef7e1721b7c5453130999b2ef899af4f20ba6db81ac4b3956ce7ade5956bf2b61e248b2be66ace885c633d4d612025208b31d1ff081ef1a0d671f579e0d3db38
7
+ data.tar.gz: 2581189b102229a0e8843691f38eaf91a9c7bf1d2db7c7a71e685124a849621cf55bdd33c6cdd1c928e2bfac051bca597601875dc9cff921063a98ff954a7b82
data/.DS_Store ADDED
Binary file
data/README.md CHANGED
@@ -1,28 +1,147 @@
1
1
  # FlowChat
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flow_chat`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ FlowChat is a Rails framework designed for crafting Menu-based conversation workflows, such as those used in USSD systems. It introduces an intuitive approach to defining conversation flows in Ruby, facilitating clear and logical flow development. Currently supporting USSD with plans to extend functionality to WhatsApp and Telegram, FlowChat makes multi-channel user interaction seamless and efficient.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The framework's architecture leverages a middleware processing pipeline, offering flexibility in customizing the conversation handling process.
6
6
 
7
- ## Installation
7
+ ## Getting Started
8
8
 
9
- Add this line to your application's Gemfile:
9
+ ### Installation
10
+
11
+ Incorporate FlowChat into your Rails project by adding the following line to your Gemfile:
10
12
 
11
13
  ```ruby
12
- gem 'flow_chat'
14
+ gem 'flow_chat', '~> 0.2.0'
15
+ ```
16
+
17
+ Then, execute:
18
+
19
+ ```bash
20
+ bundle install
13
21
  ```
14
22
 
15
- And then execute:
23
+ Alternatively, you can install it directly using:
24
+
25
+ ```bash
26
+ gem install flow_chat
27
+ ```
28
+
29
+ ### Basic Usage
30
+
31
+ #### Building Your First Flow
32
+
33
+ Create a new class derived from `FlowChat::Flow` to define your conversation flow. It's recommended to place your flow definitions under `app/flow_chat`.
34
+
35
+ For a simple "Hello World" flow:
36
+
37
+ ```ruby
38
+ class HelloWorldFlow < FlowChat::Flow
39
+ def main_page
40
+ app.say "Hello World!"
41
+ end
42
+ end
43
+ ```
44
+
45
+ The `app` instance within `FlowChat::Flow` provides methods to interact with and respond to the user, such as `app.say`, which sends a message to the user.
46
+
47
+ #### Integration with USSD
48
+
49
+ Given that most USSD gateways interact via HTTP, set up a controller to handle the conversation flow:
50
+
51
+ ```ruby
52
+ class UssdDemoController < ApplicationController
53
+ skip_forgery_protection
54
+
55
+ def hello_world
56
+ ussd_processor.run HelloWorldFlow, :main_page
57
+ end
58
+
59
+ private
60
+
61
+ def ussd_processor
62
+ @ussd_processor ||= FlowChat::Ussd::Processor.new(self) do |processor|
63
+ processor.use_gateway FlowChat::Ussd::Gateway::Nalo
64
+ processor.use_session_store FlowChat::Session::RailsSessionStore
65
+ end
66
+ end
67
+ end
68
+ ```
69
+
70
+ This controller initializes a `FlowChat::Ussd::Processor` specifying the use of Nalo Solutions' gateway and a session storage mechanism. Here, `RailsSessionStore` is chosen for simplicity and demonstration purposes.
71
+
72
+ Bind the controller action to a route:
16
73
 
17
- $ bundle install
74
+ ```ruby
75
+ Rails.application.routes.draw do
76
+ post 'ussd_hello_world' => 'ussd_demo#hello_world'
77
+ end
78
+ ```
79
+
80
+ #### Testing with the USSD Simulator
81
+
82
+ FlowChat comes with a USSD simulator for local testing:
83
+
84
+ ```ruby
85
+ class UssdSimulatorController < ApplicationController
86
+ include FlowChat::Ussd::Simulator::Controller
87
+
88
+ protected
89
+
90
+ def default_endpoint
91
+ '/ussd_hello_world'
92
+ end
93
+
94
+ def default_provider
95
+ :nalo
96
+ end
97
+ end
98
+ ```
99
+
100
+ And set up the corresponding route:
101
+
102
+ ```ruby
103
+ Rails.application.routes.draw do
104
+ get 'ussd_simulator' => 'ussd_simulator#ussd_simulator'
105
+ end
106
+ ```
107
+
108
+ Visit [http://localhost:3000/ussd_simulator](http://localhost:3000/ussd_simulator) to initiate and test your flow.
109
+
110
+ ### Advanced Usage: Implementing Multiple Screens
111
+
112
+ To engage users with a multi-step interaction, define a flow with multiple screens:
113
+
114
+ ```ruby
115
+ class MultipleScreensFlow < FlowChat::Flow
116
+ def main_page
117
+ name = app.screen(:name) { |prompt|
118
+ prompt.ask "What is your name?", transform: ->(input) { input.squish }
119
+ }
120
+
121
+ age = app.screen(:age) do |prompt|
122
+ prompt.ask "How old are you?",
123
+ convert: ->(input) { input.to_i },
124
+ validate: ->(input) { "You must be at least 13 years old" unless input >= 13 }
125
+ end
126
+
127
+ gender = app.screen(:gender) { |prompt| prompt.select "What is your gender", ["Male", "Female"] }
128
+
129
+ confirm = app.screen(:confirm) do |prompt|
130
+ prompt.yes?("Is this correct?\n\nName: #{name}\nAge: #{age}\nGender: #{gender}")
131
+ end
132
+
133
+ app.say confirm ? "Thank you for confirming" : "Please try again"
134
+ end
135
+ end
136
+ ```
18
137
 
19
- Or install it yourself as:
138
+ This example illustrates a flow that collects and confirms user information across multiple interaction steps, showcasing FlowChat's capability to handle complex conversation logic effortlessly.
20
139
 
21
- $ gem install flow_chat
140
+ TODO:
22
141
 
23
- ## Usage
142
+ ### Sub Flows
24
143
 
25
- TODO: Write usage instructions here
144
+ TODO:
26
145
 
27
146
  ## Development
28
147
 
data/flow_chat.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Stefan Froelich"]
7
7
  spec.email = ["sfroelich01@gmail.com"]
8
8
 
9
- spec.summary = "Framework for processing Menu based conversations e.g. USSD in Rails."
10
- spec.description = "Framework for processing Menu based conversations e.g. USSD in Rails."
9
+ spec.summary = "Framework for building Menu based conversations (e.g. USSD) in Rails."
10
+ spec.description = "Framework for building Menu based conversations (e.g. USSD) in Rails."
11
11
  spec.homepage = "https://github.com/radioactive-labs/flow_chat"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
Binary file
@@ -0,0 +1,9 @@
1
+ module FlowChat
2
+ class Flow
3
+ attr_reader :app
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+ end
9
+ end
@@ -25,7 +25,7 @@ module FlowChat
25
25
  value
26
26
  end
27
27
 
28
- def terminate!(msg)
28
+ def say(msg)
29
29
  raise FlowChat::Interrupt::Terminate.new(msg)
30
30
  end
31
31
  end
@@ -40,22 +40,22 @@
40
40
  </head>
41
41
  <body>
42
42
  <div class="content">
43
- <div class="field hidden<%= show_options ? '' : 'hidden' %>">
43
+ <div class="field <%= show_options ? '' : 'hidden' %>">
44
44
  <div class="label">Provider </div>
45
45
  <div class="value">
46
46
  <select id="provider">
47
- <option <%= default_provider == :nalo ? 'selected' : '' %> value="nalo">Nalo</option>
48
- <option <%= default_provider == :nsano ? 'selected' : '' %> value="nsano">Nsano</option>
47
+ <option <%= default_provider == :nalo ? 'selected' : '' %> value="nalo">Nalo</option>
48
+ <option <%= default_provider == :nsano ? 'selected' : '' %> value="nsano">Nsano</option>
49
49
  </select>
50
50
  </div>
51
51
  </div>
52
- <div class="field <%= show_options ? '' : 'hidden' %>">
52
+ <div class="field <%= show_options ? '' : 'hidden' %>">
53
53
  <div class="label">Endpoint </div>
54
54
  <div class="value">
55
55
  <input id="endpoint" value="<%= default_endpoint %>" />
56
56
  </div>
57
57
  </div>
58
- <div class="field <%= show_options ? '' : 'hidden' %>">
58
+ <div class="field <%= show_options ? '' : 'hidden' %>">
59
59
  <div class="label">MSISDN </div>
60
60
  <div class="value">
61
61
  <input id="msisdn" value="<%= default_msisdn %>" />
@@ -1,3 +1,3 @@
1
1
  module FlowChat
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flow_chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
@@ -80,13 +80,14 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.4.2
83
- description: Framework for processing Menu based conversations e.g. USSD in Rails.
83
+ description: Framework for building Menu based conversations (e.g. USSD) in Rails.
84
84
  email:
85
85
  - sfroelich01@gmail.com
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".DS_Store"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
93
  - ".travis.yml"
@@ -97,9 +98,11 @@ files:
97
98
  - bin/console
98
99
  - bin/setup
99
100
  - flow_chat.gemspec
101
+ - images/ussd_simulator.png
100
102
  - lib/flow_chat.rb
101
103
  - lib/flow_chat/config.rb
102
104
  - lib/flow_chat/context.rb
105
+ - lib/flow_chat/flow.rb
103
106
  - lib/flow_chat/interrupt.rb
104
107
  - lib/flow_chat/session/middleware.rb
105
108
  - lib/flow_chat/session/rails_session_store.rb
@@ -141,5 +144,5 @@ requirements: []
141
144
  rubygems_version: 3.5.6
142
145
  signing_key:
143
146
  specification_version: 4
144
- summary: Framework for processing Menu based conversations e.g. USSD in Rails.
147
+ summary: Framework for building Menu based conversations (e.g. USSD) in Rails.
145
148
  test_files: []