2017-07-22 2 views
0

私は2つのインテントを持っているが:アマゾンレックス意思

This is the chat bot now

彼は株式に投資するかどうかの確認が存在します。この後:

Intent types

これは、今チャットボットですか否か。彼が「はい」と答えた場合は、何も入力せずに別の意図を開始する必要があります。

どうすればよいですか?

// --------------- Intents ----------------------- 
var type; 
/** 
* Called when the user specifies an intent for this skill. 
*/ 
function dispatch(intentRequest, callback) { 
    // console.log(JSON.stringify(intentRequest, null, 2)); 
    console.log(`dispatch userId=${intentRequest.userId}, intent=${intentRequest.currentIntent.name}`); 

    const name = intentRequest.currentIntent.name; 

    // Dispatch to your skill's intent handlers 
    if (name === 'FinancialType') { 
     return getFinancialType(intentRequest,callback); 
    } 
    throw new Error(`Intent with name ${name} not supported`); 
} 

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

function loggingCallback(response, originalCallback) { 
    // console.log(JSON.stringify(response, null, 2)); 
    originalCallback(null, response); 
} 

// 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 { 
     // By default, treat the user request as coming from the America/New_York time zone. 
     process.env.TZ = 'America/New_York'; 
     console.log(`event.bot.name=${event.bot.name}`); 

     /** 
     * Uncomment this if statement and populate with your Lex bot name and/or version as 
     * a sanity check to prevent invoking this Lambda function from an undesired Lex bot or 
     * bot version. 
     */ 
     /* 
     if (event.bot.name !== 'MakeAppointment') { 
      callback('Invalid Bot Name'); 
     } 
     */ 
     dispatch(event, (response) => loggingCallback(response, callback)); 
    } catch (err) { 
     callback(err); 
    } 
}; 

function close(fulfillmentState, message) { 
    return { 
     dialogAction: { 
      type: 'Close', 
      fulfillmentState, 
      message, 
     }, 
    }; 
} 


function elicitSlot(intentName, slots, slotToElicit, message) { 
    return { 
     dialogAction: { 
      type: 'ElicitSlot', 
      intentName, 
      slots, 
      slotToElicit, 
      message, 
     }, 
    }; 
} 

function buildValidationResult(isValid, violatedSlot, messageContent) { 
    return { 
     isValid, 
     violatedSlot, 
     message: { contentType: 'PlainText', content: messageContent }, 
    }; 
} 

function getFinancialType(intentRequest,callback){ 
    var age = intentRequest.currentIntent.slots.age; 
    var amount = intentRequest.currentIntent.slots.amount; 
    const source = intentRequest.invocationSource; 

    if(amount >= 10000){ 
     type = 'Equity'; 
    } 

    callback(close('Fulfilled',{contentType: 'PlainText', 
    content: `You have choosen to invest ` + amount + ' in ' + type })); 

} 

答えて

関連する問題