Giter Club home page Giter Club logo

amazon-lex-v2-helper's Introduction

amazon-lex-helper

This repository contains a list of helper classes to handle Amazon Lex V2 responses and create custom requests. More specifically, it provides the following functionality:

  • LexEvent: Amazon Lex event class
  • LexResponse: builder to create Amazon Lex responses
  • LexEventDispatcher: utility class to define your intent handlers
  • IntentHandler: base class providing basic intent functionality

Quick Install

pip install amazon-lex-helper

Example

LexEventDispatcher class provides an observer approach to register intent handlers which scales better and is more modular than just a simple loop, as in the examples:
For example, let's add extra validation to the Book Hotel example . First step is to create our own BookHotel class to handle the intent. Notice the intent name (BookHotel) must match the intent name defined in Amazon Lex.

from amazon_lex_helper import LexEventDispatcher

from BookHotelIntent import BookHotelIntent

def lambda_handler(event, context):
    lexEventDispatcher = LexEventDispatcher()
    lexEventDispatcher.subscribe(
        BookHotelIntent("BookHotel")
    )
    return lexEventDispatcher.dispatch(event)

BookHotelIntent class adds some extra behaviour to the intent handling.
In this case we will:

  1. allow only reservations for London and Bristol cities
  2. if the city is Bristol, we will set number of nights (Nights)to 5.
from amazon_lex_helper import IntentHandler, LexEvent, LexResponse

class BookHotelIntent (IntentHandler):
    
    def process_request(self, req: LexEvent):

        if req.slot_exists("Location"):
            location = req.get_slot_interpreted_value("Location")
            if location not in ["London", "Bristol"]:
                return LexResponse.elicit_slot(req, "Location", message="Sorry, location can only be London or Bristol")
                
            if location == "Bristol":
                return LexResponse.delegate(req, "Nights", "5")
        
        return LexResponse.delegate(req)

AWS Lambda usage

You can clone this repo and execute ./create_layer.sh script, which will create a .zip file inside /layer folder.
That zip can be then used to create a layer for your AWS Lambda function.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

amazon-lex-v2-helper's People

Contributors

adancso avatar amazon-auto avatar anshumankmr avatar rubenafo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

amazon-lex-v2-helper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.