Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework webhook nodes to route on @webhook.status #1274

Open
wants to merge 1 commit into
base: main
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Array [
],
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
"type": "has_category",
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
"uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
},
],
"categories": Array [
Expand Down Expand Up @@ -245,7 +245,7 @@ Array [
],
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
"type": "has_category",
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
"uuid": "42ebf1d0-a43e-4ba6-9577-c863b20c88c4",
},
],
"categories": Array [
Expand Down
4 changes: 2 additions & 2 deletions src/components/flow/routers/airtime/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AirtimeRouterFormState,
AirtimeTransferEntry
} from 'components/flow/routers/airtime/AirtimeRouterForm';
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
import { Types } from 'config/interfaces';
import { TransferAirtime } from 'flowTypes';
import { RenderNode } from 'store/flowContext';
Expand Down Expand Up @@ -56,7 +56,7 @@ export const stateToNode = (
result_name: state.resultName.value
};

return createWebhookBasedNode(newAction, settings.originalNode, true);
return createServiceCallSplitNode(newAction, settings.originalNode, false);
};

export const getOriginalAction = (settings: NodeEditorSettings): TransferAirtime => {
Expand Down
37 changes: 22 additions & 15 deletions src/components/flow/routers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
SwitchRouter,
TransferAirtime,
UIConfig,
WebhookExitNames,
ServiceCallExitNames,
CallClassifier,
OpenTicket
} from 'flowTypes';
Expand Down Expand Up @@ -330,24 +330,23 @@ export const resolveRoutes = (
return results;
};

export const createWebhookBasedNode = (
export const createServiceCallSplitNode = (
action: CallWebhook | CallResthook | OpenTicket | TransferAirtime,
originalNode: RenderNode,
useCategoryTest: boolean
useWebhookTest: boolean
): RenderNode => {
const exits: Exit[] = [];
let cases: Case[] = [];
let categories: Category[] = [];
let operand = '';

// see if we are editing an existing router so we reuse exits
if (
originalNode &&
originalNode.node.actions.length === 1 &&
originalNode.node.actions[0].type === action.type
) {
const previousRouter = getSwitchRouter(originalNode.node);
originalNode.node.exits.forEach((exit: any) => exits.push(exit));
previousRouter.cases.forEach(kase => cases.push(kase));
originalNode.node.exits.forEach((exit: Exit) => exits.push(exit));
originalNode.node.router.categories.forEach(category => categories.push(category));
} else {
// Otherwise, let's create some new ones
Expand All @@ -365,29 +364,37 @@ export const createWebhookBasedNode = (
categories = [
{
uuid: createUUID(),
name: WebhookExitNames.Success,
name: ServiceCallExitNames.Success,
exit_uuid: exits[0].uuid
},
{
uuid: createUUID(),
name: WebhookExitNames.Failure,
name: ServiceCallExitNames.Failure,
exit_uuid: exits[1].uuid
}
];
}

if (useWebhookTest) {
operand = '@webhook.status';
cases = [
{
uuid: createUUID(),
type: useCategoryTest ? Operators.has_category : Operators.has_only_text,
arguments: [WebhookExitNames.Success],
type: Operators.has_number_between,
arguments: ['200', '299'],
category_uuid: categories[0].uuid
}
];
} else {
operand = '@results.' + snakify(action.result_name);
cases = [
{
uuid: createUUID(),
type: Operators.has_category,
arguments: [ServiceCallExitNames.Success],
category_uuid: categories[0].uuid
}
];
}

let operand = '@results.' + snakify(action.result_name);
if (!useCategoryTest) {
operand += '.category';
}

const router: SwitchRouter = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ Array [
"cases": Array [
Object {
"arguments": Array [
"Success",
"200",
"299",
],
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
"type": "has_only_text",
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
"type": "has_number_between",
"uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
},
],
"categories": Array [
Expand All @@ -135,7 +136,7 @@ Array [
},
],
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
"operand": "@results.result.category",
"operand": "@webhook.status",
"type": "switch",
},
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
Expand All @@ -159,44 +160,45 @@ Array [
"resthook": "new-resthook",
"result_name": "Result",
"type": "call_resthook",
"uuid": "70ac6ea6-803a-4c33-81c7-dc26803c313f",
"uuid": "e0bc3776-792f-49d2-b4be-48be2cf8159a",
},
],
"exits": Array [
Object {
"destination_uuid": null,
"uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
"uuid": "6c22884b-0e35-4206-982e-18320691eda9",
},
Object {
"destination_uuid": null,
"uuid": "e0bc3776-792f-49d2-b4be-48be2cf8159a",
"uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
},
],
"router": Object {
"cases": Array [
Object {
"arguments": Array [
"Success",
"200",
"299",
],
"category_uuid": "6c22884b-0e35-4206-982e-18320691eda9",
"type": "has_only_text",
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
"category_uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
"type": "has_number_between",
"uuid": "6b59e863-2e14-442b-9987-aaa284871b8e",
},
],
"categories": Array [
Object {
"exit_uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
"exit_uuid": "6c22884b-0e35-4206-982e-18320691eda9",
"name": "Success",
"uuid": "6c22884b-0e35-4206-982e-18320691eda9",
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
},
Object {
"exit_uuid": "e0bc3776-792f-49d2-b4be-48be2cf8159a",
"exit_uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
"name": "Failure",
"uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
},
],
"default_category_uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
"operand": "@results.result.category",
"default_category_uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
"operand": "@webhook.status",
"type": "switch",
},
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
Expand Down Expand Up @@ -254,11 +256,12 @@ Array [
"cases": Array [
Object {
"arguments": Array [
"Success",
"200",
"299",
],
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
"type": "has_only_text",
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
"type": "has_number_between",
"uuid": "42ebf1d0-a43e-4ba6-9577-c863b20c88c4",
},
],
"categories": Array [
Expand All @@ -274,7 +277,7 @@ Array [
},
],
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
"operand": "@results.result.category",
"operand": "@webhook.status",
"type": "switch",
},
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
Expand Down
4 changes: 2 additions & 2 deletions src/components/flow/routers/resthook/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
import { Types } from 'config/interfaces';
import { CallResthook } from 'flowTypes';
import { RenderNode } from 'store/flowContext';
Expand Down Expand Up @@ -46,7 +46,7 @@ export const stateToNode = (
result_name: state.resultName.value
};

return createWebhookBasedNode(newAction, settings.originalNode, false);
return createServiceCallSplitNode(newAction, settings.originalNode, true);
};

export const getOriginalAction = (settings: NodeEditorSettings): CallResthook => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Array [
],
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
"type": "has_category",
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
"uuid": "42ebf1d0-a43e-4ba6-9577-c863b20c88c4",
},
],
"categories": Array [
Expand Down
4 changes: 2 additions & 2 deletions src/components/flow/routers/ticket/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
import { Types } from 'config/interfaces';
import { getType } from 'config/typeConfigs';
import { OpenTicket } from 'flowTypes';
Expand Down Expand Up @@ -64,5 +64,5 @@ export const stateToNode = (
result_name: state.resultName.value
};

return createWebhookBasedNode(newAction, settings.originalNode, true);
return createServiceCallSplitNode(newAction, settings.originalNode, false);
};
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ Object {
Object {
"value": Object {
"name": "Accept",
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
"value": "application/json",
},
},
Object {
"value": Object {
"name": "",
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
"uuid": "6b59e863-2e14-442b-9987-aaa284871b8e",
"value": "",
},
},
Expand Down Expand Up @@ -328,23 +328,23 @@ Object {
Object {
"value": Object {
"name": "Accept",
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
"value": "application/json",
},
},
Object {
"validationFailures": undefined,
"value": Object {
"name": "Content-Type",
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
"uuid": "6b59e863-2e14-442b-9987-aaa284871b8e",
"value": "application/json",
},
},
Object {
"validationFailures": undefined,
"value": Object {
"name": "",
"uuid": "00dd2423-0a34-4ee2-b97d-839fb2d593ef",
"uuid": "c5722340-f7e1-4d99-ac5e-3a6e59845111",
"value": "",
},
},
Expand Down Expand Up @@ -608,11 +608,12 @@ Array [
"cases": Array [
Object {
"arguments": Array [
"Success",
"200",
"299",
],
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
"type": "has_only_text",
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
"type": "has_number_between",
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
},
],
"categories": Array [
Expand All @@ -628,7 +629,7 @@ Array [
},
],
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
"operand": "@results.my_webhook_result.category",
"operand": "@webhook.status",
"type": "switch",
},
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
Expand Down
4 changes: 2 additions & 2 deletions src/components/flow/routers/webhook/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
import { WebhookRouterFormState } from 'components/flow/routers/webhook/WebhookRouterForm';
import { DEFAULT_BODY } from 'components/nodeeditor/constants';
import { Types } from 'config/interfaces';
Expand Down Expand Up @@ -133,7 +133,7 @@ export const stateToNode = (
result_name: state.resultName.value
};

return createWebhookBasedNode(newAction, settings.originalNode, false);
return createServiceCallSplitNode(newAction, settings.originalNode, true);
};

export const getDefaultBody = (method: string): string => {
Expand Down
7 changes: 1 addition & 6 deletions src/flowTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,11 @@ export enum StartFlowExitNames {
Expired = 'Expired'
}

export enum WebhookExitNames {
export enum ServiceCallExitNames {
Success = 'Success',
Failure = 'Failure'
}

export enum TransferAirtimeExitNames {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used

Success = 'Success',
Failure = 'Failed'
}

export enum DialCategoryNames {
Answered = 'Answered',
NoAnswer = 'No Answer',
Expand Down
8 changes: 4 additions & 4 deletions src/testUtils/assetCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
UINode,
Wait,
WaitTypes,
WebhookExitNames,
ServiceCallExitNames,
HintTypes,
CallClassifier,
ComposeAttachment
Expand Down Expand Up @@ -387,15 +387,15 @@ export const createWebhookNode = (
useCategoryTest: boolean
) => {
const { categories, exits } = createCategories([
WebhookExitNames.Success,
WebhookExitNames.Failure
ServiceCallExitNames.Success,
ServiceCallExitNames.Failure
]);

const cases: Case[] = [
{
uuid: utils.createUUID(),
type: useCategoryTest ? Operators.has_category : Operators.has_only_text,
arguments: [WebhookExitNames.Success],
arguments: [ServiceCallExitNames.Success],
category_uuid: categories[0].uuid
}
];
Expand Down