aws-lex-conversation 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +35 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +29 -0
- data/.simplecov +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/LICENSE.md +21 -0
- data/README.md +160 -0
- data/Rakefile +11 -0
- data/aws-lex-conversation.gemspec +38 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/aws-lex-conversation.rb +3 -0
- data/lib/aws/lex/conversation.rb +58 -0
- data/lib/aws/lex/conversation/base.rb +40 -0
- data/lib/aws/lex/conversation/handler/base.rb +34 -0
- data/lib/aws/lex/conversation/handler/delegate.rb +17 -0
- data/lib/aws/lex/conversation/handler/echo.rb +24 -0
- data/lib/aws/lex/conversation/response/base.rb +30 -0
- data/lib/aws/lex/conversation/response/close.rb +29 -0
- data/lib/aws/lex/conversation/response/confirm_intent.rb +31 -0
- data/lib/aws/lex/conversation/response/delegate.rb +29 -0
- data/lib/aws/lex/conversation/response/elicit_intent.rb +27 -0
- data/lib/aws/lex/conversation/response/elicit_slot.rb +33 -0
- data/lib/aws/lex/conversation/support/inflector.rb +43 -0
- data/lib/aws/lex/conversation/support/responses.rb +56 -0
- data/lib/aws/lex/conversation/type/base.rb +95 -0
- data/lib/aws/lex/conversation/type/bot.rb +17 -0
- data/lib/aws/lex/conversation/type/confirmation_status.rb +17 -0
- data/lib/aws/lex/conversation/type/current_intent.rb +34 -0
- data/lib/aws/lex/conversation/type/dialog_action_type.rb +19 -0
- data/lib/aws/lex/conversation/type/enumeration.rb +44 -0
- data/lib/aws/lex/conversation/type/event.rb +37 -0
- data/lib/aws/lex/conversation/type/fulfillment_state.rb +16 -0
- data/lib/aws/lex/conversation/type/invocation_source.rb +16 -0
- data/lib/aws/lex/conversation/type/message.rb +20 -0
- data/lib/aws/lex/conversation/type/message/content_type.rb +19 -0
- data/lib/aws/lex/conversation/type/output_dialog_mode.rb +16 -0
- data/lib/aws/lex/conversation/type/recent_intent_summary_view.rb +29 -0
- data/lib/aws/lex/conversation/type/response.rb +17 -0
- data/lib/aws/lex/conversation/type/response_card.rb +23 -0
- data/lib/aws/lex/conversation/type/response_card/button.rb +18 -0
- data/lib/aws/lex/conversation/type/response_card/content_type.rb +17 -0
- data/lib/aws/lex/conversation/type/response_card/generic_attachment.rb +26 -0
- data/lib/aws/lex/conversation/type/sentiment_label.rb +18 -0
- data/lib/aws/lex/conversation/type/sentiment_response.rb +21 -0
- data/lib/aws/lex/conversation/type/sentiment_score.rb +35 -0
- data/lib/aws/lex/conversation/type/slot_detail.rb +20 -0
- data/lib/aws/lex/conversation/type/slot_resolution.rb +15 -0
- data/lib/aws/lex/conversation/version.rb +9 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 196357c0326b8a475650f1be193292f99818ca79b98a9957234f01b5e228caf9
|
4
|
+
data.tar.gz: 4acba1d9e6647752ecb57d6fed79746214fbf5dbaba2f495085a77ebb0aa2cde
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b66d860466c3514f7e4122dccc9545eaf98b3d0fd8a6535873f323c73366071197c6b545f67eef71d25f86ea1d4ddd02a334660087a7ec3c84e85dce00f9f82d
|
7
|
+
data.tar.gz: d02d3473ef14600f09d78a94bf839c80dce492943956e1afe565261eca22b33dac50c1d6699687e57d97c69e95955a81a415cc122d122f05aab9393e662bd3a1
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
name: CI
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- name: Set up Ruby 2.7
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: '2.7'
|
19
|
+
- name: Install Bundler
|
20
|
+
run: gem install bundler
|
21
|
+
- uses: actions/cache@v1
|
22
|
+
with:
|
23
|
+
path: vendor/bundle
|
24
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
25
|
+
restore-keys: |
|
26
|
+
${{ runner.os }}-gems-
|
27
|
+
- name: Install Ruby Dependencies
|
28
|
+
run: |
|
29
|
+
bundle --version
|
30
|
+
bundle config set path 'vendor/bundle'
|
31
|
+
bundle install --jobs 4 --retry 3
|
32
|
+
- name: Run Tests
|
33
|
+
env:
|
34
|
+
RAILS_ENV: test
|
35
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
TargetRubyVersion: 2.7
|
4
|
+
NewCops: enable
|
5
|
+
Exclude:
|
6
|
+
- 'bin/**/*'
|
7
|
+
- 'vendor/**/*'
|
8
|
+
Documentation:
|
9
|
+
Enabled: false
|
10
|
+
Gemspec/RequiredRubyVersion:
|
11
|
+
Enabled: false
|
12
|
+
Metrics/ClassLength:
|
13
|
+
Max: 150
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Exclude:
|
16
|
+
- 'spec/**/*'
|
17
|
+
- '*.gemspec'
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 130
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 25
|
22
|
+
Naming/FileName:
|
23
|
+
Enabled: true
|
24
|
+
Exclude:
|
25
|
+
- lib/aws-lex-conversation.rb
|
26
|
+
Style/Lambda:
|
27
|
+
EnforcedStyle: literal
|
28
|
+
Style/GuardClause:
|
29
|
+
Enabled: false
|
data/.simplecov
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at webmaster@ama.ab.ca. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Alberta Motor Association
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# Aws::Lex::Conversation
|
2
|
+
|
3
|
+
Have you played around with [AWS Lex](https://aws.amazon.com/lex/) and quickly realized you were duplicating code to read and generate the [Lex Lambda input event and response format](https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html)?
|
4
|
+
|
5
|
+
`Aws::Lex::Conversation` provides a mechanism to define the flow of a Lex conversation with a user easily!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'aws-lex-conversation'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
At a high level, you must create a new instance of `Aws::Lex::Conversation`.
|
24
|
+
|
25
|
+
Generally the conversation instance will be initialized inside your Lambda handler method as follows:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
def my_lambda_handler(event:, context:)
|
29
|
+
conversation = Aws::Lex::Conversation.new(event: event, context: context)
|
30
|
+
|
31
|
+
# define a chain of your own Handler classes
|
32
|
+
conversation.handlers = [
|
33
|
+
{
|
34
|
+
handler: Aws::Lex::Conversation::Handler::Delegate,
|
35
|
+
options: {
|
36
|
+
respond_on: ->(conversation) { conversation.current_intent.name == 'MyIntent' }
|
37
|
+
}
|
38
|
+
}
|
39
|
+
]
|
40
|
+
|
41
|
+
# return a response object to indicate Lex's next action
|
42
|
+
conversation.respond
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Any custom behaviour in your flow is achieved by defining a Handler class. Handler classes must provide the following:
|
47
|
+
|
48
|
+
1. Inherit from `Aws::Lex::Conversation::Handler::Base`.
|
49
|
+
2. Define a `will_respond?(conversation)` method that returns a boolean value.
|
50
|
+
3. Define a `response(conversation)` method to return final response to Lex. This method is called if `will_respond?` returns `true`.
|
51
|
+
|
52
|
+
The handlers defined on an `Aws::Lex::Conversation` instance will be called one-by-one in the order defined.
|
53
|
+
|
54
|
+
The first handler that returns `true` for the `will_respond?` method will provide the final Lex response action.
|
55
|
+
|
56
|
+
### Custom Handler Example
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
class SayHello < Aws::Lex::Conversation::Handler::Base
|
60
|
+
def will_respond?(conversation)
|
61
|
+
conversation.lex.incovation_source.dialog_code_hook? && # callback is for DialogCodeHook (i.e. validation)
|
62
|
+
conversation.lex.current_intent.name == 'SayHello' && # Lex has routed to the 'SayHello' intent
|
63
|
+
conversation.slots[:name] # our expected slot value is set
|
64
|
+
end
|
65
|
+
|
66
|
+
def response(conversation)
|
67
|
+
name = conversation.slots[:name]
|
68
|
+
|
69
|
+
# NOTE: you can use the Type::* classes if you wish. The final output
|
70
|
+
# will be normalized to a value that complies with the Lex response format.
|
71
|
+
#
|
72
|
+
# You can also specify raw values for the response:
|
73
|
+
#
|
74
|
+
# conversation.close(
|
75
|
+
# fulfillment_state: 'Fulfilled',
|
76
|
+
# message: { content: "Hello, #{name}!", contentType: 'PlainText' }
|
77
|
+
# )
|
78
|
+
#
|
79
|
+
conversation.close(
|
80
|
+
fulfillment_state: Aws::Lex::Conversation::Type::FulfillmentState.new('Fulfilled'),
|
81
|
+
message: Aws::Lex::Conversation::Type::Message.new(
|
82
|
+
content: "Hello, #{name}!",
|
83
|
+
content_type: Aws::Lex::Conversation::Type::Message::ContentType.new('PlainText')
|
84
|
+
)
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Built-In Handlers
|
91
|
+
|
92
|
+
### `Aws::Lex::Conversation::Handler::Echo`
|
93
|
+
|
94
|
+
This handler simply returns a close response with a message that matches the `inputTranscript` property of the input event.
|
95
|
+
|
96
|
+
| Option | Required | Description | Default Value |
|
97
|
+
|------------------|----------|--------------------------------------------------------------|-------------------------------------|
|
98
|
+
| respond_on | No | A callable that provides the condition for `will_handle?`. | `->(c) { false }` |
|
99
|
+
| fulfillment_state| No | The `fulfillmentState` value (i.e. `Fulfilled` or `Failed`). | `Fulfilled` |
|
100
|
+
| content_type | No | The `contentType` for the message response. | `PlainText` |
|
101
|
+
| content | No | The response message content. | `conversation.lex.input_transcript` |
|
102
|
+
|
103
|
+
i.e.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
conversation = Aws::Lex::Conversation.new(event: event, context: context)
|
107
|
+
conversation.handlers = [
|
108
|
+
{
|
109
|
+
handler: Aws::Lex::Conversation::Handler::Echo,
|
110
|
+
options: {
|
111
|
+
respond_on: ->(c) { true },
|
112
|
+
fulfillment_state: 'Failed',
|
113
|
+
content_type: 'SSML',
|
114
|
+
content: '<speak>Sorry<break> an error occurred.</speak>'
|
115
|
+
}
|
116
|
+
}
|
117
|
+
]
|
118
|
+
conversation.respond # => { dialogAction: { type: 'Close' } ... }
|
119
|
+
```
|
120
|
+
|
121
|
+
### `Aws::Lex::Conversation::Handler::Delegate`
|
122
|
+
|
123
|
+
This handler returns a `Delegate` response to the Lex bot (i.e. "do the next bot action").
|
124
|
+
|
125
|
+
| Option | Required | Description | Default Value |
|
126
|
+
|------------------|----------|--------------------------------------------------------------|-------------------------------------|
|
127
|
+
| respond_on | No | A callable that provides the condition for `will_handle?`. | `->(c) { false }` |
|
128
|
+
|
129
|
+
i.e.
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
conversation = Aws::Lex::Conversation.new(event: event, context: context)
|
133
|
+
conversation.handlers = [
|
134
|
+
{
|
135
|
+
handler: Aws::Lex::Conversation::Handler::Delegate,
|
136
|
+
options: {
|
137
|
+
respond_on: ->(c) { true }
|
138
|
+
}
|
139
|
+
}
|
140
|
+
]
|
141
|
+
conversation.respond # => { dialogAction: { type: 'Delegate' } }
|
142
|
+
```
|
143
|
+
|
144
|
+
## Development
|
145
|
+
|
146
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
147
|
+
|
148
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
149
|
+
|
150
|
+
## Contributing
|
151
|
+
|
152
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/amaabca/aws-lex-conversation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/amaabca/aws-lex-conversation/blob/master/CODE_OF_CONDUCT.md).
|
153
|
+
|
154
|
+
## License
|
155
|
+
|
156
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
157
|
+
|
158
|
+
## Code of Conduct
|
159
|
+
|
160
|
+
Everyone interacting in the Aws::Lex::Conversation project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/amaabca/aws-lex-conversation/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/aws/lex/conversation/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'aws-lex-conversation'
|
7
|
+
spec.version = Aws::Lex::Conversation::VERSION
|
8
|
+
spec.authors = [
|
9
|
+
'Jesse Doyle',
|
10
|
+
'Michael van den Beuken',
|
11
|
+
'Darko Dosenovic',
|
12
|
+
'Zoie Carnegie',
|
13
|
+
'Carlos Mejia Castelo'
|
14
|
+
]
|
15
|
+
spec.email = [
|
16
|
+
'jesse.doyle@ama.ab.ca',
|
17
|
+
'michael.vandenbeuken@ama.ab.ca',
|
18
|
+
'darko.dosenovic@ama.ab.ca',
|
19
|
+
'zoie.carnegie@ama.ab.ca',
|
20
|
+
'carlos.mejiacastelo@ama.ab.ca'
|
21
|
+
]
|
22
|
+
|
23
|
+
spec.summary = 'AWS Lex Conversation Dialog Management'
|
24
|
+
spec.description = 'Easily manage the flow and logic of your AWS Lex conversations.'
|
25
|
+
spec.homepage = 'https://github.com/amaabca/aws-lex-conversation'
|
26
|
+
spec.license = 'MIT'
|
27
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
28
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
29
|
+
|
30
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
spec.add_dependency 'shrink_wrap'
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'aws/lex/conversation'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|