Skip to content

Commit

Permalink
feat(api): add chat control schema
Browse files Browse the repository at this point in the history
  • Loading branch information
djabarovgeorge committed Dec 9, 2024
1 parent 6ec90ed commit 82df6e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

import { JSONSchemaDto, UiComponentEnum, UiSchema, UiSchemaGroupEnum } from '@novu/shared';

export const ChatStepControlZodSchema = z
.object({
body: z.string(),
})
.strict();

export type ChatStepControlType = z.infer<typeof ChatStepControlZodSchema>;

export const chatStepControlSchema = zodToJsonSchema(ChatStepControlZodSchema) as JSONSchemaDto;
export const chatStepUiSchema: UiSchema = {
group: UiSchemaGroupEnum.CHAT,
properties: {
body: {
component: UiComponentEnum.CHAT_BODY,
},
},
};

export const chatStepControl = {
uiSchema: chatStepUiSchema,
schema: chatStepControlSchema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { emailStepControlSchema, emailStepUiSchema, inAppControlSchema, inAppUiS
import { DelayTimeControlSchema, delayUiSchema } from './schemas/delay-control.schema';
import { DigestOutputJsonSchema, digestUiSchema } from './schemas/digest-control.schema';
import { smsStepControl } from './schemas/sms-control.schema';
import { chatStepControl } from './schemas/chat-control.schema';

export const PERMISSIVE_EMPTY_SCHEMA = {
type: 'object',
Expand All @@ -29,7 +30,8 @@ export const stepTypeToControlSchema: Record<ChannelStepEnum | ActionStepEnum, C
schema: channelStepSchemas[ChannelStepEnum.PUSH].output as unknown as JSONSchemaDto,
},
[ChannelStepEnum.CHAT]: {
schema: channelStepSchemas[ChannelStepEnum.CHAT].output as unknown as JSONSchemaDto,
schema: chatStepControl.schema,
uiSchema: chatStepControl.uiSchema,
},
[ActionStepEnum.DELAY]: {
schema: DelayTimeControlSchema,
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/dto/workflows/step-data.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum UiSchemaGroupEnum {
DIGEST = 'DIGEST',
DELAY = 'DELAY',
SMS = 'SMS',
CHAT = 'CHAT',
}

export enum UiComponentEnum {
Expand All @@ -40,6 +41,7 @@ export enum UiComponentEnum {
DELAY_AMOUNT = 'DELAY_AMOUNT',
DELAY_UNIT = 'DELAY_UNIT',
SMS_BODY = 'SMS_BODY',
CHAT_BODY = 'CHAT_BODY',
}

export class UiSchemaProperty {
Expand Down

0 comments on commit 82df6e0

Please sign in to comment.