Skip to content
Permalink
Browse files

fix: return full API.AI response on empty message

  • Loading branch information...
webus committed Aug 28, 2017
1 parent 4b19c4f commit 1c076c4fbd183aca0d43992bfbe1f1c4389bfd27
Showing with 69 additions and 8 deletions.
  1. +34 −0 fixtures/apiai/test_response_empty.json
  2. +1 −1 package.json
  3. +5 −7 src/api-ai.js
  4. +29 −0 tests/test_fb.js
@@ -0,0 +1,34 @@
{
"id": "efe087b8-8486-4117-8863-c63b09a0dd5a",
"timestamp": "2017-08-08T17:06:28.086Z",
"lang": "ru",
"result": {
"source": "agent",
"resolvedQuery": "turbo test",
"action": "action1",
"actionIncomplete": false,
"parameters": { "binType": "Yellow Bin" },
"contexts": [
{ "name": "missed_pickup",
"parameters": { "bintype.original": "yellow", "bintype": "Yellow Bin" },
"lifespan": 1
}
],
"metadata": {
"intentId": "762939a1-36f6-4a99-9de3-349e72ecb7be",
"webhookUsed": "false",
"webhookForSlotFillingUsed": "false",
"intentName": "turboTest"
},
"fulfillment": {
"speech": "",
"messages": []
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "35cb38b7-cc7a-4f56-a43c-c00fc3eb13d6"
}
@@ -1,6 +1,6 @@
{
"name": "botstack",
"version": "0.1.3",
"version": "0.1.4",
"description": "Bot Stack",
"main": "index.js",
"scripts": {
@@ -65,14 +65,12 @@ function processResponse(response, senderID) {
senderId: senderID
});
return null;
} else if (!lodash.isEmpty(messages)) {
const returnData = {
messages,
response
};
return returnData;
}
return null;
const returnData = {
messages,
response
};
return returnData;
}
return null;
}
@@ -242,4 +242,33 @@ describe('Testing FB', () => {
assert.equal(lodash.get(data, '[0].attachment.type'), 'image');
assert.equal(lodash.get(data, '[0].attachment.payload.url'), 'http://example.com/image.jpg');
});

it('Testing with empty response', async () => {
const apiAiTextResponse = require('../fixtures/apiai/test_response_empty.json');
const data = [];

const apiai = require('../src/api-ai');
const apiAiResult = apiai.processResponse(apiAiTextResponse, '1234567890');

rewiremock('./reply').callThought().with({
reply: async (message, senderId) => {
data.push(message);
return true;
}
});

rewiremock.enable();
rewiremock.isolation();

const fb = require(rewiremock.resolve('../src/fb'));

const senderID = '1234567890';
const res = await fb.processMessagesFromApiAi(apiAiResult, senderID);

rewiremock.disable();
rewiremock.clear();

assert.equal(lodash.get(apiAiResult, 'messages').length, 0);
assert.equal(!lodash.isEmpty(lodash.get(apiAiResult, 'response.result.action')), true);
});
});

0 comments on commit 1c076c4

Please sign in to comment.
You can’t perform that action at this time.