From 1b4f5f0f6202ff38d4ad9ca0a371168131d28f7d Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 30 Jan 2017 23:23:58 +0000 Subject: [PATCH] Handle arrays and empty strings in conversation response Closes #14 --- recipes/conversation/conversation.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/recipes/conversation/conversation.js b/recipes/conversation/conversation.js index c2e02195..e205d1ac 100755 --- a/recipes/conversation/conversation.js +++ b/recipes/conversation/conversation.js @@ -138,10 +138,16 @@ textStream.on('data', function(str) { console.log('error:', err); } else { context = response.context ; //update conversation context - conversation_response = response.output.text[0] ; - if (conversation_response != undefined ){ + + if (Array.isArray(response.output.text)) { + conversation_response = response.output.text.join(' ').trim(); + } else { + conversation_response = undefined; + } + + if (conversation_response){ var params = { - text: response.output.text[0], + text: conversation_response, voice: config.voice, accept: 'audio/wav' };