twilio-rails 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/operations/twilio/rails/phone/twiml/prompt_operation.rb +0 -1
- data/lib/twilio/rails/configuration.rb +6 -4
- data/lib/twilio/rails/phone/base_tree.rb +0 -1
- data/lib/twilio/rails/phone/tree.rb +0 -1
- data/lib/twilio/rails/phone/tree_macros.rb +19 -0
- data/lib/twilio/rails/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da8b95ee1335c01291ebff65ac9a32b77b7fc749057878b849a1638b477e52db
|
4
|
+
data.tar.gz: 5c67a75eb4a2bf6ff43a71d3c6528540219698dea50e68b7d96b3d3f79b13224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78aa3a4b1a34ff2d574bac9b5d9ec0f1e10ae298150a2649e147ad98234e9449e371a8329acb9c9b3cbf104208a8c4950c7d70166ae488e5ca1aa0bb3d5d84d9
|
7
|
+
data.tar.gz: 20703a2e24787e490321ae035b09f0f6c15613063839767e531f2e3f2bf48c18e3b3708208c7c81f3517e182ee4b637dab54c5e7b093bb8ff6cbb2b034641c45
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Twilio Rails
|
2
2
|
|
3
3
|
[![RSpec Tests](https://github.com/kmcphillips/twilio-rails/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/kmcphillips/twilio-rails/actions/workflows/ci.yml)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/twilio-rails.svg)](https://badge.fury.io/rb/twilio-rails)
|
4
5
|
|
5
6
|
The `twilio-rails` gem is an opinionated Rails engine and a framework for building complex, realtime, stateful phone interactions in Rails without needing to directly interact with the Twilio API or use TwiML. It is not a replacement for the [`twilio-ruby` gem](https://github.com/twilio/twilio-ruby), but is rather built on top of it.
|
6
7
|
|
@@ -12,7 +13,7 @@ What does this mean in practice? **Call and find out!**
|
|
12
13
|
|
13
14
|
## Documentation
|
14
15
|
|
15
|
-
On [RubyDoc](https://rubydoc.info/
|
16
|
+
On [RubyDoc](https://rubydoc.info/gems/twilio-rails) or [Github pages](https://twilio-rails.kev.cool/).
|
16
17
|
|
17
18
|
|
18
19
|
## Getting started
|
@@ -262,7 +263,6 @@ prompt :record_your_feedback,
|
|
262
263
|
gather: {
|
263
264
|
type: :voice,
|
264
265
|
length: 30,
|
265
|
-
beep: true,
|
266
266
|
transcribe: true,
|
267
267
|
profanity_filter: true
|
268
268
|
},
|
@@ -272,7 +272,7 @@ prompt :record_your_feedback,
|
|
272
272
|
}
|
273
273
|
```
|
274
274
|
|
275
|
-
The above `gather:` with `type: :voice` example will finish reading the message
|
275
|
+
The above `gather:` with `type: :voice` example will finish reading the message and then record the phone caller's speech for 30 seconds or until they press the `#` pound key. The phone tree will then immediately execute the `after:`, while the framework continues to handle the audio recording asynchronously. When Twilio makes it available, the audio file of the recording will be downloaded and stored as an ActiveStorage attachment in a `Recording` model as `response.recording`. If the `transcribe:` option is set to `true`, the voice in the recording will also attempt to be transcribed as text and stored as `response.transcription`. Importantly though, **neither are guaranteed to arrive or will arrive immediately**. In practice they both usually arrive within a few seconds, but can sometimes be blank or missing if the caller is silent or garbled. There is a cost to transcription so it can be disabled, and the `profanity_filter:` defaults to false and will just *** out any profanity in the transcription.
|
276
276
|
|
277
277
|
Finally, the `gather:` can also accept `type: :speech` which is a specialzed model designed to identify voice in realtime. It will provide the `response.transcription` field immediately, making it available in the `after:` proc or in the next prompt. But the tradeoffs are that it does not provide a recording, there is a time gap of a few seconds between prompts, and it is more expensive. See the [Twilio documentation for specifics](https://www.twilio.com/docs/voice/twiml/gather#speechmodel). The keys it expects match the documentation, `speech_model:`, `speech_timeout:`, `language:` (defaults to "en-US"), and `encanced:` (defaults to false).
|
278
278
|
|
@@ -48,7 +48,6 @@ module Twilio
|
|
48
48
|
when :voice
|
49
49
|
args = {
|
50
50
|
max_length: prompt.gather.args[:length],
|
51
|
-
play_beep: prompt.gather.args[:beep],
|
52
51
|
# trim: "trim-silence",
|
53
52
|
timeout: prompt.gather.args[:timeout],
|
54
53
|
action: ::Twilio::Rails::Engine.routes.url_helpers.phone_prompt_response_path(
|
@@ -16,8 +16,8 @@ module Twilio
|
|
16
16
|
@spam_filter = nil
|
17
17
|
@exception_notifier = nil
|
18
18
|
@attach_recordings = true
|
19
|
-
@yes_responses = [ "yes", "accept", "ya", "yeah", "true", "ok", "okay" ]
|
20
|
-
@no_responses = [ "no", "naw", "nah", "reject", "decline", "negative", "not", "false" ]
|
19
|
+
@yes_responses = [ "yes", "accept", "ya", "yeah", "true", "ok", "okay", "yep", "yup", "yes please" ]
|
20
|
+
@no_responses = [ "no", "naw", "nah", "reject", "decline", "negative", "not", "false", "nope", "no thank you", "know" ]
|
21
21
|
@message_class_name = "Message"
|
22
22
|
@message_class = nil
|
23
23
|
@phone_call_class_name = "PhoneCall"
|
@@ -95,12 +95,14 @@ module Twilio
|
|
95
95
|
# @return [true, false, Proc] a boolean or a proc that will be called to return a boolean to determine if reordings will be downloaded.
|
96
96
|
attr_accessor :attach_recordings
|
97
97
|
|
98
|
-
# A list of strings to be interpreted as yes or acceptance to a question.
|
98
|
+
# A list of strings to be interpreted as yes or acceptance to a question. Pairs with the
|
99
|
+
# {Twilio::Rails::Phone::TreeMacros#answer_yes?} method.
|
99
100
|
#
|
100
101
|
# @return [Array<String>] a list of strings to be interpreted as yes or acceptance to a question.
|
101
102
|
attr_accessor :yes_responses
|
102
103
|
|
103
|
-
# A list of strings to be interpreted as no or rejection to a question.
|
104
|
+
# A list of strings to be interpreted as no or rejection to a question. Pairs with the
|
105
|
+
# {Twilio::Rails::Phone::TreeMacros#answer_no?} method.
|
104
106
|
#
|
105
107
|
# @return [Array<String>] a list of strings to be interpreted as no or rejection to a question.
|
106
108
|
attr_accessor :no_responses
|
@@ -122,7 +122,6 @@ module Twilio
|
|
122
122
|
# response instance. However, this all happens asynchronously with no guarantee of time or success. Voice
|
123
123
|
# accepts the following configuration keys:
|
124
124
|
# * `:length`: The number of seconds to record. The default is 10.
|
125
|
-
# * `:beep`: A boolean if the gather is preceeded by a beep. The default is `true`.
|
126
125
|
# * `:transcribe`: A boolean if Twilio should attempt to transcribe the audio and send it back as text. The
|
127
126
|
# framework handles this all asynchronously and will update the `transcription` field. Default is `false`.
|
128
127
|
# * `:profanity_filter`: Replaces any profanity in the transcription with ***. Default is `false`.
|
@@ -102,7 +102,6 @@ module Twilio
|
|
102
102
|
@args[:number] ||= 1
|
103
103
|
elsif voice?
|
104
104
|
@args[:length] ||= 10
|
105
|
-
@args[:beep] = true unless @args.key?(:beep)
|
106
105
|
@args[:transcribe] = false unless @args.key?(:transcribe)
|
107
106
|
@args[:profanity_filter] = false unless @args.key?(:profanity_filter)
|
108
107
|
elsif speech?
|
@@ -90,6 +90,15 @@ module Twilio
|
|
90
90
|
Twilio::Rails.config.yes_responses
|
91
91
|
end
|
92
92
|
|
93
|
+
# Matches if the entire passed in string is included in the {Twilio::Rails::Configuration#yes_responses} and is
|
94
|
+
# considered a "yes".
|
95
|
+
#
|
96
|
+
# @param filename [String] the string to match against.
|
97
|
+
# @return [true, false] if the passed in string matches.
|
98
|
+
def answer_yes?(string)
|
99
|
+
answers_yes.include?((string || "").downcase.strip.gsub(/[.,!?]/, ""))
|
100
|
+
end
|
101
|
+
|
93
102
|
# The list of configured answers that are considered "no" from {Twilio::Rails::Configuration#no_responses}.
|
94
103
|
#
|
95
104
|
# @return [Array<String>] the list of configured answers that are considered "no".
|
@@ -97,6 +106,16 @@ module Twilio
|
|
97
106
|
Twilio::Rails.config.no_responses
|
98
107
|
end
|
99
108
|
|
109
|
+
# Matches if the entire passed in string is included in the {Twilio::Rails::Configuration#no_responses} and is
|
110
|
+
# considered a "no".
|
111
|
+
#
|
112
|
+
# @param filename [String] the string to match against.
|
113
|
+
# @return [true, false] if the passed in string matches.
|
114
|
+
def answer_no?(string)
|
115
|
+
answers_no.include?((string || "").downcase.strip.gsub(/[.,!?]/, ""))
|
116
|
+
end
|
117
|
+
|
118
|
+
|
100
119
|
# Finds and validates the existence of a file in the `public` folder. Formats that link to include the
|
101
120
|
# configured hose from {Twilio::Rails::Configuration#host}, and returns a fully qualified URL to the file. This
|
102
121
|
# is useful for playing audio files in a `message:` block. If the file is not found
|
data/lib/twilio/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twilio-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin McPhillips
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -267,6 +267,8 @@ metadata:
|
|
267
267
|
homepage_uri: https://github.com/kmcphillips/twilio-rails
|
268
268
|
source_code_uri: https://github.com/kmcphillips/twilio-rails
|
269
269
|
changelog_uri: https://github.com/kmcphillips/twilio-rails/blob/main/CHANGELOG.md
|
270
|
+
documentation_uri: https://rubydoc.info/gems/twilio-rails
|
271
|
+
rubygems_mfa_required: 'true'
|
270
272
|
post_install_message:
|
271
273
|
rdoc_options: []
|
272
274
|
require_paths:
|