|
| 1 | +var builder = require("botbuilder"); |
| 2 | + |
| 3 | +// Dictionaries |
| 4 | +var glossaryLookup = require('../glossaryLookup'); |
| 5 | +var qnaDB = require('../dictionaries/glossary'); |
| 6 | + |
| 7 | +var makeCompleteGlossaryArticle = require("../makeCompleteGlossaryArticle"); |
| 8 | + |
| 9 | +// global variable to pass states between pieces of the dialog |
| 10 | +var argsGlobal = {}; |
| 11 | + |
| 12 | +module.exports = { |
| 13 | + Label: 'Give single answer', |
| 14 | + Dialog: [ |
| 15 | + /* |
| 16 | + To give a single intermediate answer, flow should be as follows |
| 17 | + 0. A1 is the answer that applies |
| 18 | + 1. give out usr3AnswersDB[A1Key].longText. It will be like "XYZ applies for your case, would you like to know more?" |
| 19 | + 2. if answer = 'Ja', then show glossary |
| 20 | + - jump out of the dialog |
| 21 | +
|
| 22 | + therefore, args should contain: |
| 23 | + args = |
| 24 | + { |
| 25 | + longText: "Möchten Sie wissen, wie sich die aktuellen ordentlichen Steuersätze in den Kantonen voraussichtlich ändern?", |
| 26 | + glossary: ["Steuersatzsenkung HL"] |
| 27 | + } |
| 28 | +
|
| 29 | + we obtain args directly from usr3AnswersDB |
| 30 | + */ |
| 31 | + function (session, args) { |
| 32 | + argsGlobal = args; |
| 33 | + // long text provided in args? |
| 34 | + if(argsGlobal.longText) { |
| 35 | + // show it and ask yes/no to show glossary details |
| 36 | + builder.Prompts.choice(session, argsGlobal.longText, "Ja|Nein", {listStyle: 3, retryPrompt: "I verstehe nicht. Bitte antworten 'ja' oder 'nein'."}); |
| 37 | + } |
| 38 | + }, |
| 39 | + function (session, results) { |
| 40 | + // ok, user chose to learn more. are there glossary details? |
| 41 | + if (results.response.entity == "Ja" && argsGlobal.glossary && argsGlobal.glossary.length > 0) { |
| 42 | + // loop over related glossary records |
| 43 | + argsGlobal.glossary.forEach((glossaryRecordKey) => { |
| 44 | + if(qnaDB[glossaryRecordKey]) { |
| 45 | + // make complete glossary article here |
| 46 | + var msg = makeCompleteGlossaryArticle(session, qnaDB[glossaryRecordKey]) |
| 47 | + session.send(msg); |
| 48 | + } |
| 49 | + }); // foreach ends |
| 50 | + } |
| 51 | + else { |
| 52 | + // if user chooses not to display glossary details, we can handle this here |
| 53 | + } |
| 54 | + session.endDialog(); |
| 55 | + } |
| 56 | + ] |
| 57 | +} |
0 commit comments