From e98310bc1e8dc734394ac4536185ff1979c11050 Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Tue, 19 Dec 2017 11:45:13 +0200 Subject: [PATCH 1/6] concat array of responses --- actions.js | 2 +- skill-sdk/lib/response.js | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/actions.js b/actions.js index b5af0df..459a43a 100644 --- a/actions.js +++ b/actions.js @@ -42,7 +42,7 @@ let converseCallback = function (result, response, context, err) { // example of adding a card // example of a card sent to the application, the action and the json most of the time will come from WCS response.card('some action', {"some": "json"}); - response.say(result.output.text, 'random').deleteSkillSession(deleteSkillSession).send(); + response.say(result.output.text).deleteSkillSession(deleteSkillSession).send(); } }; diff --git a/skill-sdk/lib/response.js b/skill-sdk/lib/response.js index a3e345e..3ab0cff 100644 --- a/skill-sdk/lib/response.js +++ b/skill-sdk/lib/response.js @@ -21,19 +21,9 @@ function Response(callback) { }; } -Response.prototype.say = function(text, selection = 'random') { +Response.prototype.say = function(text) { if (text instanceof Array) { - if (typeof selection === 'string') { - switch (selection) { - case 'random': - selection = Math.floor(Math.random() * text.length); - break; - default: - selection = 0; - break; - } - } - this.response.speech.text = text[selection]; + this.response.speech.text = text.toString(); } else { if (this.response.speech.text) { this.response.speech.text = this.response.speech.text + ' ' + text; From 317cfc0659f767eec2ade67d69d947b7710b71e0 Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Sun, 24 Dec 2017 14:17:22 +0200 Subject: [PATCH 2/6] added 'all' as an option to the response.say function --- skill-sdk/lib/response.js | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/skill-sdk/lib/response.js b/skill-sdk/lib/response.js index 3ab0cff..d88401b 100644 --- a/skill-sdk/lib/response.js +++ b/skill-sdk/lib/response.js @@ -21,17 +21,37 @@ function Response(callback) { }; } -Response.prototype.say = function(text) { - if (text instanceof Array) { - this.response.speech.text = text.toString(); - } else { - if (this.response.speech.text) { - this.response.speech.text = this.response.speech.text + ' ' + text; +Response.prototype.say = function(text, selection = 'all') { + if (text instanceof Array) { + if (typeof selection === 'string') { + let res; + switch (selection) { + case 'random': + selection = Math.floor(Math.random() * text.length); + res = text[selection]; + break; + case 'all': + for(let answer in res) { + if(answer === "") { + res.splice(answer, 1); + } + } + res = text.toString(); + break; + default: + selection = 0; + break; + } + } + this.response.speech.text = res; } else { - this.response.speech.text = text; + if (this.response.speech.text) { + this.response.speech.text = this.response.speech.text + ' ' + text; + } else { + this.response.speech.text = text; + } } - } - return this; + return this; }; Response.prototype.expressiveness = function(expressiveness = 'normal') { From a3ffb4b3621b750ac9cafbdc602dde56df5fcc47 Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Sun, 24 Dec 2017 14:40:12 +0200 Subject: [PATCH 3/6] doens't remove empty strings from array --- skill-sdk/lib/response.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/skill-sdk/lib/response.js b/skill-sdk/lib/response.js index d88401b..0155bbf 100644 --- a/skill-sdk/lib/response.js +++ b/skill-sdk/lib/response.js @@ -31,11 +31,6 @@ Response.prototype.say = function(text, selection = 'all') { res = text[selection]; break; case 'all': - for(let answer in res) { - if(answer === "") { - res.splice(answer, 1); - } - } res = text.toString(); break; default: From 6ce2405adc89171d6d95cd9a9f78e77cb8cd6090 Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Sun, 24 Dec 2017 15:58:46 +0200 Subject: [PATCH 4/6] changed default response.say behavior --- skill-sdk/lib/response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skill-sdk/lib/response.js b/skill-sdk/lib/response.js index 0155bbf..af27394 100644 --- a/skill-sdk/lib/response.js +++ b/skill-sdk/lib/response.js @@ -34,7 +34,7 @@ Response.prototype.say = function(text, selection = 'all') { res = text.toString(); break; default: - selection = 0; + res = text; break; } } From 581040284232a2fdb648b703d860fd39e8a6ef16 Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Mon, 25 Dec 2017 14:57:55 +0200 Subject: [PATCH 5/6] fixed default behavior --- skill-sdk/lib/response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skill-sdk/lib/response.js b/skill-sdk/lib/response.js index af27394..7b07b01 100644 --- a/skill-sdk/lib/response.js +++ b/skill-sdk/lib/response.js @@ -34,7 +34,7 @@ Response.prototype.say = function(text, selection = 'all') { res = text.toString(); break; default: - res = text; + res = text[0]; break; } } From ee58714364751a4231b41de6221624d4f40c9cdd Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Wed, 27 Dec 2017 13:11:23 +0200 Subject: [PATCH 6/6] minor bug fix --- skill-sdk/lib/response.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/skill-sdk/lib/response.js b/skill-sdk/lib/response.js index 7b07b01..b80570a 100644 --- a/skill-sdk/lib/response.js +++ b/skill-sdk/lib/response.js @@ -23,8 +23,8 @@ function Response(callback) { Response.prototype.say = function(text, selection = 'all') { if (text instanceof Array) { + let res = text[0]; if (typeof selection === 'string') { - let res; switch (selection) { case 'random': selection = Math.floor(Math.random() * text.length); @@ -34,7 +34,6 @@ Response.prototype.say = function(text, selection = 'all') { res = text.toString(); break; default: - res = text[0]; break; } }