|
19 | 19 | var express = require('express'); // app server |
20 | 20 | var bodyParser = require('body-parser'); // parser for post requests |
21 | 21 | var AssistantV1 = require('watson-developer-cloud/assistant/v1'); // watson sdk |
22 | | -var _ = require('lodash'); // lodash |
23 | 22 |
|
24 | 23 | var app = express(); |
25 | 24 |
|
@@ -55,34 +54,26 @@ app.post('/api/message', function (req, res) { |
55 | 54 | return res.status(err.code || 500).json(err); |
56 | 55 | } |
57 | 56 |
|
58 | | - console.log('\n\nData.output:'); |
59 | | - |
60 | | - console.log(data.output); |
61 | | - |
62 | 57 | // This is a fix for now, as since Assistant version 2018-07-10, |
63 | 58 | // output text can now be in output.generic.text |
64 | 59 | var output = data.output; |
65 | | - if (output.text.length === 0 && _.has(output, 'generic')) { |
| 60 | + if (output.text.length === 0 && output.hasOwnProperty('generic')) { |
66 | 61 | var generic = output.generic; |
67 | 62 |
|
68 | | - if (_.isArray(generic)) { |
| 63 | + if (Array.isArray(generic)) { |
69 | 64 | // Loop through generic and add all text to data.output.text. |
70 | 65 | // If there are multiple responses, this will add all of them |
71 | 66 | // to the response. |
72 | 67 | for(var i = 0; i < generic.length; i++) { |
73 | | - if (_.has(generic[i], 'text')) { |
| 68 | + if (generic[i].hasOwnProperty('text')) { |
74 | 69 | data.output.text.push(generic[i].text); |
75 | | - } else if (_.has(generic[i], 'title')) { |
| 70 | + } else if (generic[i].hasOwnProperty('title')) { |
76 | 71 | data.output.text.push(generic[i].title); |
77 | 72 | } |
78 | 73 | } |
79 | 74 | } |
80 | 75 | } |
81 | 76 |
|
82 | | - console.log("------------"); |
83 | | - console.log("Output text:"); |
84 | | - console.log(data.output.text); |
85 | | - |
86 | 77 | return res.json(updateMessage(payload, data)); |
87 | 78 | }); |
88 | 79 | }); |
|
0 commit comments