tyntec-sdk
Version:
TypeScript SDK for Tyntec Conversations API V3
64 lines (63 loc) • 2.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.templateMessageSchema = exports.templateComponentsSchema = exports.templateHeaderSchema = exports.templateButtonSchema = exports.templateComponentSchema = void 0;
const zod_1 = require("zod");
const base_schema_1 = require("./base.schema");
const documentContentSchema = zod_1.z.object({
url: zod_1.z.string().url(),
caption: zod_1.z.string().optional(),
filename: zod_1.z.string().optional(),
});
exports.templateComponentSchema = zod_1.z.object({
type: zod_1.z.literal('text'),
text: zod_1.z.string(),
});
// Template button schema with discriminated union
exports.templateButtonSchema = zod_1.z.discriminatedUnion('type', [
zod_1.z.object({
type: zod_1.z.literal('quick_reply'),
index: zod_1.z.number(),
payload: zod_1.z.string(),
}),
zod_1.z.object({
type: zod_1.z.literal('url'),
index: zod_1.z.number(),
text: zod_1.z.string(),
}),
]);
// Template header schema with discriminated union
exports.templateHeaderSchema = zod_1.z.discriminatedUnion('type', [
zod_1.z.object({
type: zod_1.z.literal('text'),
text: zod_1.z.string(),
}),
zod_1.z.object({
type: zod_1.z.literal('image'),
image: base_schema_1.mediaContentSchema,
}),
zod_1.z.object({
type: zod_1.z.literal('video'),
video: base_schema_1.mediaContentSchema,
}),
zod_1.z.object({
type: zod_1.z.literal('document'),
document: documentContentSchema,
}),
zod_1.z.object({
type: zod_1.z.literal('location'),
location: base_schema_1.locationContentSchema,
}),
]);
exports.templateComponentsSchema = zod_1.z.object({
header: zod_1.z.array(exports.templateHeaderSchema).optional(),
body: zod_1.z.array(exports.templateComponentSchema).optional(),
button: zod_1.z.array(exports.templateButtonSchema).optional(),
});
exports.templateMessageSchema = base_schema_1.whatsAppBaseFields.extend({
contentType: zod_1.z.literal('template'),
template: zod_1.z.object({
templateId: zod_1.z.string(),
templateLanguage: zod_1.z.string(),
components: exports.templateComponentsSchema,
}),
});