feat: zod quick reply

This commit is contained in:
abdou6666 2025-02-03 10:58:53 +01:00
parent b09f198da3
commit 22046d57e9

View File

@ -6,21 +6,10 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { AttachmentPayload } from './attachment'; import { z } from 'zod';
import { PayloadType } from './message';
export type Payload = import { attachmentPayloadSchema } from './attachment';
| { import { PayloadType } from './message';
type: PayloadType.location;
coordinates: {
lat: number;
lon: number;
};
}
| {
type: PayloadType.attachments;
attachment: AttachmentPayload;
};
export enum QuickReplyType { export enum QuickReplyType {
text = 'text', text = 'text',
@ -29,8 +18,28 @@ export enum QuickReplyType {
user_email = 'user_email', user_email = 'user_email',
} }
export interface StdQuickReply { export const cordinatesSchema = z.object({
content_type: QuickReplyType; lat: z.number(),
title: string; lon: z.number(),
payload: string; });
}
export const payloadSchema = z.discriminatedUnion('type', [
z.object({
type: z.literal(PayloadType.location),
coordinates: cordinatesSchema,
}),
z.object({
type: z.literal(PayloadType.attachments),
attachment: attachmentPayloadSchema,
}),
]);
export const stdQuickReplySchema = z.object({
content_type: z.nativeEnum(QuickReplyType),
title: z.string(),
payload: z.string(),
});
export type Payload = z.infer<typeof payloadSchema>;
export type StdQuickReply = z.infer<typeof stdQuickReplySchema>;