Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 709dc6d

Browse files
feat: add Webhook samples (#259)
* add webhook-configure-session-parameter-enable-agent-response sample and test Change-Id: Ia8593160ed33060eb497a15723b21c1221ce55c9 * add webhook-configure-session-parameter-trigger-transition sample and test Change-Id: I118abb59182879b6969018da97d04eea0b8daeb0 * add webhook-configure-optional-or-required-form-parameters sample and test Change-Id: I7cbfeb11cece7ccf873dbc7a6dd7cff9ae264ffe * add configure-session-parameters sample and test Change-Id: Ib9f1a110473751508b50259c4696593580c64a91 * fix form parameter path Change-Id: I6411000a7d0240d7552d725c2fd1049be781a9ab * add webhook-validate-form-parameter sample and test Change-Id: I82097be3fc3f91651c88b99c7431ebb602c42c66 * add cx to region tag Change-Id: I6640604512c27a341ab8e26238bf8c3fbd1e77ef * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix test Change-Id: Icc70e18b40d8684c7909e8383b4c226fa94a162b * fix region tag Change-Id: I0fe3849c0eaf12eaf247088993898cbb47dace44 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 39f1d1c commit 709dc6d

12 files changed

Lines changed: 842 additions & 0 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-dialogflow-
151151
| Long-running-operation | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/long-running-operation.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/long-running-operation.js,samples/README.md) |
152152
| Quickstart | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
153153
| Update-intent | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/update-intent.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/update-intent.js,samples/README.md) |
154+
| Webhook-configure-optional-or-required-form-parameters | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-optional-or-required-form-parameters.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-optional-or-required-form-parameters.js,samples/README.md) |
155+
| Webhook-configure-session-parameters-enable-agent-response | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-session-parameters-enable-agent-response.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-session-parameters-enable-agent-response.js,samples/README.md) |
156+
| Webhook-configure-session-parameters-trigger-transition | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-session-parameters-trigger-transition.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-session-parameters-trigger-transition.js,samples/README.md) |
157+
| Webhook-configure-session-parameters | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-session-parameters.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-session-parameters.js,samples/README.md) |
158+
| Webhook-validate-form-parameter | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-validate-form-parameter.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-validate-form-parameter.js,samples/README.md) |
154159
| Webhooks | [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhooks.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhooks.js,samples/README.md) |
155160

156161

samples/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
* [Long-running-operation](#long-running-operation)
2626
* [Quickstart](#quickstart)
2727
* [Update-intent](#update-intent)
28+
* [Webhook-configure-optional-or-required-form-parameters](#webhook-configure-optional-or-required-form-parameters)
29+
* [Webhook-configure-session-parameters-enable-agent-response](#webhook-configure-session-parameters-enable-agent-response)
30+
* [Webhook-configure-session-parameters-trigger-transition](#webhook-configure-session-parameters-trigger-transition)
31+
* [Webhook-configure-session-parameters](#webhook-configure-session-parameters)
32+
* [Webhook-validate-form-parameter](#webhook-validate-form-parameter)
2833
* [Webhooks](#webhooks)
2934

3035
## Before you begin
@@ -263,6 +268,91 @@ __Usage:__
263268

264269

265270

271+
### Webhook-configure-optional-or-required-form-parameters
272+
273+
View the [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-optional-or-required-form-parameters.js).
274+
275+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-optional-or-required-form-parameters.js,samples/README.md)
276+
277+
__Usage:__
278+
279+
280+
`node samples/webhook-configure-optional-or-required-form-parameters.js`
281+
282+
283+
-----
284+
285+
286+
287+
288+
### Webhook-configure-session-parameters-enable-agent-response
289+
290+
View the [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-session-parameters-enable-agent-response.js).
291+
292+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-session-parameters-enable-agent-response.js,samples/README.md)
293+
294+
__Usage:__
295+
296+
297+
`node samples/webhook-configure-session-parameters-enable-agent-response.js`
298+
299+
300+
-----
301+
302+
303+
304+
305+
### Webhook-configure-session-parameters-trigger-transition
306+
307+
View the [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-session-parameters-trigger-transition.js).
308+
309+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-session-parameters-trigger-transition.js,samples/README.md)
310+
311+
__Usage:__
312+
313+
314+
`node samples/webhook-configure-session-parameters-trigger-transition.js`
315+
316+
317+
-----
318+
319+
320+
321+
322+
### Webhook-configure-session-parameters
323+
324+
View the [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-configure-session-parameters.js).
325+
326+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-configure-session-parameters.js,samples/README.md)
327+
328+
__Usage:__
329+
330+
331+
`node samples/webhook-configure-session-parameters.js`
332+
333+
334+
-----
335+
336+
337+
338+
339+
### Webhook-validate-form-parameter
340+
341+
View the [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhook-validate-form-parameter.js).
342+
343+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dialogflow-cx&page=editor&open_in_editor=samples/webhook-validate-form-parameter.js,samples/README.md)
344+
345+
__Usage:__
346+
347+
348+
`node samples/webhook-validate-form-parameter.js`
349+
350+
351+
-----
352+
353+
354+
355+
266356
### Webhooks
267357

268358
View the [source code](https://github.com/googleapis/nodejs-dialogflow-cx/blob/main/samples/webhooks.js).
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
// Copyright 2021 Google LLC
18+
//
19+
// Licensed under the Apache License, Version 2.0 (the "License");
20+
// you may not use this file except in compliance with the License.
21+
// You may obtain a copy of the License at
22+
//
23+
// http://www.apache.org/licenses/LICENSE-2.0
24+
//
25+
// Unless required by applicable law or agreed to in writing, software
26+
// distributed under the License is distributed on an "AS IS" BASIS,
27+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
// See the License for the specific language governing permissions and
29+
// limitations under the License.
30+
31+
'use strict';
32+
33+
const {assert} = require('chai');
34+
const {describe, it} = require('mocha');
35+
const webhook = require('../webhook-configure-optional-or-required-form-parameters');
36+
const number = 100;
37+
38+
describe('configure optional or required form parameter', () => {
39+
it('should test that webhook sets parameter as required', async () => {
40+
const request = {
41+
body: {
42+
fulfillmentInfo: {
43+
tag: 'required',
44+
},
45+
pageInfo: {
46+
formInfo: {
47+
parameterInfo: [
48+
{
49+
displayName: 'number',
50+
value: number,
51+
},
52+
],
53+
},
54+
},
55+
},
56+
};
57+
const temp = JSON.stringify(request);
58+
let response = '';
59+
60+
const res = {
61+
send: function (s) {
62+
response = JSON.stringify(s);
63+
},
64+
};
65+
66+
webhook.configureOptionalFormParam(JSON.parse(temp), res);
67+
assert.include(response, 'This parameter is required.');
68+
});
69+
70+
it('should test that webhook sets parameter as optional', async () => {
71+
const request = {
72+
body: {
73+
fulfillmentInfo: {
74+
tag: 'optional',
75+
},
76+
pageInfo: {
77+
formInfo: {
78+
parameterInfo: [
79+
{
80+
displayName: 'number',
81+
value: number,
82+
},
83+
],
84+
},
85+
},
86+
},
87+
};
88+
const temp = JSON.stringify(request);
89+
let response = '';
90+
91+
const res = {
92+
send: function (s) {
93+
response = JSON.stringify(s);
94+
},
95+
};
96+
97+
webhook.configureOptionalFormParam(JSON.parse(temp), res);
98+
assert.include(response, 'This parameter is optional.');
99+
});
100+
});
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
// Copyright 2021 Google LLC
18+
//
19+
// Licensed under the Apache License, Version 2.0 (the "License");
20+
// you may not use this file except in compliance with the License.
21+
// You may obtain a copy of the License at
22+
//
23+
// http://www.apache.org/licenses/LICENSE-2.0
24+
//
25+
// Unless required by applicable law or agreed to in writing, software
26+
// distributed under the License is distributed on an "AS IS" BASIS,
27+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
// See the License for the specific language governing permissions and
29+
// limitations under the License.
30+
31+
'use strict';
32+
33+
const {assert} = require('chai');
34+
const {describe, it} = require('mocha');
35+
const webhook = require('../webhook-configure-session-parameters-enable-agent-response');
36+
const number = 100;
37+
38+
describe('enable agent response', () => {
39+
it('should test webhook increases value of session parameter', async () => {
40+
const request = {
41+
body: {
42+
fulfillmentInfo: {
43+
tag: 'increase number',
44+
},
45+
sessionInfo: {
46+
parameters: {
47+
number: number,
48+
},
49+
},
50+
},
51+
};
52+
const temp = JSON.stringify(request);
53+
let response = '';
54+
55+
const res = {
56+
send: function (s) {
57+
response = JSON.stringify(s);
58+
},
59+
};
60+
61+
webhook.enableAgentResponse(JSON.parse(temp), res);
62+
assert.include(response, 'increased value');
63+
});
64+
65+
it('should test webhook decreases value of session parameter', async () => {
66+
const request = {
67+
body: {
68+
fulfillmentInfo: {
69+
tag: 'decrease number',
70+
},
71+
sessionInfo: {
72+
parameters: {
73+
number: number,
74+
},
75+
},
76+
},
77+
};
78+
const temp = JSON.stringify(request);
79+
let response = '';
80+
81+
const res = {
82+
send: function (s) {
83+
response = JSON.stringify(s);
84+
},
85+
};
86+
87+
webhook.enableAgentResponse(JSON.parse(temp), res);
88+
assert.include(response, 'decreased value');
89+
});
90+
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
// Copyright 2021 Google LLC
18+
//
19+
// Licensed under the Apache License, Version 2.0 (the "License");
20+
// you may not use this file except in compliance with the License.
21+
// You may obtain a copy of the License at
22+
//
23+
// http://www.apache.org/licenses/LICENSE-2.0
24+
//
25+
// Unless required by applicable law or agreed to in writing, software
26+
// distributed under the License is distributed on an "AS IS" BASIS,
27+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
// See the License for the specific language governing permissions and
29+
// limitations under the License.
30+
31+
'use strict';
32+
33+
const {assert} = require('chai');
34+
const {describe, it} = require('mocha');
35+
const webhook = require('../webhook-configure-session-parameters');
36+
37+
describe('configure session parameters', () => {
38+
it('should test that webhook adds new session parameter', async () => {
39+
const request = {
40+
body: {
41+
fulfillmentInfo: {
42+
tag: 'month',
43+
},
44+
},
45+
};
46+
const temp = JSON.stringify(request);
47+
let response = '';
48+
49+
const res = {
50+
send: function (s) {
51+
response = JSON.stringify(s);
52+
},
53+
};
54+
55+
webhook.configureSessionParams(JSON.parse(temp), res);
56+
assert.include(response, 'January');
57+
});
58+
59+
it('should test that webhook configures session parameter', async () => {
60+
const request = {
61+
body: {
62+
fulfillmentInfo: {
63+
tag: 'year',
64+
},
65+
},
66+
};
67+
const temp = JSON.stringify(request);
68+
let response = '';
69+
70+
const res = {
71+
send: function (s) {
72+
response = JSON.stringify(s);
73+
},
74+
};
75+
76+
webhook.configureSessionParams(JSON.parse(temp), res);
77+
assert.include(response, '1999');
78+
});
79+
});

0 commit comments

Comments
 (0)