中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

AWSLex+Lambda

AWS Lex 

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供江達(dá)網(wǎng)站建設(shè)、江達(dá)做網(wǎng)站、江達(dá)網(wǎng)站設(shè)計(jì)、江達(dá)網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、江達(dá)企業(yè)網(wǎng)站模板建站服務(wù),10余年江達(dá)做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

Create Bots --> Try a sample {OrderFlowers} 

La  Lambda initialization and validation --> 添加定義的 Lambda function

AWS Lex + Lambda

Slots --> 段值

AWS Lex + Lambda

SlotType--> define values of Slots

AWS Lex + Lambda

Slots --> FlowerType Prompt --> Prompt response cards --> URL: Global S3 https://s3.cn-north-1.amazonaws.com.cn/sides-share/AWS+INNOVATE+2018/builders_workshop/Flower.jpeg    Button title/value for each button.

AWS Lex + Lambda

修改后,“Save Intent”保存,click “Build” to test as below --

AWS Lex + Lambda  AWS Lex + Lambda  AWS Lex + Lambda

Publish to publish Slack/Facebook Channel.

AWS Lambda

Create Function --> Blueprints (filter "lex") --> Choose "lex-order-flowers-python" --> Role: LexRoleOrderFlowers

Function Code as below :

"""
This sample demonstrates an implementation of the Lex Code Hook Interface
in order to serve a sample bot which manages orders for flowers.
Bot, Intent, and Slot models which are compatible with this sample can be found in the Lex Console
as part of the 'OrderFlowers' template.
For instructions on how to set up and test this bot, as well as additional samples,
visit the Lex Getting Started documentation http://docs.aws.amazon.com/lex/latest/dg/getting-started.html.
"""
import math
import dateutil.parser
import datetime
import time
import os
import logging
import boto3
import json
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
""" --- Helpers to build responses which match the structure of the necessary dialog actions --- """
def get_slots(intent_request):
    return intent_request['currentIntent']['slots']
def elicit_slot(session_attributes, intent_name, slots, slot_to_elicit, message):
    return {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'ElicitSlot',
            'intentName': intent_name,
            'slots': slots,
            'slotToElicit': slot_to_elicit,
            'message': message
        }
    }
def close(session_attributes, fulfillment_state, message):
    response = {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'Close',
            'fulfillmentState': fulfillment_state,
            'message': message
        }
    }
    return response
def delegate(session_attributes, slots):
    return {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'Delegate',
            'slots': slots
        }
    }
""" --- Helper Functions --- """
def parse_int(n):
    try:
        return int(n)
    except ValueError:
        return float('nan')
def build_validation_result(is_valid, violated_slot, message_content):
    if message_content is None:
        return {
            "isValid": is_valid,
            "violatedSlot": violated_slot,
        }
    return {
        'isValid': is_valid,
        'violatedSlot': violated_slot,
        'message': {'contentType': 'PlainText', 'content': message_content}
    }
def isvalid_date(date):
    try:
        dateutil.parser.parse(date)
        return True
    except ValueError:
        return False
def validate_order_flowers(flower_type, date, pickup_time, number):
    flower_types = ['lilies', 'roses', 'tulips']
    if flower_type is not None and flower_type.lower() not in flower_types:
        return build_validation_result(False,
                                       'FlowerType',
                                       'We do not have {}, would you like a different type of flower?  '
                                       'Our most popular flowers are roses'.format(flower_type))
    if date is not None:
        if not isvalid_date(date):
            return build_validation_result(False, 'PickupDate', 'I did not understand that, what date would you like to pick the flowers up?')
        elif datetime.datetime.strptime(date, '%Y-%m-%d').date() <= datetime.date.today():
            return build_validation_result(False, 'PickupDate', 'You can pick up the flowers from tomorrow onwards.  What day would you like to pick them up?')
    if pickup_time is not None:
        if len(pickup_time) != 5:
            # Not a valid time; use a prompt defined on the build-time model.
            return build_validation_result(False, 'PickupTime', None)
        hour, minute = pickup_time.split(':')
        hour = parse_int(hour)
        minute = parse_int(minute)
        if math.isnan(hour) or math.isnan(minute):
            # Not a valid time; use a prompt defined on the build-time model.
            return build_validation_result(False, 'PickupTime', None)
        if hour < 10 or hour > 16:
            # Outside of business hours
            return build_validation_result(False, 'PickupTime', 'Our business hours are from ten a m. to four p m. Can you specify a time during this range?')
    if number is not None:
        num = parse_int(number)
        if num < 0 or num > 5:
            return build_validation_result(False,'FlowerNumber', 'Please input a number between 1~5. We can offer 1~5 at once.')
    return build_validation_result(True, None, None)
""" --- Functions that control the bot's behavior --- """
def order_flowers(intent_request):
    """
    Performs dialog management and fulfillment for ordering flowers.
    Beyond fulfillment, the implementation of this intent demonstrates the use of the elicitSlot dialog action
    in slot validation and re-prompting.
    """
    flower_type = get_slots(intent_request)["FlowerType"]
    date = get_slots(intent_request)["PickupDate"]
    pickup_time = get_slots(intent_request)["PickupTime"]
    number = get_slots(intent_request)["FlowerNumber"]
    source = intent_request['invocationSource']
    if source == 'DialogCodeHook':
        # Perform basic validation on the supplied input slots.
        # Use the elicitSlot dialog action to re-prompt for the first violation detected.
        slots = get_slots(intent_request)
        validation_result = validate_order_flowers(flower_type, date, pickup_time, number)
        if not validation_result['isValid']:
            slots[validation_result['violatedSlot']] = None
            return elicit_slot(intent_request['sessionAttributes'],
                               intent_request['currentIntent']['name'],
                               slots,
                               validation_result['violatedSlot'],
                               validation_result['message'])
        # Pass the price of the flowers back through session attributes to be used in various prompts defined
        # on the bot model.
        output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
        if number is not None:
            output_session_attributes['Price'] = int(number) * 5  # Elegant pricing model
        return delegate(output_session_attributes, get_slots(intent_request))
    
    sns = boto3.client('sns')
    snsmessage = {'content': 'Thanks, your order for {} of {} has been placed and will be ready for pickup by {} on {}'.format(number, flower_type, pickup_time, date)}
    #snsmessage = {"test":"message test"}
    sns.publish(
        TopicArn='YOUR_Topic_ARN', 
        Message=json.dumps(snsmessage)
    )
    # Order the flowers, and rely on the goodbye message of the bot to define the message to the end user.
    # In a real bot, this would likely involve a call to a backend service.
    return close(intent_request['sessionAttributes'],
                 'Fulfilled',
                 {'contentType': 'PlainText',
                  'OrderConfirm': 'Thanks, your order for {} of {} has been placed and will be ready for pickup by {} on {}'.format(number, flower_type, pickup_time, date)})
""" --- Intents --- """
def dispatch(intent_request):
    """
    Called when the user specifies an intent for this bot.
    """
    logger.debug('dispatch userId={}, intentName={}'.format(intent_request['userId'], intent_request['currentIntent']['name']))
    intent_name = intent_request['currentIntent']['name']
    # Dispatch to your bot's intent handlers
    if intent_name == 'OrderFlowers':
        return order_flowers(intent_request)
    raise Exception('Intent with name ' + intent_name + ' not supported')
""" --- Main handler --- """
def lambda_handler(event, context):
    """
    Route the incoming request based on intent.
    The JSON body of the request is provided in the event slot.
    """
    # By default, treat the user request as coming from the America/New_York time zone.
    os.environ['TZ'] = 'America/New_York'
    time.tzset()
    logger.debug('event.bot.name={}'.format(event['bot']['name']))
    return dispatch(event)

當(dāng)前標(biāo)題:AWSLex+Lambda
當(dāng)前URL:http://m.2m8n56k.cn/article36/gsegpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器手機(jī)網(wǎng)站建設(shè)商城網(wǎng)站外貿(mào)網(wǎng)站建設(shè)網(wǎng)站策劃網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)
主站蜘蛛池模板: 暖暖日本在线播放 | 日本免费人成黄页在线观看视频 | 久草网在线视频 | 女人扒开腿让男人捅啪啪 | 国产成人a在一区线观看高清 | 国产日本三级 | 国产精品自拍视频 | 亚洲免费在线播放 | 久久青草国产手机看片福利盒子 | 国产精品一区在线免费观看 | 亚洲国产欧洲精品路线久久 | 欧美日韩中文字幕在线观看 | 国产tv在线 | 国产成人精品男人的天堂网站 | 欧美精品hdvdeosex4k | 毛片免费在线播放 | 亚洲天堂免费视频 | 秀人网私拍福利视频在线 | 波多野结衣中文在线播放 | 97精品国产手机 | 亚洲在线看 | 国产黄色自拍 | 中文字幕一二三四区2021 | 美女视频很黄很a免费国产 美女视频黄.免费网址 | 99久久综合给久久精品 | 久久综合99re久久爱 | 日韩欧美特级毛片 | 三级毛片网站 | 国内自产拍自a免费毛片 | 久久免费国产视频 | 最刺激黄a大片免费观看下截 | 美国毛片基地a级e片 | 亚洲欧美一区二区三区综合 | 国产成人亚洲精品无广告 | 特黄特黄一级高清免费大片 | 国产精品成人一区二区三区 | 亚洲美女视频网站 | 欧美骚视频 | 亚洲一区二区精品 | 国产精品九九久久一区hh | 欧美日韩一本 |