Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Fixes for issues in payload, undefined intents and telephony #258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dialogflow-fulfillment.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class WebhookClient {
error('No handler for requested intent');
this.response_
.status(RESPONSE_CODE_BAD_REQUEST)
.status('No handler for requested intent');
.send('No handler for requested intent');
return Promise.reject(new Error('No handler for requested intent'));
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/v2-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const {debug, error} = require('./common');
const { debug, error } = require('./common');

// Response Builder classes
const {
Expand Down Expand Up @@ -149,8 +149,8 @@ class V2Agent {
* Original request language code (i.e. "en")
* @type {string} locale language code indicating the spoken/written language of the original request
*/
this.agent.locale = this.agent.request_.body.queryResult.languageCode;
debug(`Request locale: ${JSON.stringify(this.agent.locale)}`);
this.agent.locale = this.agent.request_.body.queryResult.languageCode;
debug(`Request locale: ${JSON.stringify(this.agent.locale)}`);

/**
* List of messages defined in Dialogflow's console for the matched intent
Expand Down Expand Up @@ -189,7 +189,7 @@ class V2Agent {
addTextResponse_() {
const message = this.agent.responseMessages_[0];
const fulfillmentText = message.ssml || message.text;
this.addJson_({fulfillmentText: fulfillmentText});
this.addJson_({ fulfillmentText: fulfillmentText });
}

/**
Expand All @@ -201,7 +201,7 @@ class V2Agent {
* @private
*/
addPayloadResponse_(payload, requestSource) {
this.addJson_({payload: payload.getPayload_(requestSource)});
this.addJson_({ payload: payload.getPayload_(requestSource) });
}

/**
Expand All @@ -214,7 +214,7 @@ class V2Agent {
addMessagesResponse_(requestSource) {
let messages = this.buildResponseMessages_(requestSource);
if (messages.length > 0) {
this.addJson_({fulfillmentMessages: messages});
this.addJson_({ fulfillmentMessages: messages });
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ class V2Agent {
} else {
responseJson.outputContexts = this.agent.context.getV2OutputContextsArray();
if (this.agent.endConversation_) {
responseJson.triggerEndOfConversation = this.agent.endConversation_;
responseJson.end_interaction = this.agent.endConversation_;
}
debug('Response to Dialogflow: ' + JSON.stringify(responseJson));
this.agent.response_.json(responseJson);
Expand Down Expand Up @@ -394,7 +394,7 @@ class V2Agent {
if (!messageJson.text.text[0]) {
return null;
} else {
return new Text({text: messageJson.text.text[0], platform: platform});
return new Text({ text: messageJson.text.text[0], platform: platform });
}
}

Expand Down Expand Up @@ -441,6 +441,9 @@ class V2Agent {
* @private
*/
convertPayloadJson_(messageJson, platform) {
if (!platform) {
platform = (messageJson.payload.platform) ? messageJson.payload.platform : 'PLATFORM_UNSPECIFIED';
}
return new PayloadResponse(platform, messageJson.payload, {
rawPayload: true,
sendAsMessage: true,
Expand Down
7 changes: 6 additions & 1 deletion test/webhook-v1-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ test('Test v1 original request', async (t) => {
});

test('Test v1 no handler defined', async (t) => {
let response = new ResponseMock();
let response = new ResponseMock((response) => {
t.is(
response,
'No handler for requested intent',
);
});
let agent = new WebhookClient({
request: {body: mockSlackV1Request},
response: response,
Expand Down
11 changes: 8 additions & 3 deletions test/webhook-v2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,13 @@ test('Test v2 original request', async (t) => {
);
});

test('Test v2 no handler defined', async (t) => {
let response = new ResponseMock();
test('Test v2 no handler defined', async t => {
let response = new ResponseMock((response) => {
t.is(
response,
'No handler for requested intent',
);
});
let agent = new WebhookClient({
request: {body: mockGoogleV2Request},
response: response,
Expand Down Expand Up @@ -530,7 +535,7 @@ test('Test v2 end conversation', async (t) => {
agent.end('thanks for talking to me!');
},
(responseJson) => {
t.deepEqual(responseJson.triggerEndOfConversation, true);
t.deepEqual(responseJson.end_interaction, true);
},
);
});
Expand Down