@open-wa/schema 5.0.0 → 5.2.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.
- package/dist/generated/index.cjs +8 -2
- package/dist/generated/index.cjs.map +1 -1
- package/dist/generated/index.d.cts +7868 -994
- package/dist/generated/index.d.cts.map +1 -1
- package/dist/generated/index.d.mts +7868 -994
- package/dist/generated/index.d.mts.map +1 -1
- package/dist/generated/index.mjs +8 -2
- package/dist/generated/index.mjs.map +1 -1
- package/dist/index-C9Ad0lEr.d.cts +4729 -0
- package/dist/index-C9Ad0lEr.d.cts.map +1 -0
- package/dist/index-D0QN2PaW.d.mts +4729 -0
- package/dist/index-D0QN2PaW.d.mts.map +1 -0
- package/dist/index.cjs +109 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +53 -2
- package/dist/index.mjs.map +1 -1
- package/dist/methods/index.cjs +6 -1
- package/dist/methods/index.d.cts +2 -2
- package/dist/methods/index.d.mts +2 -2
- package/dist/methods/index.mjs +2 -2
- package/dist/{methods-Dizm7Fn9.cjs → methods-BGmdzjd3.cjs} +904 -76
- package/dist/methods-BGmdzjd3.cjs.map +1 -0
- package/dist/{methods-CZqeUhKy.mjs → methods-BhLsQNtL.mjs} +587 -77
- package/dist/methods-BhLsQNtL.mjs.map +1 -0
- package/package.json +4 -3
- package/src/__tests__/generators.contract.test.ts +181 -0
- package/src/__tests__/registry.contract.test.ts +81 -0
- package/src/client-config.ts +30 -0
- package/src/codecs.test.ts +41 -0
- package/src/codecs.ts +191 -0
- package/src/common-types.ts +287 -0
- package/src/config.ts +47 -0
- package/src/enums.ts +63 -0
- package/src/events/groups.ts +33 -0
- package/src/events/index.ts +4 -0
- package/src/events/messaging.ts +86 -0
- package/src/events/registry.ts +124 -0
- package/src/events/state.ts +59 -0
- package/src/generated/AliasMap.ts +216 -0
- package/src/generated/BaseClient.ts +878 -0
- package/src/generated/BaseNamespacedClient.ts +214 -0
- package/src/generated/index.ts +5 -0
- package/src/generated/openapi.json +30049 -0
- package/src/generated/types.ts +383 -0
- package/src/http-manifest.ts +97 -0
- package/src/implementor.test.ts +88 -0
- package/src/implementor.ts +75 -0
- package/src/index.ts +46 -0
- package/src/interactive.ts +151 -0
- package/src/methods/business.ts +52 -0
- package/src/methods/chats.ts +264 -0
- package/src/methods/communities.ts +121 -0
- package/src/methods/contacts.ts +160 -0
- package/src/methods/groups.ts +378 -0
- package/src/methods/index.ts +34 -0
- package/src/methods/interactive.ts +21 -0
- package/src/methods/labels.ts +88 -0
- package/src/methods/media.ts +36 -0
- package/src/methods/messaging.ts +836 -0
- package/src/methods/session.ts +262 -0
- package/src/methods/status.ts +122 -0
- package/src/output-json-schema.ts +27 -0
- package/src/parameters.ts +237 -0
- package/src/registry.test.ts +30 -0
- package/src/registry.ts +601 -0
- package/src/return-types.ts +125 -0
- package/dist/index-BHcd0h7x.d.mts +0 -1265
- package/dist/index-BHcd0h7x.d.mts.map +0 -1
- package/dist/index-ChYFQM1K.d.cts +0 -1265
- package/dist/index-ChYFQM1K.d.cts.map +0 -1
- package/dist/methods-CZqeUhKy.mjs.map +0 -1
- package/dist/methods-Dizm7Fn9.cjs.map +0 -1
package/src/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export * from './registry';
|
|
2
|
+
export * from './config';
|
|
3
|
+
export * from './client-config';
|
|
4
|
+
export * from './common-types';
|
|
5
|
+
export * from './return-types';
|
|
6
|
+
export * from './output-json-schema';
|
|
7
|
+
export * from './methods';
|
|
8
|
+
export * from './events';
|
|
9
|
+
export * from './enums';
|
|
10
|
+
export * from './implementor';
|
|
11
|
+
export {
|
|
12
|
+
chatIdCodec,
|
|
13
|
+
contactIdCodec,
|
|
14
|
+
groupIdCodec,
|
|
15
|
+
messageIdCodec,
|
|
16
|
+
createFileCodec,
|
|
17
|
+
fileToDataUrlCodec,
|
|
18
|
+
fileToBase64Codec,
|
|
19
|
+
fileToBufferCodec,
|
|
20
|
+
fileToTempPathCodec,
|
|
21
|
+
fileToStreamCodec,
|
|
22
|
+
base64ToDataUrlCodec,
|
|
23
|
+
urlToDataUrlCodec,
|
|
24
|
+
isoDatetimeToDate,
|
|
25
|
+
unixSecondsToDate,
|
|
26
|
+
unixMillisToDate,
|
|
27
|
+
hexColorCodec,
|
|
28
|
+
jsonStringCodec,
|
|
29
|
+
ChatIdSchema,
|
|
30
|
+
ContactIdSchema,
|
|
31
|
+
GroupIdSchema,
|
|
32
|
+
MessageIdSchema,
|
|
33
|
+
ChatIdCodecSchema,
|
|
34
|
+
ContactIdCodecSchema,
|
|
35
|
+
GroupIdCodecSchema,
|
|
36
|
+
MessageIdCodecSchema,
|
|
37
|
+
FileToDataUrlSchema,
|
|
38
|
+
Base64ToDataUrlSchema,
|
|
39
|
+
HexColorSchema,
|
|
40
|
+
IsoDatetimeToDateSchema,
|
|
41
|
+
UnixSecondsToDateSchema,
|
|
42
|
+
UnixMillisToDateSchema
|
|
43
|
+
} from './codecs';
|
|
44
|
+
export * from './parameters';
|
|
45
|
+
export * from './http-manifest';
|
|
46
|
+
export * from './interactive';
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** A portable JSON document shared by the SDK, HTTP API and message builders. */
|
|
4
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };
|
|
5
|
+
export const JsonValueSchema: z.ZodType<JsonValue> = z.lazy(() => z.union([
|
|
6
|
+
z.null(), z.boolean(), z.number().finite(), z.string(),
|
|
7
|
+
z.array(JsonValueSchema), z.record(z.string(), JsonValueSchema),
|
|
8
|
+
]));
|
|
9
|
+
export const JsonObjectSchema = z.record(z.string(), JsonValueSchema);
|
|
10
|
+
const text = z.string().min(1);
|
|
11
|
+
const url = z.url().refine(value => /^https?:\/\//i.test(value), 'Use an HTTP or HTTPS URL');
|
|
12
|
+
const id = text.describe('Stable application-defined ID returned when the recipient chooses this item');
|
|
13
|
+
|
|
14
|
+
export const ReplyActionSchema = z.object({ type: z.literal('reply'), id, label: text }).strict();
|
|
15
|
+
export const LinkActionSchema = z.object({ type: z.literal('url'), label: text, url }).strict();
|
|
16
|
+
export const CallActionSchema = z.object({ type: z.literal('call'), label: text, phoneNumber: text }).strict();
|
|
17
|
+
export const CopyActionSchema = z.object({ type: z.literal('copy'), label: text, code: text }).strict();
|
|
18
|
+
export const InteractiveActionSchema = z.discriminatedUnion('type', [
|
|
19
|
+
ReplyActionSchema, LinkActionSchema, CallActionSchema, CopyActionSchema,
|
|
20
|
+
]);
|
|
21
|
+
export const NativeActionSchema = z.object({
|
|
22
|
+
name: text.describe('WhatsApp native action name; availability depends on the recipient and account'),
|
|
23
|
+
parameters: JsonObjectSchema.optional(),
|
|
24
|
+
}).strict();
|
|
25
|
+
const actions = z.array(InteractiveActionSchema).min(1).superRefine((items, ctx) => {
|
|
26
|
+
const replies = items.filter(item => item.type === 'reply');
|
|
27
|
+
if (replies.length && replies.length !== items.length) {
|
|
28
|
+
ctx.addIssue({ code: 'custom', message: 'Reply actions cannot be mixed with URL, call or copy actions' });
|
|
29
|
+
}
|
|
30
|
+
const ids = new Set<string>();
|
|
31
|
+
items.forEach((item, index) => {
|
|
32
|
+
if (item.type !== 'reply') return;
|
|
33
|
+
if (ids.has(item.id)) ctx.addIssue({ code: 'custom', path: [index, 'id'], message: 'Duplicate reply ID' });
|
|
34
|
+
ids.add(item.id);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const media = {
|
|
39
|
+
source: text.describe('HTTP(S) URL, local file path or base64 data URL; resolved by the client before sending'),
|
|
40
|
+
filename: text.optional(),
|
|
41
|
+
title: z.string().optional(),
|
|
42
|
+
};
|
|
43
|
+
export const InteractiveHeaderSchema = z.discriminatedUnion('type', [
|
|
44
|
+
z.object({ type: z.literal('text'), text }).strict(),
|
|
45
|
+
z.object({ type: z.literal('image'), ...media }).strict(),
|
|
46
|
+
z.object({ type: z.literal('video'), ...media }).strict(),
|
|
47
|
+
z.object({ type: z.literal('document'), ...media }).strict(),
|
|
48
|
+
]);
|
|
49
|
+
const base = {
|
|
50
|
+
version: z.literal(1).optional().describe('Document format version, defaults to 1; independent of WhatsApp protocol versions'),
|
|
51
|
+
body: text,
|
|
52
|
+
footer: z.string().optional(),
|
|
53
|
+
};
|
|
54
|
+
export const ButtonsContentSchema = z.object({
|
|
55
|
+
...base, type: z.literal('buttons'), header: InteractiveHeaderSchema.optional(), actions,
|
|
56
|
+
}).strict();
|
|
57
|
+
export const ListRowSchema = z.object({ id, title: text, description: z.string().optional() }).strict();
|
|
58
|
+
export const ListContentSchema = z.object({
|
|
59
|
+
...base, type: z.literal('list'), title: z.string().optional(), buttonLabel: text.default('Choose an option'),
|
|
60
|
+
sections: z.array(z.object({ title: z.string().optional(), rows: z.array(ListRowSchema).min(1) }).strict()).min(1),
|
|
61
|
+
}).strict();
|
|
62
|
+
export const FormQuestionSchema = z.object({
|
|
63
|
+
type: z.enum(['singleSelect', 'multiSelect']), id, label: text,
|
|
64
|
+
options: z.array(z.object({ id, label: text }).strict()).min(1),
|
|
65
|
+
allowCustomAnswer: z.boolean().optional(),
|
|
66
|
+
}).strict();
|
|
67
|
+
export const FormContentSchema = z.object({
|
|
68
|
+
...base, type: z.literal('form'), title: z.string().optional(), questions: z.array(FormQuestionSchema).min(1),
|
|
69
|
+
}).strict();
|
|
70
|
+
export const CarouselCardSchema = z.object({
|
|
71
|
+
body: text,
|
|
72
|
+
header: z.object({ type: z.literal('image'), ...media }).strict(),
|
|
73
|
+
actions,
|
|
74
|
+
}).strict();
|
|
75
|
+
export const CarouselContentSchema = z.object({
|
|
76
|
+
...base, type: z.literal('carousel'), cards: z.array(CarouselCardSchema).min(1),
|
|
77
|
+
}).strict();
|
|
78
|
+
export const BookingContentSchema = z.object({
|
|
79
|
+
...base, type: z.literal('booking'), title: z.string().optional(), buttonLabel: text.default('View booking'),
|
|
80
|
+
booking: z.object({
|
|
81
|
+
startAt: z.iso.datetime({ offset: true }), endAt: z.iso.datetime({ offset: true }).optional(),
|
|
82
|
+
location: z.string().optional(), url: url.optional(), managementUrl: url.optional(),
|
|
83
|
+
phoneNumber: z.string().optional(), email: z.email().optional(), description: z.string().optional(),
|
|
84
|
+
labels: z.object({
|
|
85
|
+
language: z.string().optional(), meetingType: z.string().optional(), detailsTitle: z.string().optional(),
|
|
86
|
+
addToCalendar: z.string().optional(), viewOnMap: z.string().optional(), manageBooking: z.string().optional(),
|
|
87
|
+
}).strict().optional(),
|
|
88
|
+
}).strict(),
|
|
89
|
+
actions: z.array(z.discriminatedUnion('type', [LinkActionSchema, CallActionSchema, CopyActionSchema])).optional(),
|
|
90
|
+
}).strict();
|
|
91
|
+
export const NativeContentSchema = z.object({
|
|
92
|
+
...base, type: z.literal('native'), header: InteractiveHeaderSchema.optional(),
|
|
93
|
+
actions: z.array(NativeActionSchema).min(1), parameters: JsonObjectSchema.optional(),
|
|
94
|
+
}).strict().describe('Advanced extension for new native action types; parameters are passed through without claiming recipient support');
|
|
95
|
+
|
|
96
|
+
export const InteractiveContentSchema = z.discriminatedUnion('type', [
|
|
97
|
+
ButtonsContentSchema, ListContentSchema, FormContentSchema, CarouselContentSchema, BookingContentSchema, NativeContentSchema,
|
|
98
|
+
]).superRefine((content, ctx) => {
|
|
99
|
+
const unique = (items: { id: string }[], path: (string | number)[]) => {
|
|
100
|
+
const seen = new Set<string>();
|
|
101
|
+
items.forEach((item, index) => {
|
|
102
|
+
if (seen.has(item.id)) ctx.addIssue({ code: 'custom', path: [...path, index, 'id'], message: 'IDs must be unique' });
|
|
103
|
+
seen.add(item.id);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
if (content.type === 'form') {
|
|
107
|
+
unique(content.questions, ['questions']);
|
|
108
|
+
content.questions.forEach((q, index) => {
|
|
109
|
+
unique(q.options, ['questions', index, 'options']);
|
|
110
|
+
if (q.id === '__openwa_form__') ctx.addIssue({ code: 'custom', path: ['questions', index, 'id'], message: 'This question ID is reserved' });
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (content.type === 'list') {
|
|
114
|
+
const seen = new Set<string>();
|
|
115
|
+
content.sections.forEach((section, s) => section.rows.forEach((row, r) => {
|
|
116
|
+
if (seen.has(row.id)) ctx.addIssue({ code: 'custom', path: ['sections', s, 'rows', r, 'id'], message: 'Row IDs must be unique across sections' });
|
|
117
|
+
seen.add(row.id);
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
if (content.type === 'booking' && content.booking.endAt && Date.parse(content.booking.endAt) <= Date.parse(content.booking.startAt)) {
|
|
121
|
+
ctx.addIssue({ code: 'custom', path: ['booking', 'endAt'], message: 'Booking end must be after its start' });
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export type InteractiveContent = z.input<typeof InteractiveContentSchema>;
|
|
126
|
+
export type InteractiveAction = z.infer<typeof InteractiveActionSchema>;
|
|
127
|
+
export type InteractiveHeader = z.infer<typeof InteractiveHeaderSchema>;
|
|
128
|
+
export type FormQuestion = z.infer<typeof FormQuestionSchema>;
|
|
129
|
+
/** Validate a JSON document without sending it or loading media; suitable for UI builders. */
|
|
130
|
+
export function defineInteractiveMessage<T extends InteractiveContent>(content: T): Extract<z.output<typeof InteractiveContentSchema>, { type: T['type'] }> {
|
|
131
|
+
return InteractiveContentSchema.parse(content) as Extract<z.output<typeof InteractiveContentSchema>, { type: T['type'] }>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const responseBase = {
|
|
135
|
+
messageId: text, chatId: text, senderId: text,
|
|
136
|
+
originalMessageId: z.string().optional().describe('Original WhatsApp stanza ID; may not be a full serialized message key'),
|
|
137
|
+
timestamp: z.number().optional(),
|
|
138
|
+
raw: JsonObjectSchema,
|
|
139
|
+
};
|
|
140
|
+
export const FormResponseSchema = z.object({
|
|
141
|
+
...responseBase, type: z.literal('form'),
|
|
142
|
+
answers: z.record(z.string(), z.union([z.string(), z.array(z.string())])),
|
|
143
|
+
});
|
|
144
|
+
export const InteractiveResponseSchema = z.discriminatedUnion('type', [
|
|
145
|
+
FormResponseSchema,
|
|
146
|
+
z.object({ ...responseBase, type: z.literal('reply'), id: text, label: z.string().optional() }),
|
|
147
|
+
z.object({ ...responseBase, type: z.literal('list'), id: text, label: z.string().optional() }),
|
|
148
|
+
z.object({ ...responseBase, type: z.literal('native'), name: text, parameters: JsonValueSchema.optional(), parseError: z.string().optional() }),
|
|
149
|
+
]);
|
|
150
|
+
export type FormResponse = z.infer<typeof FormResponseSchema>;
|
|
151
|
+
export type InteractiveResponse = z.infer<typeof InteractiveResponseSchema>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BusinessProfileSchema, OrderSchema, ProductSchema } from '../return-types';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { defineMethodV2 } from '../registry';
|
|
4
|
+
import { contactIdParam, messageIdParam } from '../parameters';
|
|
5
|
+
|
|
6
|
+
export const getBusinessProfile = defineMethodV2('getBusinessProfile', {
|
|
7
|
+
meta: {
|
|
8
|
+
description: 'Get business profile',
|
|
9
|
+
action: 'read',
|
|
10
|
+
namespace: 'business',
|
|
11
|
+
license: 'none',
|
|
12
|
+
functionality: 'both',
|
|
13
|
+
httpMethod: 'GET',
|
|
14
|
+
},
|
|
15
|
+
input: z.object({ contactId: contactIdParam }),
|
|
16
|
+
parameterOrder: ['contactId'],
|
|
17
|
+
output: BusinessProfileSchema,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const getBusinessProducts = defineMethodV2('getBusinessProducts', {
|
|
21
|
+
meta: {
|
|
22
|
+
description: 'Get business products',
|
|
23
|
+
action: 'read',
|
|
24
|
+
namespace: 'business',
|
|
25
|
+
license: 'none',
|
|
26
|
+
functionality: 'both',
|
|
27
|
+
httpMethod: 'GET',
|
|
28
|
+
aliases: {
|
|
29
|
+
deprecated: ['getBusinessProfilesProducts'],
|
|
30
|
+
},
|
|
31
|
+
wapiOverride: 'getBusinessProfilesProducts',
|
|
32
|
+
},
|
|
33
|
+
input: z.object({ contactId: contactIdParam }),
|
|
34
|
+
parameterOrder: ['contactId'],
|
|
35
|
+
output: z.array(ProductSchema).or(z.literal(false)),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const getOrder = defineMethodV2('getOrder', {
|
|
39
|
+
meta: {
|
|
40
|
+
description: 'Get order details',
|
|
41
|
+
action: 'read',
|
|
42
|
+
namespace: 'business',
|
|
43
|
+
license: 'insiders',
|
|
44
|
+
functionality: 'both',
|
|
45
|
+
httpMethod: 'GET',
|
|
46
|
+
},
|
|
47
|
+
input: z.object({
|
|
48
|
+
id: z.union([messageIdParam, z.string()]).describe('Order or message ID'),
|
|
49
|
+
}),
|
|
50
|
+
parameterOrder: ['id'],
|
|
51
|
+
output: OrderSchema,
|
|
52
|
+
});
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { ChatIdSchema, ChatSchema, ContactSchema } from '../common-types';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { defineMethodV2 } from '../registry';
|
|
4
|
+
import { chatIdParam, withNewMessagesOnlyParam } from '../parameters';
|
|
5
|
+
|
|
6
|
+
export const getAllChats = defineMethodV2('getAllChats', {
|
|
7
|
+
meta: {
|
|
8
|
+
description: 'Returns serialized Chat objects from the current session, optionally limited to chats with unread messages.',
|
|
9
|
+
action: 'read',
|
|
10
|
+
namespace: 'chats',
|
|
11
|
+
license: 'none',
|
|
12
|
+
functionality: 'both',
|
|
13
|
+
httpMethod: 'GET',
|
|
14
|
+
},
|
|
15
|
+
input: z.object({ withNewMessagesOnly: withNewMessagesOnlyParam }),
|
|
16
|
+
parameterOrder: ['withNewMessagesOnly'],
|
|
17
|
+
output: z.array(ChatSchema),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const getAllChatIds = defineMethodV2('getAllChatIds', {
|
|
21
|
+
meta: {
|
|
22
|
+
description: 'Get all chat IDs',
|
|
23
|
+
action: 'read',
|
|
24
|
+
namespace: 'chatIds',
|
|
25
|
+
license: 'none',
|
|
26
|
+
functionality: 'both',
|
|
27
|
+
httpMethod: 'GET',
|
|
28
|
+
aliases: {
|
|
29
|
+
explicit: ['chats.ids'],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
input: z.object({}),
|
|
33
|
+
parameterOrder: [],
|
|
34
|
+
output: z.array(ChatIdSchema),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// export const getAllChatsWithMessages = defineMethodV2('getAllChatsWithMessages', {
|
|
38
|
+
// meta: {
|
|
39
|
+
// description: 'Get chats with messages',
|
|
40
|
+
// action: 'read',
|
|
41
|
+
// namespace: 'chats',
|
|
42
|
+
// license: 'none',
|
|
43
|
+
// functionality: 'both',
|
|
44
|
+
// httpMethod: 'GET',
|
|
45
|
+
// },
|
|
46
|
+
// input: z.object({
|
|
47
|
+
// withNewMessagesOnly: withNewMessagesOnlyParam,
|
|
48
|
+
// }),
|
|
49
|
+
// parameterOrder: ['withNewMessagesOnly'],
|
|
50
|
+
// output: z.array(z.any()),
|
|
51
|
+
// });
|
|
52
|
+
|
|
53
|
+
export const getChat = defineMethodV2('getChat', {
|
|
54
|
+
meta: {
|
|
55
|
+
description: 'Get specific chat by ID',
|
|
56
|
+
action: 'read',
|
|
57
|
+
namespace: 'chats',
|
|
58
|
+
license: 'none',
|
|
59
|
+
functionality: 'both',
|
|
60
|
+
httpMethod: 'GET',
|
|
61
|
+
aliases: {
|
|
62
|
+
explicit: ['getChatById'],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
input: z.object({
|
|
66
|
+
chatId: chatIdParam,
|
|
67
|
+
}),
|
|
68
|
+
parameterOrder: ['chatId'],
|
|
69
|
+
output: ChatSchema.nullable().optional().or(z.literal(false)),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const getChatWithNonContacts = defineMethodV2('getChatWithNonContacts', {
|
|
73
|
+
meta: {
|
|
74
|
+
description: 'Get chats with non-contacts',
|
|
75
|
+
action: 'read',
|
|
76
|
+
namespace: 'chats',
|
|
77
|
+
license: 'none',
|
|
78
|
+
functionality: 'both',
|
|
79
|
+
httpMethod: 'GET',
|
|
80
|
+
},
|
|
81
|
+
input: z.object({}),
|
|
82
|
+
parameterOrder: [],
|
|
83
|
+
output: z.array(ContactSchema),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const archiveChat = defineMethodV2('archiveChat', {
|
|
87
|
+
meta: {
|
|
88
|
+
description: 'Archive a chat',
|
|
89
|
+
action: 'update',
|
|
90
|
+
namespace: 'chats',
|
|
91
|
+
license: 'none',
|
|
92
|
+
functionality: 'both',
|
|
93
|
+
httpMethod: 'PUT',
|
|
94
|
+
},
|
|
95
|
+
input: z.object({ chatId: chatIdParam }),
|
|
96
|
+
parameterOrder: ['chatId'],
|
|
97
|
+
output: z.boolean(),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export const unarchiveChat = defineMethodV2('unarchiveChat', {
|
|
101
|
+
meta: {
|
|
102
|
+
description: 'Unarchive a chat',
|
|
103
|
+
action: 'update',
|
|
104
|
+
namespace: 'chats',
|
|
105
|
+
license: 'none',
|
|
106
|
+
functionality: 'both',
|
|
107
|
+
httpMethod: 'PUT',
|
|
108
|
+
},
|
|
109
|
+
input: z.object({ chatId: chatIdParam }),
|
|
110
|
+
parameterOrder: ['chatId'],
|
|
111
|
+
output: z.boolean(),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export const clearChat = defineMethodV2('clearChat', {
|
|
115
|
+
meta: {
|
|
116
|
+
description: 'Clear chat history',
|
|
117
|
+
action: 'delete',
|
|
118
|
+
namespace: 'chats',
|
|
119
|
+
license: 'none',
|
|
120
|
+
functionality: 'both',
|
|
121
|
+
httpMethod: 'DELETE',
|
|
122
|
+
},
|
|
123
|
+
input: z.object({ chatId: chatIdParam }),
|
|
124
|
+
parameterOrder: ['chatId'],
|
|
125
|
+
output: z.boolean(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export const deleteChat = defineMethodV2('deleteChat', {
|
|
129
|
+
meta: {
|
|
130
|
+
description: 'Delete a chat',
|
|
131
|
+
action: 'delete',
|
|
132
|
+
namespace: 'chats',
|
|
133
|
+
license: 'none',
|
|
134
|
+
functionality: 'both',
|
|
135
|
+
httpMethod: 'DELETE',
|
|
136
|
+
},
|
|
137
|
+
input: z.object({ chatId: chatIdParam }),
|
|
138
|
+
parameterOrder: ['chatId'],
|
|
139
|
+
output: z.boolean(),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export const pinChat = defineMethodV2('pinChat', {
|
|
143
|
+
meta: {
|
|
144
|
+
description: 'Pin a chat',
|
|
145
|
+
action: 'update',
|
|
146
|
+
namespace: 'chats',
|
|
147
|
+
license: 'none',
|
|
148
|
+
functionality: 'both',
|
|
149
|
+
httpMethod: 'PUT',
|
|
150
|
+
},
|
|
151
|
+
input: z.object({ chatId: chatIdParam }),
|
|
152
|
+
parameterOrder: ['chatId'],
|
|
153
|
+
output: z.boolean(),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export const unpinChat = defineMethodV2('unpinChat', {
|
|
157
|
+
meta: {
|
|
158
|
+
description: 'Unpin a chat',
|
|
159
|
+
action: 'update',
|
|
160
|
+
namespace: 'chats',
|
|
161
|
+
license: 'none',
|
|
162
|
+
functionality: 'both',
|
|
163
|
+
httpMethod: 'PUT',
|
|
164
|
+
},
|
|
165
|
+
input: z.object({ chatId: chatIdParam }),
|
|
166
|
+
parameterOrder: ['chatId'],
|
|
167
|
+
output: z.boolean(),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
export const muteChat = defineMethodV2('muteChat', {
|
|
171
|
+
meta: {
|
|
172
|
+
description: 'Mute a chat',
|
|
173
|
+
action: 'update',
|
|
174
|
+
namespace: 'chats',
|
|
175
|
+
license: 'none',
|
|
176
|
+
functionality: 'both',
|
|
177
|
+
httpMethod: 'PUT',
|
|
178
|
+
},
|
|
179
|
+
input: z.object({
|
|
180
|
+
chatId: chatIdParam,
|
|
181
|
+
muteDuration: z.union([z.number(), z.string()]).describe('Mute duration'),
|
|
182
|
+
}),
|
|
183
|
+
parameterOrder: ['chatId', 'muteDuration'],
|
|
184
|
+
output: z.union([z.string(), z.boolean(), z.number()]),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export const unmuteChat = defineMethodV2('unmuteChat', {
|
|
188
|
+
meta: {
|
|
189
|
+
description: 'Unmute a chat',
|
|
190
|
+
action: 'update',
|
|
191
|
+
namespace: 'chats',
|
|
192
|
+
license: 'none',
|
|
193
|
+
functionality: 'both',
|
|
194
|
+
httpMethod: 'PUT',
|
|
195
|
+
},
|
|
196
|
+
input: z.object({ chatId: chatIdParam }),
|
|
197
|
+
parameterOrder: ['chatId'],
|
|
198
|
+
output: z.union([z.string(), z.boolean(), z.number()]),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
export const markAsRead = defineMethodV2('markAsRead', {
|
|
202
|
+
meta: {
|
|
203
|
+
description: 'Mark chat as read',
|
|
204
|
+
action: 'update',
|
|
205
|
+
namespace: 'chats',
|
|
206
|
+
license: 'none',
|
|
207
|
+
functionality: 'both',
|
|
208
|
+
httpMethod: 'PUT',
|
|
209
|
+
aliases: {
|
|
210
|
+
namespacedName: 'markAsRead',
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
input: z.object({ chatId: chatIdParam }),
|
|
214
|
+
parameterOrder: ['chatId'],
|
|
215
|
+
output: z.boolean(),
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
export const markAsUnread = defineMethodV2('markAsUnread', {
|
|
219
|
+
meta: {
|
|
220
|
+
description: 'Mark chat as unread',
|
|
221
|
+
action: 'update',
|
|
222
|
+
namespace: 'chats',
|
|
223
|
+
license: 'none',
|
|
224
|
+
functionality: 'both',
|
|
225
|
+
httpMethod: 'PUT',
|
|
226
|
+
aliases: {
|
|
227
|
+
namespacedName: 'markAsUnread',
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
input: z.object({ chatId: chatIdParam }),
|
|
231
|
+
parameterOrder: ['chatId'],
|
|
232
|
+
output: z.boolean(),
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
export const setChatEphemeral = defineMethodV2('setChatEphemeral', {
|
|
236
|
+
meta: {
|
|
237
|
+
description: 'Set ephemeral messages for chat',
|
|
238
|
+
action: 'update',
|
|
239
|
+
namespace: 'chats',
|
|
240
|
+
license: 'none',
|
|
241
|
+
functionality: 'both',
|
|
242
|
+
httpMethod: 'PUT',
|
|
243
|
+
},
|
|
244
|
+
input: z.object({
|
|
245
|
+
chatId: chatIdParam,
|
|
246
|
+
ephemeral: z.union([z.boolean(), z.number()]).describe('Ephemeral setting'),
|
|
247
|
+
}),
|
|
248
|
+
parameterOrder: ['chatId', 'ephemeral'],
|
|
249
|
+
output: z.boolean(),
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
export const isChatOnline = defineMethodV2('isChatOnline', {
|
|
253
|
+
meta: {
|
|
254
|
+
description: 'Check if chat is online',
|
|
255
|
+
action: 'read',
|
|
256
|
+
namespace: 'chats',
|
|
257
|
+
license: 'none',
|
|
258
|
+
functionality: 'both',
|
|
259
|
+
httpMethod: 'GET',
|
|
260
|
+
},
|
|
261
|
+
input: z.object({ chatId: chatIdParam }),
|
|
262
|
+
parameterOrder: ['chatId'],
|
|
263
|
+
output: z.union([z.boolean(), z.string()]),
|
|
264
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { GroupChatIdSchema } from '../common-types';
|
|
2
|
+
import { CommunityAdminIdsSchema, CommunityAdminsSchema, CommunityMetadataSchema, CommunityParticipantIdsSchema, CommunityParticipantsSchema } from '../return-types';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { defineMethodV2 } from '../registry';
|
|
5
|
+
import { communityIdParam } from '../parameters';
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Community Methods
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get all communities
|
|
13
|
+
*/
|
|
14
|
+
export const getAllCommunities = defineMethodV2('getAllCommunities', {
|
|
15
|
+
meta: {
|
|
16
|
+
description: 'Get all communities',
|
|
17
|
+
action: 'read',
|
|
18
|
+
namespace: 'communities',
|
|
19
|
+
license: 'none',
|
|
20
|
+
functionality: 'both',
|
|
21
|
+
httpMethod: 'GET',
|
|
22
|
+
},
|
|
23
|
+
input: z.object({}),
|
|
24
|
+
parameterOrder: [],
|
|
25
|
+
output: z.array(GroupChatIdSchema),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get community info
|
|
30
|
+
*/
|
|
31
|
+
export const getCommunityInfo = defineMethodV2('getCommunityInfo', {
|
|
32
|
+
meta: {
|
|
33
|
+
description: 'Get community metadata',
|
|
34
|
+
action: 'read',
|
|
35
|
+
namespace: 'communities',
|
|
36
|
+
license: 'none',
|
|
37
|
+
functionality: 'both',
|
|
38
|
+
httpMethod: 'GET',
|
|
39
|
+
},
|
|
40
|
+
input: z.object({
|
|
41
|
+
communityId: communityIdParam
|
|
42
|
+
}),
|
|
43
|
+
parameterOrder: ['communityId'],
|
|
44
|
+
output: CommunityMetadataSchema,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get community participant IDs
|
|
49
|
+
*/
|
|
50
|
+
export const getCommunityParticipantIds = defineMethodV2('getCommunityParticipantIds', {
|
|
51
|
+
meta: {
|
|
52
|
+
description: 'Get community participant IDs',
|
|
53
|
+
action: 'read',
|
|
54
|
+
namespace: 'communities',
|
|
55
|
+
license: 'none',
|
|
56
|
+
functionality: 'both',
|
|
57
|
+
httpMethod: 'GET',
|
|
58
|
+
},
|
|
59
|
+
input: z.object({
|
|
60
|
+
communityId: communityIdParam
|
|
61
|
+
}),
|
|
62
|
+
parameterOrder: ['communityId'],
|
|
63
|
+
output: z.array(CommunityParticipantIdsSchema),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get community admin IDs
|
|
68
|
+
*/
|
|
69
|
+
export const getCommunityAdminIds = defineMethodV2('getCommunityAdminIds', {
|
|
70
|
+
meta: {
|
|
71
|
+
description: 'Get community admin IDs',
|
|
72
|
+
action: 'read',
|
|
73
|
+
namespace: 'communities',
|
|
74
|
+
license: 'none',
|
|
75
|
+
functionality: 'both',
|
|
76
|
+
httpMethod: 'GET',
|
|
77
|
+
},
|
|
78
|
+
input: z.object({
|
|
79
|
+
communityId: communityIdParam
|
|
80
|
+
}),
|
|
81
|
+
parameterOrder: ['communityId'],
|
|
82
|
+
output: z.array(CommunityAdminIdsSchema),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get community participants
|
|
87
|
+
*/
|
|
88
|
+
export const getCommunityParticipants = defineMethodV2('getCommunityParticipants', {
|
|
89
|
+
meta: {
|
|
90
|
+
description: 'Get community participants',
|
|
91
|
+
action: 'read',
|
|
92
|
+
namespace: 'communities',
|
|
93
|
+
license: 'none',
|
|
94
|
+
functionality: 'both',
|
|
95
|
+
httpMethod: 'GET',
|
|
96
|
+
},
|
|
97
|
+
input: z.object({
|
|
98
|
+
communityId: communityIdParam
|
|
99
|
+
}),
|
|
100
|
+
parameterOrder: ['communityId'],
|
|
101
|
+
output: z.array(CommunityParticipantsSchema),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get community admins
|
|
106
|
+
*/
|
|
107
|
+
export const getCommunityAdmins = defineMethodV2('getCommunityAdmins', {
|
|
108
|
+
meta: {
|
|
109
|
+
description: 'Get community admins',
|
|
110
|
+
action: 'read',
|
|
111
|
+
namespace: 'communities',
|
|
112
|
+
license: 'none',
|
|
113
|
+
functionality: 'both',
|
|
114
|
+
httpMethod: 'GET',
|
|
115
|
+
},
|
|
116
|
+
input: z.object({
|
|
117
|
+
communityId: communityIdParam
|
|
118
|
+
}),
|
|
119
|
+
parameterOrder: ['communityId'],
|
|
120
|
+
output: z.array(CommunityAdminsSchema),
|
|
121
|
+
});
|