Skip to content

Commit 7fc4083

Browse files
aribraygcf-owl-bot[bot]
authored and
Ace Nassri
committed
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 f40f3b8 commit 7fc4083

10 files changed

+747
-0
lines changed
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+
});
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+
});
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+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const uuid = require('uuid');
20+
const webhook = require('../webhook-configure-session-parameters-trigger-transition.js');
21+
22+
// variables to construct path to target page
23+
const location = 'global';
24+
const projectId = process.env.GCLOUD_PROJECT;
25+
const flowId = '00000000-0000-0000-0000-000000000000';
26+
const pageId = `temp_page_${uuid.v4()}`;
27+
const agentId = '4e2cb784-012c-48b2-9d8c-a877d3be3437';
28+
const targetPage = `projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}/pages/${pageId}`;
29+
30+
const number = 100;
31+
32+
const request = {
33+
body: {
34+
targetPage: targetPage,
35+
fulfillmentInfo: {
36+
tag: 'configure-session-parameter-trigger-transition',
37+
},
38+
sessionInfo: {
39+
parameters: {
40+
number: number,
41+
},
42+
},
43+
},
44+
};
45+
46+
describe('trigger transition', () => {
47+
it('should test that webhook response contains target page', async () => {
48+
const temp = JSON.stringify(request);
49+
let response = '';
50+
51+
const res = {
52+
send: function (s) {
53+
response = JSON.stringify(s);
54+
},
55+
};
56+
57+
webhook.triggerTransition(JSON.parse(temp), res);
58+
assert.include(response, pageId);
59+
});
60+
});

0 commit comments

Comments
 (0)