stealth 0.10.4 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +8 -8
  3. data/VERSION +1 -1
  4. data/lib/stealth/cli.rb +22 -0
  5. data/lib/stealth/generators/builder.rb +37 -0
  6. data/lib/stealth/generators/builder/Gemfile +12 -0
  7. data/lib/stealth/generators/builder/bot/controllers/bot_controller.rb +11 -0
  8. data/lib/stealth/generators/builder/bot/controllers/catch_alls_controller.rb +22 -0
  9. data/lib/stealth/generators/builder/bot/controllers/goodbyes_controller.rb +7 -0
  10. data/lib/stealth/generators/builder/bot/controllers/hellos_controller.rb +7 -0
  11. data/lib/stealth/generators/builder/bot/flow_map.rb.tt +17 -0
  12. data/lib/stealth/generators/builder/bot/helpers/bot_helper.rb +2 -0
  13. data/lib/stealth/generators/builder/bot/replies/catch_alls/catch_all.yml +0 -0
  14. data/lib/stealth/generators/builder/bot/replies/goodbyes/say_goodbye.yml +0 -0
  15. data/lib/stealth/generators/builder/bot/replies/hellos/say_hello.yml +2 -0
  16. data/lib/stealth/generators/builder/config.ru +4 -0
  17. data/lib/stealth/generators/builder/config/boot.rb +6 -0
  18. data/lib/stealth/generators/builder/config/environment.rb +4 -0
  19. data/lib/stealth/generators/builder/config/initializers/.keep +0 -0
  20. data/lib/stealth/generators/builder/config/puma.rb +10 -0
  21. data/lib/stealth/generators/builder/config/services.yml +36 -0
  22. data/lib/stealth/generators/builder/config/sidekiq.yml +3 -0
  23. data/lib/stealth/generators/builder/readme.md +1 -0
  24. data/lib/stealth/generators/generate.rb +37 -0
  25. data/lib/stealth/generators/generate/flow/controllers/controller.tt +26 -0
  26. data/lib/stealth/generators/generate/flow/helpers/helper.tt +2 -0
  27. data/lib/stealth/generators/generate/flow/replies/ask_reply.tt +9 -0
  28. data/lib/stealth/generators/generate/flow/replies/say_no_reply.tt +2 -0
  29. data/lib/stealth/generators/generate/flow/replies/say_yes_reply.tt +2 -0
  30. metadata +27 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7066a33db237e17ba73f818c95699faf001f32fb725f3aeda7d6b43d7a3348a
4
- data.tar.gz: 10335bd9447c9e0f4fd1c7138b725fa288b0e352ace0d5cb57d55d0d5a22a4c9
3
+ metadata.gz: 0e7a98ce4d22d1d86114ca6afd49c33886796f54ce19e65b82389e9329aafc5c
4
+ data.tar.gz: baf1faa70c99ceaa7ab0e74380986546ee4dd87a24b56a4e836ce2409176ae2c
5
5
  SHA512:
6
- metadata.gz: bfdc731ba0787dd13869a96d84f7b3d9d7a9bde7ea59e79601812ecebcae1e301812019f36a726d9abbf5072cc8839e60f78c3c788b98f25123de35677548069
7
- data.tar.gz: 1ed7f0b36c5dbc75701bbfdd5ac4f1df876ae367c3b8e13ffe86069d741a547e4e7a49fabc90bf04d537134c9355184f9ae083af80b9fffba5d604e03c91bb28
6
+ metadata.gz: e5959cb310d89fee9fdfabc3ffcba9834ff37e506d7b0353d6212c09c7fdc8c6a7c106e47282e136b8cc07c6b350a142091c150ef127e41c70f20d16ba02932a
7
+ data.tar.gz: 41bd4e035073d704df2d68e9993e007a85f89fb11a8f9d469bc2a20b4eabb3d030ff87a9350a48f86882dfdce5dee2d1eeefbed74695e0603a189feb2ab7d2bf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stealth (0.10.2)
4
+ stealth (0.10.3)
5
5
  activesupport (~> 5.2.0.rc1)
6
6
  multi_json (~> 1.12)
7
7
  puma (~> 3.10)
@@ -20,16 +20,16 @@ GEM
20
20
  concurrent-ruby (1.0.5)
21
21
  connection_pool (2.2.1)
22
22
  diff-lcs (1.3)
23
- i18n (0.9.3)
23
+ i18n (0.9.5)
24
24
  concurrent-ruby (~> 1.0)
25
25
  minitest (5.11.3)
26
26
  mock_redis (0.17.3)
27
27
  multi_json (1.13.1)
28
- mustermann (1.0.1)
28
+ mustermann (1.0.2)
29
29
  oj (3.3.6)
30
30
  puma (3.11.2)
31
31
  rack (2.0.3)
32
- rack-protection (2.0.0)
32
+ rack-protection (2.0.1)
33
33
  rack
34
34
  rack-test (0.7.0)
35
35
  rack (>= 1.0, < 3)
@@ -49,15 +49,15 @@ GEM
49
49
  rspec-support (3.6.0)
50
50
  rspec_junit_formatter (0.3.0)
51
51
  rspec-core (>= 2, < 4, != 2.12.0)
52
- sidekiq (5.1.0)
52
+ sidekiq (5.1.1)
53
53
  concurrent-ruby (~> 1.0)
54
54
  connection_pool (~> 2.2, >= 2.2.0)
55
55
  rack-protection (>= 1.5.0)
56
- redis (>= 3.3.4, < 5)
57
- sinatra (2.0.0)
56
+ redis (>= 3.3.5, < 5)
57
+ sinatra (2.0.1)
58
58
  mustermann (~> 1.0)
59
59
  rack (~> 2.0)
60
- rack-protection (= 2.0.0)
60
+ rack-protection (= 2.0.1)
61
61
  tilt (~> 2.0)
62
62
  thor (0.20.0)
63
63
  thread_safe (0.3.6)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.4
1
+ 0.10.5
data/lib/stealth/cli.rb CHANGED
@@ -4,11 +4,33 @@
4
4
  require 'thor'
5
5
  require 'stealth/cli_base'
6
6
  require 'stealth/commands/console'
7
+ require 'stealth/generators/builder'
8
+ require 'stealth/generators/generate'
7
9
 
8
10
  module Stealth
9
11
  class Cli < Thor
10
12
  extend CliBase
11
13
 
14
+ desc 'new', 'Creates a new Stealth bot'
15
+ long_desc <<-EOS
16
+ `stealth new <name>` creates a new Stealth both with the given name.
17
+
18
+ $ > stealth new new_bot
19
+ EOS
20
+ def new(name)
21
+ Stealth::Generators::Builder.start([name])
22
+ end
23
+
24
+ desc 'generate', 'Generates scaffold Stealth files'
25
+ long_desc <<-EOS
26
+ `stealth generate <generator> <name>` generates scaffold Stealth files
27
+
28
+ $ > stealth generate flow quote
29
+ EOS
30
+ def generate(generator, name)
31
+ Stealth::Generators::Generate.start([generator, name])
32
+ end
33
+
12
34
  desc 'version', 'Prints stealth version'
13
35
  long_desc <<-EOS
14
36
  `stealth version` prints the version of the bundled stealth gem.
@@ -0,0 +1,37 @@
1
+ require 'thor/group'
2
+
3
+ module Stealth
4
+ module Generators
5
+ class Builder < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :name
9
+
10
+ def self.source_root
11
+ File.dirname(__FILE__) + "/builder"
12
+ end
13
+
14
+ def create_bot_directory
15
+ empty_directory(name)
16
+ end
17
+
18
+ def create_bot_structure
19
+ # Bot Directory
20
+ directory('bot', "#{name}/bot")
21
+
22
+ # Config Directory
23
+ directory('config', "#{name}/config")
24
+
25
+ # Miscellaneous Files
26
+ copy_file "config.ru", "#{name}/config.ru"
27
+ copy_file "Gemfile", "#{name}/Gemfile"
28
+ copy_file "readme.md", "#{name}/readme.md"
29
+ end
30
+
31
+ def change_directory_bundle
32
+ puts run("cd #{name} && bundle install")
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.5.0'
4
+
5
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
6
+ gem 'stealth', '~> 0.10.0'
7
+
8
+ # Uncomment to enable the Stealth Facebook Driver
9
+ # gem 'stealth-facebook'
10
+
11
+ # Uncomment to enable the Stealth Twilio SMS Driver
12
+ # gem 'stealth-twilio'
@@ -0,0 +1,11 @@
1
+ class BotController < Stealth::Controller
2
+
3
+ def route
4
+ if current_session.present?
5
+ step_to session: current_session
6
+ else
7
+ step_to flow: 'Hello', state: 'say_hello'
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,22 @@
1
+ class CatchAllsController < BotController
2
+
3
+ def level1
4
+ send_replies
5
+
6
+ if previous_session_specifies_fails_to?
7
+ step_to flow: previous_session.flow_string, state: previous_state.to_s
8
+ else
9
+ step_to session: previous_session - 2.states
10
+ end
11
+ end
12
+
13
+ private
14
+ def previous_session_specifies_fails_to?
15
+ previous_state.present?
16
+ end
17
+
18
+ def previous_state
19
+ previous_session.flow.current_state.fails_to
20
+ end
21
+
22
+ end
@@ -0,0 +1,7 @@
1
+ class GoodbyesController < BotController
2
+
3
+ def say_goodbye
4
+ send_replies
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ class HellosController < BotController
2
+
3
+ def say_hello
4
+ send_replies
5
+ end
6
+
7
+ end
@@ -0,0 +1,17 @@
1
+ class <%= name.capitalize %>Flow
2
+
3
+ include Stealth::Flow
4
+
5
+ flow :hello do
6
+ state :say_hello
7
+ end
8
+
9
+ flow :goodbye do
10
+ state :say_goodbye
11
+ end
12
+
13
+ flow :catchall do
14
+ state :level1
15
+ end
16
+
17
+ end
@@ -0,0 +1,2 @@
1
+ module BotHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ - reply_type: text
2
+ text: 'Hello World!'
@@ -0,0 +1,4 @@
1
+ require 'rack/handler/puma'
2
+ require_relative 'config/boot'
3
+
4
+ Rack::Handler::Puma.run(Stealth::Server)
@@ -0,0 +1,6 @@
1
+ require 'stealth'
2
+ require_relative './environment'
3
+
4
+ Bundler.require(:default, Stealth.env)
5
+
6
+ Stealth.boot
@@ -0,0 +1,4 @@
1
+ Stealth.load_services_config(File.read(File.join(File.dirname(__FILE__), 'services.yml')))
2
+
3
+ REDIS_URL = ENV['REDIS_URL'] || 'redis://localhost:6379/0'
4
+ $redis = Redis.new(:url => REDIS_URL)
@@ -0,0 +1,10 @@
1
+ threads_count = ENV.fetch("STEALTH_MAX_THREADS") { 5 }.to_i
2
+ threads threads_count, threads_count
3
+
4
+ # Specifies the `port` that Puma will listen on to receive requests, default is 3000.
5
+ #
6
+ port ENV.fetch("PORT") { 3000 }
7
+
8
+ # Specifies the `environment` that Puma will run in.
9
+ #
10
+ environment ENV.fetch("STEALTH_ENV") { "development" }
@@ -0,0 +1,36 @@
1
+ default: &default
2
+ # ==========================================
3
+ # ===== Example Facebook Service Setup =====
4
+ # ==========================================
5
+ # facebook:
6
+ # verify_token: XXXFACEBOOK_VERIFY_TOKENXXX
7
+ # page_access_token: XXXFACEBOOK_ACCESS_TOKENXXX
8
+ # setup:
9
+ # greeting: # Greetings are broken up by locale
10
+ # - locale: default
11
+ # text: "Welcome to the Stealth bot 🤖"
12
+ # persistent_menu:
13
+ # - type: payload
14
+ # text: Main Menu
15
+ # payload: main_menu
16
+ # - type: url
17
+ # text: Visit our website
18
+ # url: https://example.com
19
+ # - type: call
20
+ # text: Call us
21
+ # payload: "+4155330000"
22
+ #
23
+ # ===========================================
24
+ # ======== Example SMS Service Setup ========
25
+ # ===========================================
26
+ # twilio:
27
+ # account_sid: XXXTWILIO_ACCOUNT_SIDXXX
28
+ # auth_token: XXXTWILIO_AUTH_TOKENXXX
29
+ # from_phone: +14155330000
30
+
31
+ production:
32
+ <<: *default
33
+ development:
34
+ <<: *default
35
+ test:
36
+ <<: *default
@@ -0,0 +1,3 @@
1
+ ---
2
+ :verbose: false
3
+ :concurrency: <%= ENV.fetch('SIDEKIQ_CONCURRENCY', 5).to_i %>
@@ -0,0 +1 @@
1
+ # Stealth Bot Framework
@@ -0,0 +1,37 @@
1
+ require 'thor/group'
2
+
3
+ module Stealth
4
+ module Generators
5
+ class Generate < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :generator
9
+ argument :name
10
+
11
+ def self.source_root
12
+ File.dirname(__FILE__) + "/generate/flow"
13
+ end
14
+
15
+ def create_controller
16
+ template('controllers/controller.tt', "controllers/#{name.pluralize}_controller.rb")
17
+ end
18
+
19
+ def create_replies
20
+ # Sample Ask Reply
21
+ template('replies/ask_reply.tt', "replies/#{name.pluralize}/ask_example.yml")
22
+ # Sample Say Replies
23
+ template('replies/say_yes_reply.tt', "replies/#{name.pluralize}/say_yes_example.yml")
24
+ template('replies/say_no_reply.tt', "replies/#{name.pluralize}/say_no_example.yml")
25
+ end
26
+
27
+ def create_helper
28
+ template('helpers/helper.tt', "helpers/#{name}_helper.rb")
29
+ end
30
+
31
+ def edit_flow_map
32
+ # TODO
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ class <%= name.camelize.pluralize %>Controller < BotController
2
+
3
+ def ask_example
4
+ send_replies
5
+ update_session_to_next
6
+ end
7
+
8
+ def get_example
9
+ if current_message.message == 'Yes'
10
+ step_to state: 'say_yes_example'
11
+ elsif current_message.message == 'No'
12
+ step_to state: 'say_no_example'
13
+ end
14
+ end
15
+
16
+ def say_yes_example
17
+ send_replies
18
+ update_session_to state: 'ask_example'
19
+ end
20
+
21
+ def say_no_example
22
+ send_replies
23
+ update_session_to state: 'ask_example'
24
+ end
25
+
26
+ end
@@ -0,0 +1,2 @@
1
+ module <%= name.camelize %>Helper < BotHelper
2
+ end
@@ -0,0 +1,9 @@
1
+ - reply_type: text
2
+ text: "Welcome to your brand new Stealth flow."
3
+ - reply_type: delay
4
+ duration: 2
5
+ - reply_type: text
6
+ text: 'That was pretty easy huh?'
7
+ suggestions:
8
+ - text: "Yes"
9
+ - text: "No"
@@ -0,0 +1,2 @@
1
+ - reply_type: text
2
+ text: "Oh no. :( Why don't you check out our docs at http://www.hello.com for more information."
@@ -0,0 +1,2 @@
1
+ - reply_type: text
2
+ text: "Awesome!. Check out our docs at http://www.hello.com for additional Stealth awesomeness."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-15 00:00:00.000000000 Z
11
+ date: 2018-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -183,6 +183,31 @@ files:
183
183
  - lib/stealth/flow/core_ext.rb
184
184
  - lib/stealth/flow/specification.rb
185
185
  - lib/stealth/flow/state.rb
186
+ - lib/stealth/generators/builder.rb
187
+ - lib/stealth/generators/builder/Gemfile
188
+ - lib/stealth/generators/builder/bot/controllers/bot_controller.rb
189
+ - lib/stealth/generators/builder/bot/controllers/catch_alls_controller.rb
190
+ - lib/stealth/generators/builder/bot/controllers/goodbyes_controller.rb
191
+ - lib/stealth/generators/builder/bot/controllers/hellos_controller.rb
192
+ - lib/stealth/generators/builder/bot/flow_map.rb.tt
193
+ - lib/stealth/generators/builder/bot/helpers/bot_helper.rb
194
+ - lib/stealth/generators/builder/bot/replies/catch_alls/catch_all.yml
195
+ - lib/stealth/generators/builder/bot/replies/goodbyes/say_goodbye.yml
196
+ - lib/stealth/generators/builder/bot/replies/hellos/say_hello.yml
197
+ - lib/stealth/generators/builder/config.ru
198
+ - lib/stealth/generators/builder/config/boot.rb
199
+ - lib/stealth/generators/builder/config/environment.rb
200
+ - lib/stealth/generators/builder/config/initializers/.keep
201
+ - lib/stealth/generators/builder/config/puma.rb
202
+ - lib/stealth/generators/builder/config/services.yml
203
+ - lib/stealth/generators/builder/config/sidekiq.yml
204
+ - lib/stealth/generators/builder/readme.md
205
+ - lib/stealth/generators/generate.rb
206
+ - lib/stealth/generators/generate/flow/controllers/controller.tt
207
+ - lib/stealth/generators/generate/flow/helpers/helper.tt
208
+ - lib/stealth/generators/generate/flow/replies/ask_reply.tt
209
+ - lib/stealth/generators/generate/flow/replies/say_no_reply.tt
210
+ - lib/stealth/generators/generate/flow/replies/say_yes_reply.tt
186
211
  - lib/stealth/jobs.rb
187
212
  - lib/stealth/logger.rb
188
213
  - lib/stealth/reply.rb