stealth 2.0.0.beta4 → 2.0.0.beta5

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: c7c4304b177d264b2f7179e5bad5c8bf509421a386f0d9ec66d4c7c53c4c1972
4
- data.tar.gz: fdcd30455510aef62945bce7716e06559c3b2eb0105b4199ba5c8c99e201b60f
3
+ metadata.gz: 24ba7ba55d264e21395db7b9166ecf96064c2c0d8c8bc51d09dd274ecaf5fd34
4
+ data.tar.gz: c42254f819550577f249fddb13266cfa6bc8e2f27760994e3efdf7798447ecdd
5
5
  SHA512:
6
- metadata.gz: d0aa0623fcc9978fd62a31fbe863fa1e143427431f125e144f97967cf9792ba37f0779e3fae826647eccc3726633fbb61ff7ae2c2b9f82580a3d890ca92c3174
7
- data.tar.gz: a64cfaa6e32319b28dc2bebe0ad6626c0c8e482de0ac13bbcf0f46c5b73cc71121d06535ed91ed6e11afe65bcc5859cc7bb4076494715755f0468227a86ca077
6
+ metadata.gz: 3f1af77ae1b811b4f53f85df2365fae399efe6caf9db77a801898250dfcdb732e366b06efa1641b255eda53e2a22fff38ca7a8ebd6577d6dcf860509d002c261
7
+ data.tar.gz: 7146a30ad60302ccc322e6691c6676b6b281dee1625bc1acf674e133b87d371b5cc470c5d3d4eb6d50526d33992a81f424364fbf4b10e23d93910aed815b5864
data/.circleci/config.yml CHANGED
@@ -3,7 +3,7 @@ version: 2
3
3
  jobs:
4
4
  ruby_2_6:
5
5
  docker:
6
- - image: circleci/ruby:2.6-node-browsers
6
+ - image: cimg/ruby:2.6
7
7
  environment:
8
8
  STEALTH_ENV: test
9
9
 
@@ -56,7 +56,7 @@ jobs:
56
56
  destination: test-results
57
57
  ruby_2_7:
58
58
  docker:
59
- - image: circleci/ruby:2.7-node-browsers
59
+ - image: cimg/ruby:2.7
60
60
  environment:
61
61
  STEALTH_ENV: test
62
62
 
@@ -110,7 +110,61 @@ jobs:
110
110
 
111
111
  ruby_3_0:
112
112
  docker:
113
- - image: circleci/ruby:3.0-node-browsers
113
+ - image: cimg/ruby:3.0
114
+ environment:
115
+ STEALTH_ENV: test
116
+
117
+ working_directory: ~/repo
118
+
119
+ steps:
120
+ - checkout
121
+
122
+ # Download and cache dependencies
123
+ - restore_cache:
124
+ keys:
125
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
126
+ # fallback to using the latest cache if no exact match is found
127
+ - v1-dependencies-
128
+ - run:
129
+ name: Configure Bundler
130
+ command: |
131
+ echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
132
+ source $BASH_ENV
133
+ gem install bundler
134
+ - run:
135
+ name: install dependencies
136
+ command: |
137
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
138
+
139
+ - save_cache:
140
+ paths:
141
+ - ./vendor/bundle
142
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
143
+
144
+ # run tests!
145
+ - run:
146
+ name: run tests
147
+ command: |
148
+ mkdir /tmp/test-results
149
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
150
+
151
+ bundle exec rspec --format progress \
152
+ --format RspecJunitFormatter \
153
+ --out /tmp/test-results/rspec.xml \
154
+ --format progress \
155
+ -- \
156
+ $TEST_FILES
157
+
158
+ # collect reports
159
+ - store_test_results:
160
+ path: /tmp/test-results
161
+ - store_artifacts:
162
+ path: /tmp/test-results
163
+ destination: test-results
164
+
165
+ ruby_3_1:
166
+ docker:
167
+ - image: cimg/ruby:3.1
114
168
  environment:
115
169
  STEALTH_ENV: test
116
170
 
@@ -169,3 +223,4 @@ workflows:
169
223
  - ruby_2_6
170
224
  - ruby_2_7
171
225
  - ruby_3_0
226
+ - ruby_3_1
data/CHANGELOG.md CHANGED
@@ -53,6 +53,9 @@
53
53
  * [Controllers] `handle_message` now supports `Regexp` keys.
54
54
  * [Configuration] `database.yml` is now parsed with ERB in order to support environment variables. Thanks @malkovro.
55
55
  * [Replies] Speech and SSML replies now use `speech` and `ssml` as keys, respectively, instead of `text`
56
+ * [Replies] Voice services (determined by having "voice" in the name) now automatically skip auto-delays.
57
+ * [Controllers] `current_message` now has a `confidence` attribute containing a float with the confidence value of the transcription (from 0 to 1).
58
+ * [Controllers] Added a `halt!` method that can be used with the controller error handlers to stop code execution.
56
59
 
57
60
  ## Bug Fixes
58
61
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stealth (2.0.0.beta4)
4
+ stealth (2.0.0.beta5)
5
5
  activesupport (~> 6.0)
6
6
  multi_json (~> 1.12)
7
7
  puma (>= 4.2, < 6.0)
@@ -12,13 +12,13 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activesupport (6.1.4.6)
15
+ activesupport (6.1.5)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
19
19
  tzinfo (~> 2.0)
20
20
  zeitwerk (~> 2.3)
21
- concurrent-ruby (1.1.9)
21
+ concurrent-ruby (1.1.10)
22
22
  connection_pool (2.2.5)
23
23
  diff-lcs (1.3)
24
24
  i18n (1.10.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta4
1
+ 2.0.0.beta5
data/lib/stealth/base.rb CHANGED
@@ -88,7 +88,7 @@ module Stealth
88
88
 
89
89
  Thread.current[:configuration] ||= begin
90
90
  @semaphore.synchronize do
91
- services_config = YAML.load(ERB.new(services_yaml).result)
91
+ services_config = YAML.safe_load(ERB.new(services_yaml).result, aliases: true)
92
92
 
93
93
  unless services_config.has_key?(env)
94
94
  raise Stealth::Errors::ConfigurationError, "Could not find services.yml configuration for #{env} environment"
@@ -91,6 +91,11 @@ module Stealth
91
91
  unless flow_controller.progressed?
92
92
  run_catch_all(reason: 'Did not send replies, update session, or step')
93
93
  end
94
+ rescue Stealth::Errors::Halted
95
+ Stealth::Logger.l(
96
+ topic: "session",
97
+ message: "User #{current_session_id}: session halted."
98
+ )
94
99
  rescue StandardError => e
95
100
  if e.class == Stealth::Errors::UnrecognizedMessage
96
101
  run_unrecognized_message(err: e)
@@ -215,6 +220,10 @@ module Stealth
215
220
  @progressed = :do_nothing
216
221
  end
217
222
 
223
+ def halt!
224
+ raise Stealth::Errors::Halted
225
+ end
226
+
218
227
  private
219
228
 
220
229
  def update_session(flow:, state:)
@@ -72,8 +72,12 @@ module Stealth
72
72
 
73
73
  private
74
74
 
75
+ def voice_service?
76
+ current_service.match?(/voice/)
77
+ end
78
+
75
79
  def send_reply(reply:)
76
- if !reply.delay? && Stealth.config.auto_insert_delays
80
+ if !reply.delay? && Stealth.config.auto_insert_delays && !voice_service?
77
81
  # if it's the first reply in the service_reply or the previous reply
78
82
  # wasn't a custom delay, then insert a delay
79
83
  if @previous_reply.blank? || !@previous_reply.delay?
@@ -60,5 +60,8 @@ module Stealth
60
60
  class ReservedHomophoneUsed < Errors
61
61
  end
62
62
 
63
+ class Halted < Errors
64
+ end
65
+
63
66
  end
64
67
  end
@@ -21,9 +21,9 @@ module Stealth
21
21
  end
22
22
 
23
23
  def getex(key, expiration=Stealth.config.session_ttl)
24
- $redis.multi do
25
- $redis.expire(key, expiration)
26
- $redis.get(key)
24
+ $redis.multi do |pipeline|
25
+ pipeline.expire(key, expiration)
26
+ pipeline.get(key)
27
27
  end.last
28
28
  end
29
29
 
@@ -45,7 +45,7 @@ module Stealth
45
45
  :blue
46
46
  when :smooch
47
47
  :magenta
48
- when :alexa, :voice, :unrecognized_message
48
+ when :alexa, :voice, :twilio_voice, :unrecognized_message
49
49
  :light_cyan
50
50
  when :nlp
51
51
  :cyan
@@ -21,7 +21,7 @@ module Stealth
21
21
  <body>
22
22
  <center>
23
23
  <a href='https://hellostealth.org'>
24
- <img src='http://assets.blackops.nyc/stealth/logo.svg' height='120' alt='Stealth Logo' aria-label='hellostealth.org' />
24
+ <img src='https://raw.githubusercontent.com/hellostealth/stealth/master/logo.svg' height='120' alt='Stealth Logo' aria-label='hellostealth.org' />
25
25
  </a>
26
26
  </center>
27
27
  </body>
@@ -6,7 +6,7 @@ module Stealth
6
6
 
7
7
  attr_accessor :sender_id, :target_id, :timestamp, :service, :message,
8
8
  :location, :attachments, :payload, :referral, :nlp_result,
9
- :catch_all_reason
9
+ :catch_all_reason, :confidence
10
10
 
11
11
  def initialize(service:)
12
12
  @service = service
@@ -6,7 +6,7 @@ describe "Stealth::Configuration" do
6
6
 
7
7
  describe "accessing via method calling" do
8
8
  let(:services_yml) { File.read(File.join(File.dirname(__FILE__), 'support', 'services.yml')) }
9
- let(:parsed_config) { YAML.load(ERB.new(services_yml).result)[Stealth.env] }
9
+ let(:parsed_config) { YAML.safe_load(ERB.new(services_yml).result, aliases: true)[Stealth.env] }
10
10
  let(:config) { Stealth.load_services_config!(services_yml) }
11
11
 
12
12
  it "should return the root node" do
@@ -42,6 +42,11 @@ describe "Stealth::Controller" do
42
42
  def parts_unknown
43
43
  step_to flow: :parts, state: :unknown
44
44
  end
45
+
46
+ def halted
47
+ halt!
48
+ step_to state: :other_action2
49
+ end
45
50
  end
46
51
 
47
52
  class FlowMap
@@ -60,6 +65,7 @@ describe "Stealth::Controller" do
60
65
  state :other_action4
61
66
  state :broken_action
62
67
  state :part_unknown
68
+ state :halted
63
69
  state :deprecated_action, redirects_to: :other_action
64
70
  state :deprecated_action2, redirects_to: 'mr_robot->my_action'
65
71
  end
@@ -884,6 +890,34 @@ describe "Stealth::Controller" do
884
890
  controller.action(action: :parts_unknown)
885
891
  end
886
892
  end
893
+
894
+ describe "halt!" do
895
+ it "should catch the error and log the sessio halt" do
896
+ ### It's lame we have to include these two
897
+ expect(Stealth::Logger).to receive(:l).with(
898
+ topic: "primary_session",
899
+ message: "User #{facebook_message.sender_id}: setting session to mr_tron->halted"
900
+ )
901
+ expect(Stealth::Logger).to receive(:l).with(
902
+ topic: "previous_session",
903
+ message: "User #{facebook_message.sender_id}: setting to parts->unknown"
904
+ )
905
+ ###
906
+
907
+ expect(Stealth::Logger).to receive(:l).with(
908
+ topic: "session",
909
+ message: "User #{facebook_message.sender_id}: session halted."
910
+ )
911
+
912
+ controller.step_to(flow: :mr_tron, state: :halted)
913
+ end
914
+
915
+ it "should NOT continue with the rest of the controller code" do
916
+ expect_any_instance_of(MrTronsController).to_not receive(:other_action2)
917
+ expect_any_instance_of(MrTronsController).to_not receive(:step_to).with(state: :other_action2)
918
+ controller.step_to(flow: :mr_tron, state: :halted)
919
+ end
920
+ end
887
921
  end
888
922
 
889
923
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta4
4
+ version: 2.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-03-05 00:00:00.000000000 Z
12
+ date: 2022-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -327,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
327
  - !ruby/object:Gem::Version
328
328
  version: 1.3.1
329
329
  requirements: []
330
- rubygems_version: 3.2.32
330
+ rubygems_version: 3.3.7
331
331
  signing_key:
332
332
  specification_version: 4
333
333
  summary: Ruby framework for conversational bots