2017-12-21 15 views
1

私はディナーオーダーを設計しようとしています。 'orderDinner'ダイアログには2つの機能しかありません - >プロンプトのテキストと応答を処理します。 'orderDinner'ダイアログのコンテキストでは、beginDialogActionはトリガー 'alcohol'に対して行われます。新しいダイアログ 'checkAge'が呼び出されます。これを達成するためにどのような方法プロンプトの途中で中断されたダイアログは、プロンプトステップの最初から再開します

bot.dialog('orderDinner', [ 
function (session, args){ 
    let promptmessage; 
    if (args && args.resumed == true) { 
     promptmessage = 'What else would you like to add?'; 
    } else { 
     promptmessage = 'What would you like to order today?'; 
    } 
    promptmessage += '(_type done when no more items to add_)'; 
    builder.Prompts.text(session, promptmessage); 
}, 
function (session, results, args) { 
    session.send(`${results.response} added to dinner cart!`); 
    session.replaceDialog('orderDinner', { 
     resumed : true 
    }); 
} 
]).beginDialogAction('checkAge', 'checkAge', { 
    matches: /^alcohol$/i 
}).beginDialogAction('doneOrderDinner', 'doneOrderDinner', { 
    matches: /^done$/i 
}) 

bot.dialog('doneOrderDinner',[ 
    (session) => { 
     session.send("Food will be on your way"); 
     session.replaceDialog('mainBotMenu'); 
    } 
]) 

bot.dialog('checkAge', [ 
    (session, result) => { 
     builder.Prompts.number(session, 'Please enter your age'); 
    }, 
    (session, result) => { 
     let canGetAlcohol = false; 
     if(result.response > 18) { 
      session.send('You can get alcohol'); 
      canGetAlcohol = true; 
     } else { 
      session.send('Too young for alcohol'); 
     } 
     const dialogResult = { resumed : true, canGetAlcohol : canGetAlcohol } 
     session.endDialogWithResult(dialogResult) 
    } 
]); 

があります:checkAgeが行われ、年齢が「orderDinner]ダイアログがステップ2から再開されなければならない検証されますが、それは常にステップ以下は1から開始した後、私が欲しいのは、コードされています流れを壊すことなく?さて、メッセージ: 「アルコールがカートに追加さ」が

答えて

0

を印刷されることはありませんあなたは関数がIDialogWaterfallStepインタフェースを実装ダイアログのダイアログまたは配列である必要があり、あなたのorderDinnerダイアログ内の関数で誤ったパラメータを渡されてきた、とIDialogWaterfallStepです

export interface IDialogWaterfallStep { 
    /** 
    * @param session Session object for the current conversation. 
    * @param result 
    * * __result:__ _{any}_ - For the first step of the waterfall this will be `null` or the value of any arguments passed to the handler. 
    * * __result:__ _{IDialogResult}_ - For subsequent waterfall steps this will be the result of the prompt or dialog called in the previous step. 
    * @param skip Function used to manually skip to the next step of the waterfall. 
    * @param skip.results (Optional) results to pass to the next waterfall step. This lets you more accurately mimic the results returned from a prompt or dialog. 
    */ 
    (session: Session, result?: any | IDialogResult<any>, skip?: (results?: IDialogResult<any>) => void): any; 
} 

だからあなたのコード内でパラメータresumedは変数resultsにする必要があります:このように。これでコードを変更することができます。

function (session, args){ 
    let promptmessage; 
    if (args && args.resumed) { 
     promptmessage = 'What else would you like to add?'; 
    } else { 
     promptmessage = 'What would you like to order today?'; 
    } 
    promptmessage += '(_type done when no more items to add_)'; 
    builder.Prompts.text(session, promptmessage); 
}, 
function (session, results) { 
    session.send(`${results.response} added to dinner cart!`); 
    session.replaceDialog('orderDinner', { 
     resumed : true 
    }); 
} 
+0

ありがとうございます。しかし、まだ私は意図されたものを達成することができません。 「アルコールをカートに追加」は印刷されません。つまり、「checkAge」ダイアログの後に、最初のステップから注文夕食が開始されます。 – Sushovan

+0

@Sushovan、あなたは他のコードを変更していませんか?私はあなたのコードを使用し、私は私の答えで言ったようにパラメータを変更した、 "アルコールがカートに追加された"私の側によく表示されます。 –

+0

はい、まったく同じコードです。それは面白いです。だからちょうどあなたがcheckAgeダイアログを通過することを確認するために、そして「アルコールがカートに追加されました」というメッセージが受信されます。ここにコードを貼り付けることは可能ですか?私はまったく同じことを実行し、私はいくつかの設定を台無しにしているかどうかを確認します。ありがとう!! – Sushovan

関連する問題