2017-08-31 19 views

答えて

0

現在のところ、Amazon Lexではフォールバックの意図やデフォルトの意図はサポートされていません。しかし、私は回避策を見つけました。ここに私がしたことがあります。

チャットクライアントとLexの間でAPIゲートウェイとラムダ機能を設定します。 APIゲートウェイにリクエストを送信します

enter image description here

あなたのチャットクライアントは、APIゲートウェイはレックスにリクエストを(レックスが1つのよりラムダ関数を持つことになります)転送するラムダ関数とラムダ関数にこれを転送します。 Lexからの応答を返している間、Lambda関数がエラーメッセージであり、何らかのアクションをトリガーしている場合、Lambda関数をチェックインできます。

は、ラムダ関数の中で、私たちはこのようなものを使用することができます。
import logging 
import boto3 

logger = logging.getLogger() 
logger.setLevel(logging.DEBUG) 

client_run = boto3.client('lex-runtime') 
client_model = boto3.client('lex-models') 

def lambda_handler(event, context): 
    response = client_run.post_text(
     botName='name_of_your_bot', 
     botAlias='alias_of_your_bot', 
     userId='some_id', 
     sessionAttributes={ 
      'key1': 'value1' 
     }, 
     inputText=event['user_query'] 
    ) 
    bot_details = client_model.get_bot(
    name='name_of_your_bot', 
    versionOrAlias='$LATEST' 
    ) 
    for content in bot_details['clarificationPrompt']['messages']: 
     if response["message"] == content['content']: 
      return error_handling_method(event) 
    for content in bot_details['abortStatement']['messages']: 
     if response["message"] == content['content']: 
      return error_handling_method(event) 
    return response["message"] 

はそれがお役に立てば幸いです。

関連する問題