From a02dd662db6f1a14dd38dff37da472eb4c6c5f5d Mon Sep 17 00:00:00 2001 From: Ari Bornstein Date: Mon, 18 Sep 2017 13:50:32 +0300 Subject: [PATCH] Added support for - Multiprompts (Allows users to process text and attachements useful for integrating with images and cognitive services) - Session variables in hero cards and prompt options --- README.md | 1 + lib/GraphDialog.js | 29 +++++++++++++++++++++++------ package-lock.json | 28 +++++++++++++++++++++++++++- package.json | 1 + 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8366003..81e08bc 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ Properties: Prompt types can be one of: * `text` [default] - Prompts for free text. This options is set in case no `type` property is provided +* `multiprompt` - Prompts for free text or an attachment. * `number` - Request for a valid number * `time` - Request for a time construct like "2 hours ago", "yesterday", etc. * `confirm` - Yes \ No diff --git a/lib/GraphDialog.js b/lib/GraphDialog.js index 9b67461..94f5679 100755 --- a/lib/GraphDialog.js +++ b/lib/GraphDialog.js @@ -11,6 +11,7 @@ var Node = require('./Node'); var IntentScorer = require('./IntentScorer'); var Common = require('./Common'); var Validator = require('./Validator'); +var multiPrompt = require('botframework_multiprompt'); // the GraphDialog class manages the dialog's state class GraphDialog { @@ -106,6 +107,7 @@ class GraphDialog { // this is where the magic happens. loops this list of steps for each node. setBotDialog() { var _this = this; + this.options.bot.dialog('multiPrompt', multiPrompt.multiPrompt); this.options.bot.dialog(this.internalPath, [ async (session, args, next) => { session.dialogData.data = args || {}; @@ -153,6 +155,14 @@ class GraphDialog { var promptType = currentNode.data.type || 'text'; currentNode.data.options = currentNode.data.options || {}; + //replace handlebars + currentNode.data.text = strformat(currentNode.data.text, session.dialogData.data); + for(var i = 0; i < currentNode.data.options.length; i++){ + if (typeof(currentNode.data.options[i] == 'string')){ + currentNode.data.options[i] = strformat(currentNode.data.options[i], session.dialogData.data); + } + } + var listStyle = (currentNode.data.config && currentNode.data.config.listStyle && builder.ListStyle[currentNode.data.config.listStyle]) @@ -162,7 +172,14 @@ class GraphDialog { currentNode.data.options.listStyle = listStyle; } - builder.Prompts[promptType](session, currentNode.data.text, currentNode.data.options, { listStyle }); + if (currentNode.data.type == 'multiprompt'){ + //handle multiprompt + builder.Prompts.multiPrompt = multiPrompt.multiPromptsLauncher; + multiPrompt.multiPromptsLauncher(session, currentNode.data.text ); + } else{ + builder.Prompts[promptType](session, currentNode.data.text, currentNode.data.options, { listStyle }); + } + break; case Node.NodeType.score: @@ -226,20 +243,20 @@ class GraphDialog { generateHeroCard(session, data) { var hero = new builder.HeroCard(session); - if (data.title) hero.title(data.title); - if (data.subtitle) hero.subtitle(data.subtitle); - if (data.text) hero.text(data.text); + if (data.title) hero.title(strformat(data.title, session.dialogData.data)); + if (data.subtitle) hero.subtitle(strformat(data.subtitle, session.dialogData.data)); + if (data.text) hero.text(strformat(data.text, session.dialogData.data)); if (data.images && data.images.length > 0) { hero.images([ - builder.CardImage.create(session, data.images[0]) + builder.CardImage.create(session, strformat(data.images[0], session.dialogData.data)) ]); } if (data.tap) { switch (data.tap.action) { case "openUrl": - hero.tap(builder.CardAction.openUrl(session, data.tap.value)); + hero.tap(builder.CardAction.openUrl(session, strformat(data.tap.value, session.dialogData.data))); break; } } diff --git a/package-lock.json b/package-lock.json index 61b37ac..03a8617 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bot-graph-dialog", - "version": "3.4.5", + "version": "3.8.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -91,6 +91,32 @@ "url-join": "1.1.0" } }, + "botframework_multiprompt": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/botframework_multiprompt/-/botframework_multiprompt-1.0.3.tgz", + "integrity": "sha512-zJXR2IQwdjRlv9LuULA8JDMs1Bz+tx9p75rFH+EdcQHY4xYUWxHrcfsQ5aj8MqoJds42W3c/hOMaQSxmZvg8kw==", + "requires": { + "botbuilder": "3.9.1" + }, + "dependencies": { + "botbuilder": { + "version": "3.9.1", + "resolved": "https://registry.npmjs.org/botbuilder/-/botbuilder-3.9.1.tgz", + "integrity": "sha1-EErt42IYXQqjIizbVF4504jQnwY=", + "requires": { + "async": "1.5.2", + "base64url": "2.0.0", + "chrono-node": "1.3.4", + "jsonwebtoken": "7.4.1", + "promise": "7.3.1", + "request": "2.81.0", + "rsa-pem-from-mod-exp": "0.8.4", + "sprintf-js": "1.1.1", + "url-join": "1.1.0" + } + } + } + }, "buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", diff --git a/package.json b/package.json index c8e0eb4..57e0e0d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "homepage": "https://github.com/CatalystCode/bot-graph-dialog#readme", "dependencies": { "botbuilder": "^3.8.4", + "botframework_multiprompt": "^1.0.3", "extend": "^3.0.0", "jsep": "^0.3.0", "request-promise": "^4.1.1",