2017-05-16 17 views
1

私は今、AWS Lexチャットボットを構築しており、ラムダ機能設定に関するいくつかの問題に直面しています。サンプルコードによれば、このラムダ関数は会話の最後に使用されました。クローズ(.....)AWS Lexラムダ機能スロットを引き出す

'use strict'; 

    // Close dialog with the customer, reporting fulfillmentState of Failed 
     or Fulfilled ("Thanks, your pizza will arrive in 20 minutes") 
    function close(sessionAttributes, fulfillmentState, message) { 
     return { 
      sessionAttributes, 
      dialogAction: { 
       type: 'Close', 
       fulfillmentState, 
       message, 
      }, 
     }; 
    } 

は、しかし、私がやりたいものをDialogCodeHookの代わりに、このFulfillmentCodeHookを使用している機能:コードは次のようだった理由です。

Lex内の最も単純なロジックは、質問1 - >回答1 - >質問2 - >回答2 - >質問2 - >回答3を得ることです。私はしたい何 は応答値=値は1.2 質問3を依頼した場合1.1、1.2 応答値=値は1.1 質問の4-値4.1、値4.2。質問2 を掲載している場合は許さ質問1 - 応答値を掲載し です はい、あなたは決定木を実装するためにLambdaを使うことができます。AWSのディスカッションフォーラムでは、 を使用できます。 Lambdaでは、特定のメッセージを設定し、 'dialogAction'を使用してスロットを引き出すことができます。この具体的な会話の流れについては

if (response_value = 1.1) { 
// set dialogAction.message = "Question 2" 
... 
// set type = ElicitSlot 
... 
// slotToElicit = answer2" 

} 

同様にあなたが質問3、4を依頼する条件を定義するなど

しかし、私はどこ私が.....この場合はを置く必要があることを確認していませんこのElicitSlot関数の使い方

近い機能のサンプルコードのフルバージョンは、次のとおりです。

'use strict'; 

// Close dialog with the customer, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will arrive in 20 minutes") 
function close(sessionAttributes, fulfillmentState, message) { 
    return { 
     sessionAttributes, 
     dialogAction: { 
      type: 'Close', 
      fulfillmentState, 
      message, 
     }, 
    }; 
} 

// --------------- Events ----------------------- 

function dispatch(intentRequest, callback) { 
    console.log('request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.intentName}'); 
    const sessionAttributes = intentRequest.sessionAttributes; 
    const slots = intentRequest.currentIntent.slots; 
    const crust = slots.crust; 
    const size = slots.size; 
    const pizzaKind = slots.pizzaKind; 

    callback(close(sessionAttributes, 'Fulfilled', 
    {'contentType': 'PlainText', 'content': `Okay, I have ordered your ${size} ${pizzaKind} pizza on ${crust} crust`})); 

} 

// --------------- Main handler ----------------------- 

// Route the incoming request based on intent. 
// The JSON body of the request is provided in the event slot. 
exports.handler = (event, context, callback) => { 
    try { 
     dispatch(event, 
      (response) => { 
       callback(null, response); 
      }); 
    } catch (err) { 
     callback(err); 
    } 
}; 

誰かが助けることを願って!どうもありがとうございます!!!!!!!!!!!!!!!!!!!!!

+0

** lex **タグがあなたの質問に間違っていることを恐れています。 (このlexタグは、yaccやbisonと一緒に使用されることが多いコンパイラコンパイラツールのlexやflex用です。)これはあなたが覚えているレックスではないと思います。 (疑問がある場合はlexのバブルヘルプを参照するか、タグをクリックしてください) – Scheff

+0

ああ、私が意味するのはAWS Lex関数です。そのために残念。ありがとう! –

答えて

0

このコードを確認してください:https://github.com/nicholasjackson/slack-bot-lex-lambda/blob/master/src/dispatcher.js

それは同様にあなたが後にしていることをあなたが持っている近い(...)、だけでなく、ElicitSlot(...)を含むすべての可能なシナリオのための関数を示します。 ElicitIntentダイアログアクションタイプもありますが、これはコードでは使用されていませんが、いくつかのシナリオでは役立つ可能性があります。

希望します。 Tibor

+0

ありがとう! –

関連する問題