@hexabot-ai/types 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/LICENSE.md +120 -0
  2. package/README.md +172 -0
  3. package/dist/cjs/analytics/index.js +18 -0
  4. package/dist/cjs/analytics/integration-health.js +30 -0
  5. package/dist/cjs/analytics/stats.js +32 -0
  6. package/dist/cjs/attachment/attachment.js +53 -0
  7. package/dist/cjs/attachment/index.js +16 -0
  8. package/dist/cjs/audit/audit-log.js +33 -0
  9. package/dist/cjs/audit/index.js +11 -0
  10. package/dist/cjs/channel/channel-metadata.js +15 -0
  11. package/dist/cjs/channel/index.js +15 -0
  12. package/dist/cjs/channel/source-full.js +16 -0
  13. package/dist/cjs/channel/source.js +25 -0
  14. package/dist/cjs/chat/attachment.js +32 -0
  15. package/dist/cjs/chat/button.js +70 -0
  16. package/dist/cjs/chat/index.js +87 -0
  17. package/dist/cjs/chat/label-group.js +22 -0
  18. package/dist/cjs/chat/label.js +37 -0
  19. package/dist/cjs/chat/message-contract.js +183 -0
  20. package/dist/cjs/chat/message.js +107 -0
  21. package/dist/cjs/chat/options.js +122 -0
  22. package/dist/cjs/chat/quick-reply.js +35 -0
  23. package/dist/cjs/chat/subscriber.js +36 -0
  24. package/dist/cjs/chat/thread.js +36 -0
  25. package/dist/cjs/cms/content-type.js +17 -0
  26. package/dist/cjs/cms/content.js +29 -0
  27. package/dist/cjs/cms/index.js +21 -0
  28. package/dist/cjs/cms/menu.js +36 -0
  29. package/dist/cjs/dummy/dummy.js +18 -0
  30. package/dist/cjs/dummy/index.js +12 -0
  31. package/dist/cjs/i18n/index.js +16 -0
  32. package/dist/cjs/i18n/language.js +19 -0
  33. package/dist/cjs/i18n/translation.js +17 -0
  34. package/dist/cjs/index.js +32 -0
  35. package/dist/cjs/setting/index.js +18 -0
  36. package/dist/cjs/setting/metadata.js +17 -0
  37. package/dist/cjs/setting/setting.js +36 -0
  38. package/dist/cjs/shared/aliases.js +41 -0
  39. package/dist/cjs/shared/base.js +14 -0
  40. package/dist/cjs/shared/object.js +19 -0
  41. package/dist/cjs/shared/preprocess.js +13 -0
  42. package/dist/cjs/shared/profile.js +33 -0
  43. package/dist/cjs/user/credential.js +26 -0
  44. package/dist/cjs/user/domain.js +56 -0
  45. package/dist/cjs/user/index.js +39 -0
  46. package/dist/cjs/user/model.js +24 -0
  47. package/dist/cjs/user/permission.js +32 -0
  48. package/dist/cjs/user/role.js +24 -0
  49. package/dist/cjs/user/user-profile-assigned.js +38 -0
  50. package/dist/cjs/user/user-profile.js +12 -0
  51. package/dist/cjs/user/user.js +44 -0
  52. package/dist/cjs/workflow/domain.js +44 -0
  53. package/dist/cjs/workflow/helpers.js +35 -0
  54. package/dist/cjs/workflow/index.js +40 -0
  55. package/dist/cjs/workflow/mcp-server.js +33 -0
  56. package/dist/cjs/workflow/memory-definition.js +21 -0
  57. package/dist/cjs/workflow/memory-record.js +44 -0
  58. package/dist/cjs/workflow/workflow-run.js +100 -0
  59. package/dist/cjs/workflow/workflow-version.js +39 -0
  60. package/dist/cjs/workflow/workflow.js +98 -0
  61. package/dist/esm/analytics/index.js +7 -0
  62. package/dist/esm/analytics/integration-health.js +27 -0
  63. package/dist/esm/analytics/stats.js +29 -0
  64. package/dist/esm/attachment/attachment.js +50 -0
  65. package/dist/esm/attachment/index.js +6 -0
  66. package/dist/esm/audit/audit-log.js +30 -0
  67. package/dist/esm/audit/index.js +6 -0
  68. package/dist/esm/channel/channel-metadata.js +12 -0
  69. package/dist/esm/channel/index.js +8 -0
  70. package/dist/esm/channel/source-full.js +13 -0
  71. package/dist/esm/channel/source.js +22 -0
  72. package/dist/esm/chat/attachment.js +29 -0
  73. package/dist/esm/chat/button.js +67 -0
  74. package/dist/esm/chat/index.js +15 -0
  75. package/dist/esm/chat/label-group.js +19 -0
  76. package/dist/esm/chat/label.js +34 -0
  77. package/dist/esm/chat/message-contract.js +180 -0
  78. package/dist/esm/chat/message.js +104 -0
  79. package/dist/esm/chat/options.js +119 -0
  80. package/dist/esm/chat/quick-reply.js +32 -0
  81. package/dist/esm/chat/subscriber.js +33 -0
  82. package/dist/esm/chat/thread.js +33 -0
  83. package/dist/esm/cms/content-type.js +14 -0
  84. package/dist/esm/cms/content.js +26 -0
  85. package/dist/esm/cms/index.js +8 -0
  86. package/dist/esm/cms/menu.js +33 -0
  87. package/dist/esm/dummy/dummy.js +15 -0
  88. package/dist/esm/dummy/index.js +6 -0
  89. package/dist/esm/i18n/index.js +7 -0
  90. package/dist/esm/i18n/language.js +16 -0
  91. package/dist/esm/i18n/translation.js +14 -0
  92. package/dist/esm/index.js +16 -0
  93. package/dist/esm/setting/index.js +7 -0
  94. package/dist/esm/setting/metadata.js +14 -0
  95. package/dist/esm/setting/setting.js +33 -0
  96. package/dist/esm/shared/aliases.js +35 -0
  97. package/dist/esm/shared/base.js +11 -0
  98. package/dist/esm/shared/object.js +14 -0
  99. package/dist/esm/shared/preprocess.js +9 -0
  100. package/dist/esm/shared/profile.js +30 -0
  101. package/dist/esm/user/credential.js +23 -0
  102. package/dist/esm/user/domain.js +53 -0
  103. package/dist/esm/user/index.js +13 -0
  104. package/dist/esm/user/model.js +21 -0
  105. package/dist/esm/user/permission.js +29 -0
  106. package/dist/esm/user/role.js +21 -0
  107. package/dist/esm/user/user-profile-assigned.js +35 -0
  108. package/dist/esm/user/user-profile.js +9 -0
  109. package/dist/esm/user/user.js +41 -0
  110. package/dist/esm/workflow/domain.js +41 -0
  111. package/dist/esm/workflow/helpers.js +30 -0
  112. package/dist/esm/workflow/index.js +12 -0
  113. package/dist/esm/workflow/mcp-server.js +30 -0
  114. package/dist/esm/workflow/memory-definition.js +18 -0
  115. package/dist/esm/workflow/memory-record.js +41 -0
  116. package/dist/esm/workflow/workflow-run.js +96 -0
  117. package/dist/esm/workflow/workflow-version.js +36 -0
  118. package/dist/esm/workflow/workflow.js +94 -0
  119. package/dist/types/analytics/index.d.ts +3 -0
  120. package/dist/types/analytics/index.d.ts.map +1 -0
  121. package/dist/types/analytics/integration-health.d.ts +55 -0
  122. package/dist/types/analytics/integration-health.d.ts.map +1 -0
  123. package/dist/types/analytics/stats.d.ts +43 -0
  124. package/dist/types/analytics/stats.d.ts.map +1 -0
  125. package/dist/types/attachment/attachment.d.ts +212 -0
  126. package/dist/types/attachment/attachment.d.ts.map +1 -0
  127. package/dist/types/attachment/index.d.ts +2 -0
  128. package/dist/types/attachment/index.d.ts.map +1 -0
  129. package/dist/types/audit/audit-log.d.ts +58 -0
  130. package/dist/types/audit/audit-log.d.ts.map +1 -0
  131. package/dist/types/audit/index.d.ts +2 -0
  132. package/dist/types/audit/index.d.ts.map +1 -0
  133. package/dist/types/channel/channel-metadata.d.ts +7 -0
  134. package/dist/types/channel/channel-metadata.d.ts.map +1 -0
  135. package/dist/types/channel/index.d.ts +4 -0
  136. package/dist/types/channel/index.d.ts.map +1 -0
  137. package/dist/types/channel/source-full.d.ts +58 -0
  138. package/dist/types/channel/source-full.d.ts.map +1 -0
  139. package/dist/types/channel/source.d.ts +44 -0
  140. package/dist/types/channel/source.d.ts.map +1 -0
  141. package/dist/types/chat/attachment.d.ts +34 -0
  142. package/dist/types/chat/attachment.d.ts.map +1 -0
  143. package/dist/types/chat/button.d.ts +31 -0
  144. package/dist/types/chat/button.d.ts.map +1 -0
  145. package/dist/types/chat/index.d.ts +11 -0
  146. package/dist/types/chat/index.d.ts.map +1 -0
  147. package/dist/types/chat/label-group.d.ts +47 -0
  148. package/dist/types/chat/label-group.d.ts.map +1 -0
  149. package/dist/types/chat/label.d.ts +102 -0
  150. package/dist/types/chat/label.d.ts.map +1 -0
  151. package/dist/types/chat/message-contract.d.ts +883 -0
  152. package/dist/types/chat/message-contract.d.ts.map +1 -0
  153. package/dist/types/chat/message.d.ts +1132 -0
  154. package/dist/types/chat/message.d.ts.map +1 -0
  155. package/dist/types/chat/options.d.ts +64 -0
  156. package/dist/types/chat/options.d.ts.map +1 -0
  157. package/dist/types/chat/quick-reply.d.ts +32 -0
  158. package/dist/types/chat/quick-reply.d.ts.map +1 -0
  159. package/dist/types/chat/subscriber.d.ts +236 -0
  160. package/dist/types/chat/subscriber.d.ts.map +1 -0
  161. package/dist/types/chat/thread.d.ts +126 -0
  162. package/dist/types/chat/thread.d.ts.map +1 -0
  163. package/dist/types/cms/content-type.d.ts +26 -0
  164. package/dist/types/cms/content-type.d.ts.map +1 -0
  165. package/dist/types/cms/content.d.ts +49 -0
  166. package/dist/types/cms/content.d.ts.map +1 -0
  167. package/dist/types/cms/index.d.ts +4 -0
  168. package/dist/types/cms/index.d.ts.map +1 -0
  169. package/dist/types/cms/menu.d.ts +85 -0
  170. package/dist/types/cms/menu.d.ts.map +1 -0
  171. package/dist/types/dummy/dummy.d.ts +26 -0
  172. package/dist/types/dummy/dummy.d.ts.map +1 -0
  173. package/dist/types/dummy/index.d.ts +2 -0
  174. package/dist/types/dummy/index.d.ts.map +1 -0
  175. package/dist/types/i18n/index.d.ts +3 -0
  176. package/dist/types/i18n/index.d.ts.map +1 -0
  177. package/dist/types/i18n/language.d.ts +32 -0
  178. package/dist/types/i18n/language.d.ts.map +1 -0
  179. package/dist/types/i18n/translation.d.ts +26 -0
  180. package/dist/types/i18n/translation.d.ts.map +1 -0
  181. package/dist/types/index.d.ts +12 -0
  182. package/dist/types/index.d.ts.map +1 -0
  183. package/dist/types/setting/index.d.ts +3 -0
  184. package/dist/types/setting/index.d.ts.map +1 -0
  185. package/dist/types/setting/metadata.d.ts +26 -0
  186. package/dist/types/setting/metadata.d.ts.map +1 -0
  187. package/dist/types/setting/setting.d.ts +41 -0
  188. package/dist/types/setting/setting.d.ts.map +1 -0
  189. package/dist/types/shared/aliases.d.ts +4 -0
  190. package/dist/types/shared/aliases.d.ts.map +1 -0
  191. package/dist/types/shared/base.d.ts +7 -0
  192. package/dist/types/shared/base.d.ts.map +1 -0
  193. package/dist/types/shared/object.d.ts +3 -0
  194. package/dist/types/shared/object.d.ts.map +1 -0
  195. package/dist/types/shared/preprocess.d.ts +3 -0
  196. package/dist/types/shared/preprocess.d.ts.map +1 -0
  197. package/dist/types/shared/profile.d.ts +40 -0
  198. package/dist/types/shared/profile.d.ts.map +1 -0
  199. package/dist/types/user/credential.d.ts +97 -0
  200. package/dist/types/user/credential.d.ts.map +1 -0
  201. package/dist/types/user/domain.d.ts +54 -0
  202. package/dist/types/user/domain.d.ts.map +1 -0
  203. package/dist/types/user/index.d.ts +9 -0
  204. package/dist/types/user/index.d.ts.map +1 -0
  205. package/dist/types/user/model.d.ts +142 -0
  206. package/dist/types/user/model.d.ts.map +1 -0
  207. package/dist/types/user/permission.d.ts +90 -0
  208. package/dist/types/user/permission.d.ts.map +1 -0
  209. package/dist/types/user/role.d.ts +111 -0
  210. package/dist/types/user/role.d.ts.map +1 -0
  211. package/dist/types/user/user-profile-assigned.d.ts +181 -0
  212. package/dist/types/user/user-profile-assigned.d.ts.map +1 -0
  213. package/dist/types/user/user-profile.d.ts +32 -0
  214. package/dist/types/user/user-profile.d.ts.map +1 -0
  215. package/dist/types/user/user.d.ts +270 -0
  216. package/dist/types/user/user.d.ts.map +1 -0
  217. package/dist/types/workflow/domain.d.ts +32 -0
  218. package/dist/types/workflow/domain.d.ts.map +1 -0
  219. package/dist/types/workflow/helpers.d.ts +117 -0
  220. package/dist/types/workflow/helpers.d.ts.map +1 -0
  221. package/dist/types/workflow/index.d.ts +8 -0
  222. package/dist/types/workflow/index.d.ts.map +1 -0
  223. package/dist/types/workflow/mcp-server.d.ts +67 -0
  224. package/dist/types/workflow/mcp-server.d.ts.map +1 -0
  225. package/dist/types/workflow/memory-definition.d.ts +35 -0
  226. package/dist/types/workflow/memory-definition.d.ts.map +1 -0
  227. package/dist/types/workflow/memory-record.d.ts +284 -0
  228. package/dist/types/workflow/memory-record.d.ts.map +1 -0
  229. package/dist/types/workflow/workflow-run.d.ts +375 -0
  230. package/dist/types/workflow/workflow-run.d.ts.map +1 -0
  231. package/dist/types/workflow/workflow-version.d.ts +179 -0
  232. package/dist/types/workflow/workflow-version.d.ts.map +1 -0
  233. package/dist/types/workflow/workflow.d.ts +366 -0
  234. package/dist/types/workflow/workflow.d.ts.map +1 -0
  235. package/package.json +59 -0
  236. package/src/analytics/index.ts +26 -0
  237. package/src/analytics/integration-health.ts +44 -0
  238. package/src/analytics/stats.ts +41 -0
  239. package/src/attachment/attachment.ts +75 -0
  240. package/src/attachment/index.ts +19 -0
  241. package/src/audit/audit-log.ts +42 -0
  242. package/src/audit/index.ts +12 -0
  243. package/src/channel/channel-metadata.ts +20 -0
  244. package/src/channel/index.ts +19 -0
  245. package/src/channel/source-full.ts +25 -0
  246. package/src/channel/source.ts +42 -0
  247. package/src/chat/attachment.ts +44 -0
  248. package/src/chat/button.ts +90 -0
  249. package/src/chat/index.ts +173 -0
  250. package/src/chat/label-group.ts +35 -0
  251. package/src/chat/label.ts +56 -0
  252. package/src/chat/message-contract.ts +370 -0
  253. package/src/chat/message.ts +164 -0
  254. package/src/chat/options.ts +130 -0
  255. package/src/chat/quick-reply.ts +41 -0
  256. package/src/chat/subscriber.ts +73 -0
  257. package/src/chat/thread.ts +55 -0
  258. package/src/cms/content-type.ts +26 -0
  259. package/src/cms/content.ts +48 -0
  260. package/src/cms/index.ts +33 -0
  261. package/src/cms/menu.ts +54 -0
  262. package/src/dummy/dummy.ts +30 -0
  263. package/src/dummy/index.ts +14 -0
  264. package/src/i18n/index.ts +23 -0
  265. package/src/i18n/language.ts +28 -0
  266. package/src/i18n/translation.ts +26 -0
  267. package/src/index.test.ts +1271 -0
  268. package/src/index.ts +27 -0
  269. package/src/setting/index.ts +25 -0
  270. package/src/setting/metadata.ts +26 -0
  271. package/src/setting/setting.ts +46 -0
  272. package/src/shared/aliases.ts +48 -0
  273. package/src/shared/base.ts +13 -0
  274. package/src/shared/object.ts +19 -0
  275. package/src/shared/preprocess.ts +14 -0
  276. package/src/shared/profile.ts +49 -0
  277. package/src/user/credential.ts +45 -0
  278. package/src/user/domain.ts +94 -0
  279. package/src/user/index.ts +78 -0
  280. package/src/user/model.ts +40 -0
  281. package/src/user/permission.ts +51 -0
  282. package/src/user/role.ts +43 -0
  283. package/src/user/user-profile-assigned.ts +70 -0
  284. package/src/user/user-profile.ts +21 -0
  285. package/src/user/user.ts +87 -0
  286. package/src/workflow/domain.ts +47 -0
  287. package/src/workflow/helpers.ts +40 -0
  288. package/src/workflow/index.ts +70 -0
  289. package/src/workflow/mcp-server.ts +64 -0
  290. package/src/workflow/memory-definition.ts +31 -0
  291. package/src/workflow/memory-record.ts +71 -0
  292. package/src/workflow/workflow-run.ts +156 -0
  293. package/src/workflow/workflow-version.ts +68 -0
  294. package/src/workflow/workflow.ts +163 -0
@@ -0,0 +1,370 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+
7
+ import { z } from "zod";
8
+
9
+ import type { Attachment } from "../attachment/attachment";
10
+
11
+ import { attachmentPayloadSchema } from "./attachment";
12
+ import { PayloadType, buttonSchema } from "./button";
13
+ import type { Message as EntityMessage } from "./message";
14
+ import { contentOptionsSchema } from "./options";
15
+ import { stdQuickReplySchema } from "./quick-reply";
16
+
17
+ export enum StdEventType {
18
+ message = "message",
19
+ delivery = "delivery",
20
+ read = "read",
21
+ typing = "typing",
22
+ follow = "follow",
23
+ echo = "echo",
24
+ error = "error",
25
+ unknown = "",
26
+ }
27
+
28
+ export enum IncomingMessageType {
29
+ text = "text",
30
+ postback = "postback",
31
+ quickReply = "quickReply",
32
+ location = "location",
33
+ attachment = "attachment",
34
+ unknown = "",
35
+ }
36
+
37
+ export const incomingMessageType = z.enum(IncomingMessageType);
38
+
39
+ export type IncomingMessageTypeLiteral = z.infer<typeof incomingMessageType>;
40
+
41
+ export enum OutgoingMessageType {
42
+ text = "text",
43
+ quickReply = "quickReply",
44
+ buttons = "buttons",
45
+ attachment = "attachment",
46
+ list = "list",
47
+ carousel = "carousel",
48
+ system = "system",
49
+ }
50
+
51
+ export const outgoingMessageTypeSchema = z.enum(OutgoingMessageType);
52
+
53
+ export type OutgoingMessageTypeLiteral = z.infer<
54
+ typeof outgoingMessageTypeSchema
55
+ >;
56
+
57
+ export const payloadTypeSchema = z.enum(PayloadType);
58
+
59
+ export type PayloadTypeLiteral = z.infer<typeof payloadTypeSchema>;
60
+
61
+ export const stdOutgoingTextMessageDataSchema = z.object({
62
+ text: z.string(),
63
+ });
64
+
65
+ export type StdOutgoingTextMessageData = z.infer<
66
+ typeof stdOutgoingTextMessageDataSchema
67
+ >;
68
+
69
+ export const stdOutgoingQuickRepliesMessageDataSchema = z.object({
70
+ text: z.string(),
71
+ quickReplies: z.array(stdQuickReplySchema),
72
+ });
73
+
74
+ export type StdOutgoingQuickRepliesMessageData = z.infer<
75
+ typeof stdOutgoingQuickRepliesMessageDataSchema
76
+ >;
77
+
78
+ export const stdOutgoingButtonsMessageDataSchema = z.object({
79
+ text: z.string(),
80
+ buttons: z.array(buttonSchema),
81
+ });
82
+
83
+ export type StdOutgoingButtonsMessageData = z.infer<
84
+ typeof stdOutgoingButtonsMessageDataSchema
85
+ >;
86
+
87
+ export const contentElementSchema = z
88
+ .object({
89
+ id: z.string(),
90
+ title: z.string(),
91
+ })
92
+ .catchall(z.any());
93
+
94
+ export type ContentElement = z.infer<typeof contentElementSchema>;
95
+
96
+ export const contentPaginationSchema = z.object({
97
+ total: z.number(),
98
+ skip: z.number(),
99
+ limit: z.number(),
100
+ });
101
+
102
+ export type ContentPagination = z.infer<typeof contentPaginationSchema>;
103
+
104
+ export const stdOutgoingListMessageDataSchema = z.object({
105
+ options: contentOptionsSchema,
106
+ elements: z.array(contentElementSchema),
107
+ pagination: contentPaginationSchema,
108
+ });
109
+
110
+ export type StdOutgoingListMessageData = z.infer<
111
+ typeof stdOutgoingListMessageDataSchema
112
+ >;
113
+
114
+ export interface OutgoingPopulatedListMessage {
115
+ title: string;
116
+ subtitle: string | null;
117
+ image_url?: { payload: Attachment; type: string } | null;
118
+ url?: string;
119
+ action_title?: string;
120
+ action_payload?: string;
121
+ }
122
+
123
+ export const stdOutgoingAttachmentMessageDataSchema = z.object({
124
+ attachment: attachmentPayloadSchema,
125
+ quickReplies: z.array(stdQuickReplySchema).optional(),
126
+ });
127
+
128
+ export type StdOutgoingAttachmentMessageData = z.infer<
129
+ typeof stdOutgoingAttachmentMessageDataSchema
130
+ >;
131
+
132
+ export const stdOutgoingSystemMessageDataSchema = z.object({
133
+ outcome: z.string().optional(),
134
+ data: z.any().optional(),
135
+ });
136
+
137
+ export type StdOutgoingSystemMessageData = z.infer<
138
+ typeof stdOutgoingSystemMessageDataSchema
139
+ >;
140
+
141
+ export const stdOutgoingTextMessageSchema = z.object({
142
+ type: z.literal(OutgoingMessageType.text),
143
+ data: stdOutgoingTextMessageDataSchema,
144
+ });
145
+
146
+ export type StdOutgoingTextMessage = z.infer<
147
+ typeof stdOutgoingTextMessageSchema
148
+ >;
149
+
150
+ export const stdOutgoingQuickRepliesMessageSchema = z.object({
151
+ type: z.literal(OutgoingMessageType.quickReply),
152
+ data: stdOutgoingQuickRepliesMessageDataSchema,
153
+ });
154
+
155
+ export type StdOutgoingQuickRepliesMessage = z.infer<
156
+ typeof stdOutgoingQuickRepliesMessageSchema
157
+ >;
158
+
159
+ export const stdOutgoingButtonsMessageSchema = z.object({
160
+ type: z.literal(OutgoingMessageType.buttons),
161
+ data: stdOutgoingButtonsMessageDataSchema,
162
+ });
163
+
164
+ export type StdOutgoingButtonsMessage = z.infer<
165
+ typeof stdOutgoingButtonsMessageSchema
166
+ >;
167
+
168
+ export const stdOutgoingListMessageSchema = z.object({
169
+ type: z.literal(OutgoingMessageType.list),
170
+ data: stdOutgoingListMessageDataSchema,
171
+ });
172
+
173
+ export type StdOutgoingListMessage = z.infer<
174
+ typeof stdOutgoingListMessageSchema
175
+ >;
176
+
177
+ export const stdOutgoingCarouselMessageSchema = z.object({
178
+ type: z.literal(OutgoingMessageType.carousel),
179
+ data: stdOutgoingListMessageDataSchema,
180
+ });
181
+
182
+ export type StdOutgoingCarouselMessage = z.infer<
183
+ typeof stdOutgoingCarouselMessageSchema
184
+ >;
185
+
186
+ export const stdOutgoingAttachmentMessageSchema = z.object({
187
+ type: z.literal(OutgoingMessageType.attachment),
188
+ data: stdOutgoingAttachmentMessageDataSchema,
189
+ });
190
+
191
+ export type StdOutgoingAttachmentMessage = z.infer<
192
+ typeof stdOutgoingAttachmentMessageSchema
193
+ >;
194
+
195
+ export const stdOutgoingMessageSchema = z.discriminatedUnion("type", [
196
+ stdOutgoingTextMessageSchema,
197
+ stdOutgoingQuickRepliesMessageSchema,
198
+ stdOutgoingButtonsMessageSchema,
199
+ stdOutgoingListMessageSchema,
200
+ stdOutgoingCarouselMessageSchema,
201
+ stdOutgoingAttachmentMessageSchema,
202
+ ]);
203
+
204
+ export type StdOutgoingMessage = z.infer<typeof stdOutgoingMessageSchema>;
205
+
206
+ export const stdIncomingTextMessageDataSchema = z.object({
207
+ text: z.string(),
208
+ });
209
+
210
+ export type StdIncomingTextMessageData = z.infer<
211
+ typeof stdIncomingTextMessageDataSchema
212
+ >;
213
+
214
+ export const stdIncomingPayloadMessageDataSchema = z.object({
215
+ text: z.string(),
216
+ payload: z.string(),
217
+ });
218
+
219
+ export type StdIncomingPayloadMessageData = z.infer<
220
+ typeof stdIncomingPayloadMessageDataSchema
221
+ >;
222
+
223
+ export const stdIncomingLocationMessageDataSchema = z.object({
224
+ coordinates: z.object({
225
+ lat: z.number(),
226
+ lon: z.number(),
227
+ }),
228
+ });
229
+
230
+ export type StdIncomingLocationMessageData = z.infer<
231
+ typeof stdIncomingLocationMessageDataSchema
232
+ >;
233
+
234
+ export const stdIncomingAttachmentMessageDataSchema = z.object({
235
+ serializedText: z.string(),
236
+ attachment: z.union([
237
+ attachmentPayloadSchema,
238
+ z.array(attachmentPayloadSchema),
239
+ ]),
240
+ });
241
+
242
+ export type StdIncomingAttachmentMessageData = z.infer<
243
+ typeof stdIncomingAttachmentMessageDataSchema
244
+ >;
245
+
246
+ export const stdIncomingTextMessageSchema = z.object({
247
+ type: z.literal(IncomingMessageType.text),
248
+ data: stdIncomingTextMessageDataSchema,
249
+ });
250
+
251
+ export type StdIncomingTextMessage = z.infer<
252
+ typeof stdIncomingTextMessageSchema
253
+ >;
254
+
255
+ export const stdIncomingPostBackMessageSchema = z.object({
256
+ type: z.literal(IncomingMessageType.postback),
257
+ data: stdIncomingPayloadMessageDataSchema,
258
+ });
259
+
260
+ export type StdIncomingPostBackMessage = z.infer<
261
+ typeof stdIncomingPostBackMessageSchema
262
+ >;
263
+
264
+ export const stdIncomingQuickReplyMessageSchema = z.object({
265
+ type: z.literal(IncomingMessageType.quickReply),
266
+ data: stdIncomingPayloadMessageDataSchema,
267
+ });
268
+
269
+ export type StdIncomingQuickReplyMessage = z.infer<
270
+ typeof stdIncomingQuickReplyMessageSchema
271
+ >;
272
+
273
+ export const stdIncomingLocationMessageSchema = z.object({
274
+ type: z.literal(IncomingMessageType.location),
275
+ data: stdIncomingLocationMessageDataSchema,
276
+ });
277
+
278
+ export type StdIncomingLocationMessage = z.infer<
279
+ typeof stdIncomingLocationMessageSchema
280
+ >;
281
+
282
+ export const stdIncomingAttachmentMessageSchema = z.object({
283
+ type: z.literal(IncomingMessageType.attachment),
284
+ data: stdIncomingAttachmentMessageDataSchema,
285
+ });
286
+
287
+ export type StdIncomingAttachmentMessage = z.infer<
288
+ typeof stdIncomingAttachmentMessageSchema
289
+ >;
290
+
291
+ export const stdIncomingMessageSchema = z.discriminatedUnion("type", [
292
+ stdIncomingTextMessageSchema,
293
+ stdIncomingPostBackMessageSchema,
294
+ stdIncomingQuickReplyMessageSchema,
295
+ stdIncomingLocationMessageSchema,
296
+ stdIncomingAttachmentMessageSchema,
297
+ ]);
298
+
299
+ export type StdIncomingMessage = z.infer<typeof stdIncomingMessageSchema>;
300
+
301
+ export interface IncomingMessage
302
+ extends Omit<EntityMessage, "recipient" | "sentBy"> {
303
+ message: StdIncomingMessage;
304
+ sender: string;
305
+ }
306
+
307
+ export interface OutgoingMessage extends Omit<EntityMessage, "sender"> {
308
+ message: StdOutgoingMessage;
309
+ recipient: string;
310
+ sentBy?: string;
311
+ handover: boolean;
312
+ }
313
+
314
+ export type AnyMessage = IncomingMessage | OutgoingMessage;
315
+
316
+ export const stdOutgoingTextEnvelopeSchema = stdOutgoingTextMessageSchema;
317
+
318
+ export type StdOutgoingTextEnvelope = StdOutgoingTextMessage;
319
+
320
+ export const stdOutgoingQuickRepliesEnvelopeSchema =
321
+ stdOutgoingQuickRepliesMessageSchema;
322
+
323
+ export type StdOutgoingQuickRepliesEnvelope = StdOutgoingQuickRepliesMessage;
324
+
325
+ export const stdOutgoingButtonsEnvelopeSchema = stdOutgoingButtonsMessageSchema;
326
+
327
+ export type StdOutgoingButtonsEnvelope = StdOutgoingButtonsMessage;
328
+
329
+ export const stdOutgoingListEnvelopeSchema = z.discriminatedUnion("type", [
330
+ stdOutgoingListMessageSchema,
331
+ stdOutgoingCarouselMessageSchema,
332
+ ]);
333
+
334
+ export type StdOutgoingListEnvelope = z.infer<
335
+ typeof stdOutgoingListEnvelopeSchema
336
+ >;
337
+
338
+ export const stdOutgoingAttachmentEnvelopeSchema =
339
+ stdOutgoingAttachmentMessageSchema;
340
+
341
+ export type StdOutgoingAttachmentEnvelope = StdOutgoingAttachmentMessage;
342
+
343
+ export const stdOutgoingSystemMessageSchema = z.object({
344
+ type: z.literal(OutgoingMessageType.system),
345
+ data: stdOutgoingSystemMessageDataSchema,
346
+ });
347
+
348
+ export type StdOutgoingSystemMessage = z.infer<
349
+ typeof stdOutgoingSystemMessageSchema
350
+ >;
351
+
352
+ export const stdOutgoingSystemEnvelopeSchema = stdOutgoingSystemMessageSchema;
353
+
354
+ export type StdOutgoingSystemEnvelope = StdOutgoingSystemMessage;
355
+
356
+ export const stdOutgoingMessageEnvelopeSchema = stdOutgoingMessageSchema;
357
+
358
+ export type StdOutgoingMessageEnvelope = StdOutgoingMessage;
359
+
360
+ export const stdOutgoingEnvelopeSchema = z.discriminatedUnion("type", [
361
+ stdOutgoingTextMessageSchema,
362
+ stdOutgoingQuickRepliesMessageSchema,
363
+ stdOutgoingButtonsMessageSchema,
364
+ stdOutgoingListMessageSchema,
365
+ stdOutgoingCarouselMessageSchema,
366
+ stdOutgoingAttachmentMessageSchema,
367
+ stdOutgoingSystemMessageSchema,
368
+ ]);
369
+
370
+ export type StdOutgoingEnvelope = z.infer<typeof stdOutgoingEnvelopeSchema>;
@@ -0,0 +1,164 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+
7
+ import { z } from "zod";
8
+
9
+ import { asId, withAliases } from "../shared/aliases";
10
+ import { baseStubSchema } from "../shared/base";
11
+ import { preprocess } from "../shared/preprocess";
12
+ import { userSchema } from "../user/user";
13
+
14
+ import {
15
+ IncomingMessageType,
16
+ OutgoingMessageType,
17
+ stdOutgoingMessageSchema,
18
+ stdIncomingMessageSchema,
19
+ type StdIncomingMessage,
20
+ type StdOutgoingMessage,
21
+ } from "./message-contract";
22
+ import { subscriberSchema } from "./subscriber";
23
+ import { threadSchema } from "./thread";
24
+
25
+ const messageAliasMap = {
26
+ senderId: "sender",
27
+ recipientId: "recipient",
28
+ sentById: "sentBy",
29
+ threadId: "thread",
30
+ } as const;
31
+ const incomingOnlyTypes = new Set<IncomingMessageType>([
32
+ IncomingMessageType.postback,
33
+ IncomingMessageType.location,
34
+ ]);
35
+ const outgoingOnlyTypes = new Set<OutgoingMessageType>([
36
+ OutgoingMessageType.buttons,
37
+ OutgoingMessageType.list,
38
+ OutgoingMessageType.carousel,
39
+ OutgoingMessageType.system,
40
+ ]);
41
+ const invalidDirectionMessage = {
42
+ type: "__invalidDirection__",
43
+ data: null,
44
+ };
45
+ const parseByDirection = (
46
+ message: unknown,
47
+ record: Record<string, unknown>,
48
+ ): unknown => {
49
+ const hasSender = record.sender != null;
50
+ const hasRecipient = record.recipient != null;
51
+ const hasSentBy = record.sentBy != null;
52
+ const shouldUseOutgoingSchema = hasRecipient || hasSentBy;
53
+ const shouldUseIncomingSchema = hasSender && !shouldUseOutgoingSchema;
54
+
55
+ if (shouldUseOutgoingSchema) {
56
+ const parsed = stdOutgoingMessageSchema.safeParse(message);
57
+
58
+ return parsed.success ? parsed.data : invalidDirectionMessage;
59
+ }
60
+
61
+ if (shouldUseIncomingSchema) {
62
+ const parsed = stdIncomingMessageSchema.safeParse(message);
63
+
64
+ return parsed.success ? parsed.data : invalidDirectionMessage;
65
+ }
66
+
67
+ const type =
68
+ typeof message === "object" && message !== null
69
+ ? (message as Record<string, unknown>).type
70
+ : undefined;
71
+
72
+ if (typeof type !== "string") {
73
+ const parsed = messagePayloadSchema.safeParse(message);
74
+
75
+ return parsed.success ? parsed.data : message;
76
+ }
77
+
78
+ if (incomingOnlyTypes.has(type as IncomingMessageType)) {
79
+ const parsed = stdIncomingMessageSchema.safeParse(message);
80
+
81
+ return parsed.success ? parsed.data : message;
82
+ }
83
+
84
+ if (outgoingOnlyTypes.has(type as OutgoingMessageType)) {
85
+ const parsed = stdOutgoingMessageSchema.safeParse(message);
86
+
87
+ return parsed.success ? parsed.data : message;
88
+ }
89
+
90
+ const parsed = messagePayloadSchema.safeParse(message);
91
+
92
+ return parsed.success ? parsed.data : message;
93
+ };
94
+ const normalizeMessageRecord = (value: unknown): unknown => {
95
+ const normalized = withAliases(value, messageAliasMap);
96
+ if (
97
+ typeof normalized !== "object" ||
98
+ normalized === null ||
99
+ !("message" in normalized)
100
+ ) {
101
+ return normalized;
102
+ }
103
+
104
+ const record = normalized as Record<string, unknown>;
105
+ record.message = parseByDirection(record.message, record);
106
+
107
+ return record;
108
+ };
109
+ const messagePayloadSchema = z.union([
110
+ stdIncomingMessageSchema,
111
+ stdOutgoingMessageSchema,
112
+ ]) as z.ZodType<StdIncomingMessage | StdOutgoingMessage>;
113
+ const messageStubObjectSchema = baseStubSchema.extend({
114
+ mid: z.string().optional(),
115
+ message: messagePayloadSchema,
116
+ read: z.coerce.boolean(),
117
+ delivery: z.coerce.boolean(),
118
+ handover: z.coerce.boolean(),
119
+ });
120
+
121
+ export const messageStubSchema = messageStubObjectSchema;
122
+
123
+ export const messageSchema = preprocess(
124
+ normalizeMessageRecord,
125
+ messageStubObjectSchema.extend({
126
+ sender: preprocess(
127
+ (value) => (value == null ? null : asId(value)),
128
+ z.string().nullable(),
129
+ ).optional(),
130
+ recipient: preprocess(
131
+ (value) => (value == null ? null : asId(value)),
132
+ z.string().nullable(),
133
+ ).optional(),
134
+ sentBy: preprocess(
135
+ (value) => (value == null ? null : asId(value)),
136
+ z.string().nullable(),
137
+ ).optional(),
138
+ thread: preprocess(
139
+ (value) => (value == null ? null : asId(value)),
140
+ z.string(),
141
+ ),
142
+ }),
143
+ );
144
+
145
+ const messageFullObjectSchema = messageStubObjectSchema.extend({
146
+ sender: subscriberSchema.nullable().optional(),
147
+ recipient: subscriberSchema.nullable().optional(),
148
+ sentBy: z
149
+ .lazy(() => userSchema)
150
+ .nullable()
151
+ .optional(),
152
+ thread: threadSchema,
153
+ });
154
+
155
+ export const messageFullSchema = preprocess(
156
+ normalizeMessageRecord,
157
+ messageFullObjectSchema,
158
+ );
159
+
160
+ export type MessageStub = z.infer<typeof messageStubSchema>;
161
+
162
+ export type Message = z.infer<typeof messageSchema>;
163
+
164
+ export type MessageFull = z.infer<typeof messageFullSchema>;
@@ -0,0 +1,130 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+
7
+ import { z } from "zod";
8
+
9
+ import { buttonSchema } from "./button";
10
+
11
+ export const contentOptionsSchema = z.object({
12
+ display: z.enum(["list", "carousel"]).meta({
13
+ title: "Display",
14
+ }),
15
+ contentType: z
16
+ .string()
17
+ .optional()
18
+ .meta({
19
+ title: "Content Type",
20
+ "ui:widget": "AutoCompleteWidget",
21
+ "ui:options": {
22
+ entity: "ContentType",
23
+ valueKey: "id",
24
+ labelKey: "name",
25
+ },
26
+ }),
27
+ fields: z
28
+ .object({
29
+ title: z.string().meta({
30
+ title: "Title",
31
+ "ui:field": "AutoCompleteField",
32
+ "ui:options": {
33
+ entity: "ContentType",
34
+ idFormPath: "content.contentType",
35
+ nestedArrayField: "schema.properties",
36
+ nestedArrayItemField: "type",
37
+ nestedArrayItemValue: "string",
38
+ },
39
+ }),
40
+ subtitle: z
41
+ .string()
42
+ .optional()
43
+ .meta({
44
+ title: "Subtitle",
45
+ "ui:field": "AutoCompleteField",
46
+ "ui:options": {
47
+ entity: "ContentType",
48
+ idFormPath: "content.contentType",
49
+ nestedArrayField: "schema.properties",
50
+ nestedArrayItemField: "type",
51
+ nestedArrayItemValue: "string",
52
+ },
53
+ }),
54
+ image_url: z
55
+ .string()
56
+ .optional()
57
+ .meta({
58
+ title: "Image URL Field",
59
+ "ui:field": "AutoCompleteField",
60
+ "ui:options": {
61
+ entity: "ContentType",
62
+ idFormPath: "content.contentType",
63
+ nestedArrayField: "schema.properties",
64
+ nestedArrayItemField: "type",
65
+ nestedArrayItemValue: "file",
66
+ },
67
+ }),
68
+ url: z
69
+ .string()
70
+ .optional()
71
+ .meta({
72
+ title: "URL",
73
+ "ui:field": "AutoCompleteField",
74
+ "ui:options": {
75
+ showOnlyWhenWebUrlButton: true,
76
+ entity: "ContentType",
77
+ valueKey: "name",
78
+ idFormPath: "content.contentType",
79
+ nestedArrayField: "schema.properties",
80
+ nestedArrayItemField: "type",
81
+ nestedArrayItemValue: "uri",
82
+ },
83
+ }),
84
+ action_title: z
85
+ .string()
86
+ .optional()
87
+ .meta({
88
+ title: "Action Title",
89
+ "ui:options": {
90
+ showOnlyWhenPostbackButton: true,
91
+ },
92
+ }),
93
+ action_payload: z
94
+ .string()
95
+ .optional()
96
+ .meta({
97
+ title: "Action Payload",
98
+ "ui:options": {
99
+ showOnlyWhenPostbackButton: true,
100
+ },
101
+ }),
102
+ })
103
+ .meta({ title: "Fields" }),
104
+ buttons: z.array(buttonSchema).meta({ title: "Buttons" }),
105
+ limit: z.number().finite(),
106
+ query: z.any().optional(),
107
+ top_element_style: z.enum(["large", "compact"]).optional().meta({
108
+ title: "Top Element Style",
109
+ }),
110
+ });
111
+
112
+ export type ContentOptions = z.infer<typeof contentOptionsSchema>;
113
+
114
+ export const fallbackOptionsSchema = z.object({
115
+ active: z.boolean(),
116
+ message: z.array(z.string()),
117
+ max_attempts: z.number().finite(),
118
+ });
119
+
120
+ export type FallbackOptions = z.infer<typeof fallbackOptionsSchema>;
121
+
122
+ export const ActionOptionsSchema = z.object({
123
+ typing: z.union([z.boolean(), z.int().nonnegative()]).optional(),
124
+ content: contentOptionsSchema.optional(),
125
+ fallback: fallbackOptionsSchema.optional(),
126
+ assignTo: z.string().optional(),
127
+ effects: z.array(z.string()).optional(),
128
+ });
129
+
130
+ export type ActionOptions = z.infer<typeof ActionOptionsSchema>;
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+
7
+ import { z } from "zod";
8
+
9
+ import { attachmentPayloadSchema } from "./attachment";
10
+ import { PayloadType } from "./button";
11
+
12
+ export const coordinatesSchema = z.object({
13
+ lat: z.number(),
14
+ lon: z.number(),
15
+ });
16
+
17
+ export const payloadSchema = z.discriminatedUnion("type", [
18
+ z.object({
19
+ type: z.literal(PayloadType.location),
20
+ coordinates: coordinatesSchema,
21
+ }),
22
+ z.object({
23
+ type: z.literal(PayloadType.attachment),
24
+ attachment: attachmentPayloadSchema,
25
+ }),
26
+ ]);
27
+
28
+ export const stdQuickReplySchema = z.object({
29
+ title: z.string().meta({
30
+ title: "Title",
31
+ description: "The label shown to the user.",
32
+ }),
33
+ payload: z.string().meta({
34
+ title: "Payload",
35
+ description: "The value sent back when the quick reply is selected.",
36
+ }),
37
+ });
38
+
39
+ export type Payload = z.infer<typeof payloadSchema>;
40
+
41
+ export type StdQuickReply = z.infer<typeof stdQuickReplySchema>;