2017-07-22 2 views
0

Ich habe zwei Absichten:Amazon Lex Absicht

Intent types

Dies ist das Chat-Bot jetzt:

This is the chat bot now

Danach wird es eine Bestätigung, ob er im Eigenkapital investieren will oder nicht. Wenn er Ja sagt, muss eine andere Absicht gestartet werden, ohne dass er etwas eingibt.

Wie erreiche ich das?

Hier ist meine Lambda-Funktion:

// --------------- 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 })); 

} 

Antwort

Verwandte Themen