@open-wa/schema 5.3.0 → 5.5.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/calling-media--BLrFrPc.cjs +113 -0
- package/dist/calling-media--BLrFrPc.cjs.map +1 -0
- package/dist/calling-media-BNTYvogE.mjs +60 -0
- package/dist/calling-media-BNTYvogE.mjs.map +1 -0
- package/dist/calling-media-CeGgSzhw.d.cts +48 -0
- package/dist/calling-media-CeGgSzhw.d.cts.map +1 -0
- package/dist/calling-media-CeGgSzhw.d.mts +48 -0
- package/dist/calling-media-CeGgSzhw.d.mts.map +1 -0
- package/dist/calling-media.cjs +8 -0
- package/dist/calling-media.d.cts +2 -0
- package/dist/calling-media.d.mts +2 -0
- package/dist/calling-media.mjs +2 -0
- package/dist/generated/index.cjs +94 -3
- package/dist/generated/index.cjs.map +1 -1
- package/dist/generated/index.d.cts +2328 -133
- package/dist/generated/index.d.cts.map +1 -1
- package/dist/generated/index.d.mts +2328 -133
- package/dist/generated/index.d.mts.map +1 -1
- package/dist/generated/index.mjs +94 -3
- package/dist/generated/index.mjs.map +1 -1
- package/dist/{index-C9Ad0lEr.d.cts → index-BWvNXopK.d.cts} +2375 -41
- package/dist/index-BWvNXopK.d.cts.map +1 -0
- package/dist/{index-D0QN2PaW.d.mts → index-Co8HQxm8.d.mts} +2375 -41
- package/dist/index-Co8HQxm8.d.mts.map +1 -0
- package/dist/index.cjs +191 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +105 -21
- package/dist/index.mjs.map +1 -1
- package/dist/methods/index.cjs +34 -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-BhLsQNtL.mjs → methods-BH7nDC3z.mjs} +816 -51
- package/dist/methods-BH7nDC3z.mjs.map +1 -0
- package/dist/{methods-BGmdzjd3.cjs → methods-DpDzgsbe.cjs} +1284 -63
- package/dist/methods-DpDzgsbe.cjs.map +1 -0
- package/package.json +15 -4
- package/src/calling-media.ts +64 -0
- package/src/calling-wire.ts +17 -0
- package/src/calling.ts +61 -0
- package/src/common-types.ts +16 -0
- package/src/effect-projection.ts +67 -0
- package/src/events/calls.ts +12 -0
- package/src/events/groups.ts +30 -6
- package/src/events/index.ts +4 -0
- package/src/events/messaging.ts +7 -7
- package/src/events/polls.ts +11 -0
- package/src/events/registry.ts +2 -1
- package/src/events/whatsapp-events.ts +13 -0
- package/src/generated/AliasMap.ts +30 -1
- package/src/generated/BaseClient.ts +153 -8
- package/src/generated/BaseNamespacedClient.ts +36 -1
- package/src/generated/openapi.json +22999 -12765
- package/src/generated/types.ts +87 -0
- package/src/index.ts +10 -0
- package/src/license.ts +10 -0
- package/src/media-options.ts +46 -0
- package/src/methods/calls.ts +23 -0
- package/src/methods/contacts.ts +10 -1
- package/src/methods/groups.ts +9 -3
- package/src/methods/index.ts +2 -0
- package/src/methods/messaging.ts +159 -45
- package/src/methods/session.ts +10 -0
- package/src/methods/whatsapp-events.ts +35 -0
- package/src/polls.ts +37 -0
- package/src/session-refresh.ts +15 -0
- package/src/whatsapp-event-registry.ts +17 -0
- package/src/whatsapp-events.ts +91 -0
- package/dist/index-C9Ad0lEr.d.cts.map +0 -1
- package/dist/index-D0QN2PaW.d.mts.map +0 -1
- package/dist/methods-BGmdzjd3.cjs.map +0 -1
- package/dist/methods-BhLsQNtL.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-wa/schema",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Zod-based schema definitions for open-wa",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -60,14 +60,25 @@
|
|
|
60
60
|
"types": "./dist/http-manifest.d.mts",
|
|
61
61
|
"default": "./dist/http-manifest.mjs"
|
|
62
62
|
}
|
|
63
|
+
},
|
|
64
|
+
"./calling-media": {
|
|
65
|
+
"import": {
|
|
66
|
+
"types": "./dist/calling-media.d.mts",
|
|
67
|
+
"default": "./dist/calling-media.mjs"
|
|
68
|
+
},
|
|
69
|
+
"require": {
|
|
70
|
+
"types": "./dist/calling-media.d.cts",
|
|
71
|
+
"default": "./dist/calling-media.cjs"
|
|
72
|
+
}
|
|
63
73
|
}
|
|
64
74
|
},
|
|
65
75
|
"dependencies": {
|
|
66
76
|
"@asteasolutions/zod-to-openapi": "^9.1.0",
|
|
67
|
-
"@open-wa/config": "5.
|
|
68
|
-
"@open-wa/utils": "5.
|
|
77
|
+
"@open-wa/config": "5.5.0",
|
|
78
|
+
"@open-wa/utils": "5.5.0",
|
|
69
79
|
"zod": "^4.6.5",
|
|
70
|
-
"zod-to-json-schema": "^3.25.2"
|
|
80
|
+
"zod-to-json-schema": "^3.25.2",
|
|
81
|
+
"effect": "4.0.2"
|
|
71
82
|
},
|
|
72
83
|
"devDependencies": {
|
|
73
84
|
"ts-node": "^10.9.2",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export { decodeAudioPacket } from './calling-wire';
|
|
2
|
+
/** Device defaults are serializable so embedded and remote clients share the same API. */
|
|
3
|
+
export const DEFAULT_MIC = 'default:microphone' as const;
|
|
4
|
+
export const DEFAULT_SPEAKER = 'default:speaker' as const;
|
|
5
|
+
export const DEFAULT_CAM = 'default:camera' as const;
|
|
6
|
+
|
|
7
|
+
export interface RawAudioFormat {
|
|
8
|
+
encoding: 'pcm16le' | 'float32le';
|
|
9
|
+
sampleRate: number;
|
|
10
|
+
channels: 1 | 2;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface MediaDescriptor {
|
|
14
|
+
kind: 'file' | 'url' | 'device' | 'remote';
|
|
15
|
+
path?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
deviceId?: string;
|
|
18
|
+
raw?: RawAudioFormat;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
overwrite?: boolean;
|
|
21
|
+
loop?: boolean;
|
|
22
|
+
/** Internal helper admission; applications use ordinary files/devices/streams. */
|
|
23
|
+
remoteId?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type AudioInput = string | MediaDescriptor | ReadableStream<Uint8Array> | Blob | null;
|
|
27
|
+
export type AudioOutput = string | MediaDescriptor | WritableStream<Uint8Array> | null;
|
|
28
|
+
export type VideoInput = string | MediaDescriptor | null;
|
|
29
|
+
export interface CallMediaOptions {
|
|
30
|
+
microphone?: AudioInput;
|
|
31
|
+
speaker?: AudioOutput;
|
|
32
|
+
camera?: VideoInput;
|
|
33
|
+
onMediaFailure?: 'end' | 'keep-open';
|
|
34
|
+
}
|
|
35
|
+
export interface CallingOptions {
|
|
36
|
+
defaults?: CallMediaOptions;
|
|
37
|
+
preparationTimeoutMs?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Keep the cause carried by Effect queue failures, whose own message can be empty. */
|
|
41
|
+
export function describeCallMediaFailure(error: unknown): string {
|
|
42
|
+
let current = error;
|
|
43
|
+
const seen = new Set<unknown>();
|
|
44
|
+
while (current && typeof current === 'object' && !seen.has(current)) {
|
|
45
|
+
seen.add(current);
|
|
46
|
+
if ('_tag' in current && current._tag === 'TaskTimeoutError' && 'timeoutMs' in current) return `Call audio processing exceeded ${current.timeoutMs} ms.`;
|
|
47
|
+
if ('_tag' in current && current._tag === 'QueueOverloadedError') return 'Call audio processing exceeded its bounded receive queue.';
|
|
48
|
+
if ('cause' in current && current.cause !== undefined) { current = current.cause; continue; }
|
|
49
|
+
if ('message' in current && typeof current.message === 'string' && current.message.trim()) return current.message;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
return typeof current === 'string' && current.trim() ? current : 'Call media failed without reporting a cause.';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function normalizeCallMedia(
|
|
56
|
+
microphone?: AudioInput | CallMediaOptions,
|
|
57
|
+
speaker?: AudioOutput,
|
|
58
|
+
camera?: VideoInput,
|
|
59
|
+
): CallMediaOptions {
|
|
60
|
+
if (microphone && typeof microphone === 'object' && !('kind' in microphone) && !('getReader' in microphone) && !('arrayBuffer' in microphone)) {
|
|
61
|
+
return microphone as CallMediaOptions;
|
|
62
|
+
}
|
|
63
|
+
return { microphone: microphone as AudioInput | undefined, speaker, camera };
|
|
64
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Neutral OpenWA audio framing. Format is negotiated in start/ready JSON. */
|
|
2
|
+
export const AUDIO_WIRE_VERSION = 1;
|
|
3
|
+
export const AUDIO_FRAME_HEADER_BYTES = 20;
|
|
4
|
+
export function encodeAudioPacket(audio: Uint8Array, sequence: number, timestampMs: number): Uint8Array {
|
|
5
|
+
const packet = new Uint8Array(AUDIO_FRAME_HEADER_BYTES + audio.length);
|
|
6
|
+
const view = new DataView(packet.buffer);
|
|
7
|
+
view.setUint32(0, 0x4f574131); // OWA1
|
|
8
|
+
view.setUint32(4, sequence); view.setFloat64(8, timestampMs); view.setUint32(16, audio.length);
|
|
9
|
+
packet.set(audio, AUDIO_FRAME_HEADER_BYTES); return packet;
|
|
10
|
+
}
|
|
11
|
+
export function decodeAudioPacket(packet: Uint8Array): { audio: Uint8Array; sequence: number; timestampMs: number } {
|
|
12
|
+
if (packet.length < AUDIO_FRAME_HEADER_BYTES) throw new Error('Audio packet is missing its header.');
|
|
13
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
14
|
+
const timestampMs = view.getFloat64(8);
|
|
15
|
+
if (view.getUint32(0) !== 0x4f574131 || view.getUint32(16) !== packet.length - AUDIO_FRAME_HEADER_BYTES || !Number.isFinite(timestampMs)) throw new Error('Invalid OpenWA audio packet.');
|
|
16
|
+
return { audio: packet.subarray(AUDIO_FRAME_HEADER_BYTES), sequence: view.getUint32(4), timestampMs };
|
|
17
|
+
}
|
package/src/calling.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import type { AudioInput, AudioOutput, CallMediaOptions, VideoInput } from './calling-media';
|
|
3
|
+
|
|
4
|
+
export const RawAudioFormatSchema = Schema.Struct({ encoding: Schema.Literals(['pcm16le', 'float32le']), sampleRate: Schema.Number, channels: Schema.Literals([1, 2]) });
|
|
5
|
+
export const MediaDescriptorSchema = Schema.Struct({
|
|
6
|
+
kind: Schema.Literals(['file', 'url', 'device', 'remote']), path: Schema.optional(Schema.String), url: Schema.optional(Schema.String),
|
|
7
|
+
deviceId: Schema.optional(Schema.String), raw: Schema.optional(RawAudioFormatSchema), headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
8
|
+
overwrite: Schema.optional(Schema.Boolean), loop: Schema.optional(Schema.Boolean), remoteId: Schema.optional(Schema.String),
|
|
9
|
+
});
|
|
10
|
+
export const CallMediaOptionsSchema = Schema.Struct({
|
|
11
|
+
microphone: Schema.optional(Schema.Unknown), speaker: Schema.optional(Schema.Unknown), camera: Schema.optional(Schema.Unknown),
|
|
12
|
+
onMediaFailure: Schema.optional(Schema.Literals(['end', 'keep-open'])),
|
|
13
|
+
});
|
|
14
|
+
export const CallIdentitySchema = Schema.Struct({
|
|
15
|
+
id: Schema.String,
|
|
16
|
+
sessionId: Schema.String,
|
|
17
|
+
generation: Schema.String,
|
|
18
|
+
});
|
|
19
|
+
export const CallEndReasonSchema = Schema.Struct({
|
|
20
|
+
code: Schema.String,
|
|
21
|
+
message: Schema.String,
|
|
22
|
+
source: Schema.Literals(['local', 'media', 'license', 'session', 'whatsapp']),
|
|
23
|
+
});
|
|
24
|
+
export const CallSnapshotSchema = Schema.Struct({
|
|
25
|
+
...CallIdentitySchema.fields,
|
|
26
|
+
peer: Schema.String,
|
|
27
|
+
state: Schema.String,
|
|
28
|
+
direction: Schema.Literals(['incoming', 'outgoing']),
|
|
29
|
+
video: Schema.Boolean,
|
|
30
|
+
terminal: Schema.Boolean,
|
|
31
|
+
observedAt: Schema.Number,
|
|
32
|
+
endReason: Schema.optional(CallEndReasonSchema),
|
|
33
|
+
media: Schema.optional(Schema.Struct({ state: Schema.Literals(['attached', 'ended']), reason: Schema.optional(Schema.String) })),
|
|
34
|
+
});
|
|
35
|
+
export const CallReasonSchema = Schema.Struct({ code: Schema.String, message: Schema.String, status: Schema.Number });
|
|
36
|
+
export const CallActionResultSchema = Schema.Union([
|
|
37
|
+
Schema.Struct({ ok: Schema.Literal(true), status: Schema.Literal('requested'), callId: Schema.optional(Schema.String) }),
|
|
38
|
+
Schema.Struct({ ok: Schema.Literal(false), status: Schema.Literals(['unavailable', 'failed', 'unknown']), reason: CallReasonSchema, callId: Schema.optional(Schema.String) }),
|
|
39
|
+
]);
|
|
40
|
+
export const CallCapabilitiesSchema = Schema.Struct({
|
|
41
|
+
control: Schema.Boolean, audio: Schema.Boolean, video: Schema.Boolean,
|
|
42
|
+
reason: Schema.optional(CallReasonSchema),
|
|
43
|
+
});
|
|
44
|
+
export type CallIdentity = typeof CallIdentitySchema.Type;
|
|
45
|
+
export type CallSnapshot = typeof CallSnapshotSchema.Type;
|
|
46
|
+
export type CallEndReason = typeof CallEndReasonSchema.Type;
|
|
47
|
+
export type CallActionResult = typeof CallActionResultSchema.Type;
|
|
48
|
+
export type CallCapabilities = typeof CallCapabilitiesSchema.Type;
|
|
49
|
+
export type CallAudioObserver = { ok: true; status: 'attached'; stop(): Promise<void> };
|
|
50
|
+
|
|
51
|
+
/** Methods are hydrated locally; transports carry only CallSnapshot. */
|
|
52
|
+
export interface Call extends CallSnapshot {
|
|
53
|
+
accept(microphone?: AudioInput | CallMediaOptions, speaker?: AudioOutput, camera?: VideoInput): Promise<CallActionResult>;
|
|
54
|
+
reject(): Promise<CallActionResult>;
|
|
55
|
+
end(): Promise<CallActionResult>;
|
|
56
|
+
mute(): Promise<CallActionResult>;
|
|
57
|
+
unmute(): Promise<CallActionResult>;
|
|
58
|
+
clearAudio(): Promise<CallActionResult>;
|
|
59
|
+
setMedia(options: CallMediaOptions): Promise<CallActionResult>;
|
|
60
|
+
observeAudio(speaker: AudioOutput): Promise<CallAudioObserver | Exclude<CallActionResult, { ok: true }>>;
|
|
61
|
+
}
|
package/src/common-types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { WhatsAppEventRegistrySchema } from './whatsapp-event-registry';
|
|
2
3
|
|
|
3
4
|
// Aliases
|
|
4
5
|
export const ContactIdSchema = z.string().brand('ContactId').describe('Opaque WhatsApp contact identifier. Preserve the exact value returned by the API.');
|
|
@@ -54,6 +55,9 @@ export enum MessageTypes {
|
|
|
54
55
|
VOICE = 'ptt',
|
|
55
56
|
IMAGE = 'image',
|
|
56
57
|
VIDEO = 'video',
|
|
58
|
+
ALBUM = 'album',
|
|
59
|
+
EVENT_CREATION = 'event_creation',
|
|
60
|
+
EVENT_RESPONSE = 'event_response',
|
|
57
61
|
DOCUMENT = 'document',
|
|
58
62
|
STICKER = 'sticker',
|
|
59
63
|
LOCATION = 'location',
|
|
@@ -79,6 +83,8 @@ export enum MessageAck {
|
|
|
79
83
|
* An enum of all the "simple listeners". A simple listener is a listener that just takes one parameter which is the callback function to handle the event.
|
|
80
84
|
*/
|
|
81
85
|
export enum SimpleListener {
|
|
86
|
+
Event = 'onEvent',
|
|
87
|
+
EventResponse = 'onEventResponse',
|
|
82
88
|
/**
|
|
83
89
|
* Represents [[onMessage]]
|
|
84
90
|
*/
|
|
@@ -180,6 +186,16 @@ const MessageSchemaBase = z.object({
|
|
|
180
186
|
labels: z.array(z.string()).optional(),
|
|
181
187
|
mentionedJidList: z.array(ContactIdSchema).optional(),
|
|
182
188
|
caption: z.string().optional(),
|
|
189
|
+
event: WhatsAppEventRegistrySchema.optional(),
|
|
190
|
+
expectedImageCount: z.number().int().nonnegative().nullable().optional()
|
|
191
|
+
.describe('Number of image messages declared by an album container; not a received-media count.'),
|
|
192
|
+
expectedVideoCount: z.number().int().nonnegative().nullable().optional()
|
|
193
|
+
.describe('Number of video messages declared by an album container, including GIF videos.'),
|
|
194
|
+
parentMsgKey: MessageIdSchema.nullable().optional()
|
|
195
|
+
.describe('Serialized parent message ID for associated media.'),
|
|
196
|
+
associationType: z.string().nullable().optional()
|
|
197
|
+
.describe('WhatsApp association type. Album media uses MEDIA_ALBUM.'),
|
|
198
|
+
isGif: z.boolean().optional(),
|
|
183
199
|
sender: z.any(), // Circular reference handled later/lazy
|
|
184
200
|
timestamp: z.number(),
|
|
185
201
|
content: z.string(),
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
type JsonSchema = { $ref?: string; type?: string; const?: unknown; enum?: unknown[]; anyOf?: JsonSchema[]; oneOf?: JsonSchema[]; properties?: Record<string, JsonSchema>; required?: string[]; items?: JsonSchema; additionalProperties?: boolean | JsonSchema; minimum?: number; maximum?: number; exclusiveMinimum?: number; exclusiveMaximum?: number; minLength?: number; maxLength?: number };
|
|
5
|
+
|
|
6
|
+
/** Project Effect contracts into the serving method and listener registry. */
|
|
7
|
+
export function projectEffectSchema<S extends Schema.Top>(schema: S): z.ZodType<S['Type'], S['Encoded']> {
|
|
8
|
+
// JSON codec generation maps undefined to null. Project Struct fields from
|
|
9
|
+
// their original schemas so optional properties retain their JS semantics.
|
|
10
|
+
if ('fields' in schema) {
|
|
11
|
+
const fields = schema.fields as Record<string, Schema.Top>;
|
|
12
|
+
const shape = Object.fromEntries(Object.entries(fields).map(([name, field]) => {
|
|
13
|
+
const optional = field.ast.context?.isOptional === true;
|
|
14
|
+
const hasUndefined = field.ast._tag === 'Union' && field.ast.types.some(member => member._tag === 'Undefined');
|
|
15
|
+
const valueSchema = !optional ? field : hasUndefined
|
|
16
|
+
? Schema.required(field as Schema.optional<Schema.Top>)
|
|
17
|
+
: Schema.requiredKey(field as Schema.optionalKey<Schema.Top>);
|
|
18
|
+
const value = projectEffectSchema(valueSchema);
|
|
19
|
+
return [name, optional ? value.optional() : value];
|
|
20
|
+
}));
|
|
21
|
+
return z.object(shape) as z.ZodType<S['Type'], S['Encoded']>;
|
|
22
|
+
}
|
|
23
|
+
const document = Schema.toJsonSchemaDocument(schema);
|
|
24
|
+
const project = (node: JsonSchema): z.ZodType => {
|
|
25
|
+
if (node.$ref) {
|
|
26
|
+
const key = node.$ref.split('/').at(-1)!;
|
|
27
|
+
return project(document.definitions[key] as JsonSchema);
|
|
28
|
+
}
|
|
29
|
+
if ('const' in node) return z.literal(node.const as string | number | boolean | null);
|
|
30
|
+
if (node.enum) return z.union(node.enum.map(value => z.literal(value as string | number | boolean | null)));
|
|
31
|
+
const members = node.anyOf ?? node.oneOf;
|
|
32
|
+
if (members) return z.union(members.map(project));
|
|
33
|
+
switch (node.type) {
|
|
34
|
+
case 'string': {
|
|
35
|
+
let value = z.string();
|
|
36
|
+
if (node.minLength !== undefined) value = value.min(node.minLength);
|
|
37
|
+
if (node.maxLength !== undefined) value = value.max(node.maxLength);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
case 'number':
|
|
41
|
+
case 'integer': {
|
|
42
|
+
let value = node.type === 'integer' ? z.number().int() : z.number();
|
|
43
|
+
if (node.minimum !== undefined) value = value.min(node.minimum);
|
|
44
|
+
if (node.maximum !== undefined) value = value.max(node.maximum);
|
|
45
|
+
if (node.exclusiveMinimum !== undefined) value = value.gt(node.exclusiveMinimum);
|
|
46
|
+
if (node.exclusiveMaximum !== undefined) value = value.lt(node.exclusiveMaximum);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
case 'boolean': return z.boolean();
|
|
50
|
+
case 'null': return z.null();
|
|
51
|
+
case 'array': return z.array(project(node.items ?? {}));
|
|
52
|
+
case 'object': {
|
|
53
|
+
const properties = node.properties ?? {};
|
|
54
|
+
const values = typeof node.additionalProperties === 'object' ? project(node.additionalProperties) : node.additionalProperties ? z.unknown() : undefined;
|
|
55
|
+
if (!Object.keys(properties).length && values) return z.record(z.string(), values);
|
|
56
|
+
const required = new Set(node.required ?? []);
|
|
57
|
+
const object = z.object(Object.fromEntries(Object.entries(properties).map(([key, value]) => {
|
|
58
|
+
const field = project(value);
|
|
59
|
+
return [key, required.has(key) ? field : field.optional()];
|
|
60
|
+
})));
|
|
61
|
+
return values ? object.catchall(values) : object;
|
|
62
|
+
}
|
|
63
|
+
default: return z.unknown();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return project(document.schema as JsonSchema) as z.ZodType<S['Type'], S['Encoded']>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CallSnapshotSchema } from '../calling';
|
|
2
|
+
import { projectEffectSchema } from '../effect-projection';
|
|
3
|
+
import { defineListenerV2 } from './registry';
|
|
4
|
+
|
|
5
|
+
export const incomingCallEvent = defineListenerV2('incomingCall', {
|
|
6
|
+
legacyName: 'onIncomingCall', meta: { namespace: 'calls', license: 'restricted', status: 'experimental', description: 'A native incoming call. The SDK hydrates its bound controls.' },
|
|
7
|
+
payload: projectEffectSchema(CallSnapshotSchema), defaultQueueOptions: { capacity: 32, concurrency: 1 },
|
|
8
|
+
});
|
|
9
|
+
export const callStateEvent = defineListenerV2('callState', {
|
|
10
|
+
legacyName: 'onCallState', meta: { namespace: 'calls', license: 'restricted', status: 'experimental', description: 'Observed native call state, including unknown states.' },
|
|
11
|
+
payload: projectEffectSchema(CallSnapshotSchema), defaultQueueOptions: { capacity: 64, concurrency: 1 },
|
|
12
|
+
});
|
package/src/events/groups.ts
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { defineListenerV2 } from './registry';
|
|
3
|
+
import { ContactIdSchema, GroupIdSchema } from '../common-types';
|
|
4
|
+
|
|
5
|
+
const participantChatIdSchema = z.union([
|
|
6
|
+
GroupIdSchema,
|
|
7
|
+
z.object({ _serialized: GroupIdSchema }).passthrough(),
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
export const ParticipantChangeSchema = z.object({
|
|
11
|
+
groupId: GroupIdSchema,
|
|
12
|
+
action: z.enum(['add', 'remove', 'promote', 'demote', 'invite', 'leave']),
|
|
13
|
+
participantIds: z.array(ContactIdSchema),
|
|
14
|
+
by: z.string().optional(),
|
|
15
|
+
who: ContactIdSchema.optional(),
|
|
16
|
+
chat: participantChatIdSchema.optional(),
|
|
17
|
+
}).passthrough();
|
|
18
|
+
export type ParticipantChange = z.infer<typeof ParticipantChangeSchema>;
|
|
19
|
+
|
|
20
|
+
/** Adapt the existing patch callback without replacing its native listener. */
|
|
21
|
+
export const ParticipantChangePatchSchema = z.object({
|
|
22
|
+
action: ParticipantChangeSchema.shape.action,
|
|
23
|
+
who: ContactIdSchema,
|
|
24
|
+
chat: participantChatIdSchema,
|
|
25
|
+
by: z.string().optional(),
|
|
26
|
+
}).passthrough().transform(change => ({
|
|
27
|
+
...change,
|
|
28
|
+
groupId: typeof change.chat === 'string' ? change.chat : change.chat._serialized,
|
|
29
|
+
participantIds: [change.who],
|
|
30
|
+
})).pipe(ParticipantChangeSchema);
|
|
3
31
|
|
|
4
32
|
export const participantsChangedEvent = defineListenerV2('participantsChanged', {
|
|
5
33
|
legacyName: 'onParticipantsChanged',
|
|
@@ -8,13 +36,9 @@ export const participantsChangedEvent = defineListenerV2('participantsChanged',
|
|
|
8
36
|
namespace: 'groups',
|
|
9
37
|
status: 'stable',
|
|
10
38
|
license: 'none',
|
|
39
|
+
aliases: ['onGlobalParticipantsChanged'],
|
|
11
40
|
},
|
|
12
|
-
payload:
|
|
13
|
-
groupId: z.string(),
|
|
14
|
-
action: z.enum(['add', 'remove', 'promote', 'demote']),
|
|
15
|
-
participantIds: z.array(z.string()),
|
|
16
|
-
by: z.string().optional(),
|
|
17
|
-
}),
|
|
41
|
+
payload: ParticipantChangeSchema,
|
|
18
42
|
});
|
|
19
43
|
|
|
20
44
|
export const addedToGroupEvent = defineListenerV2('addedToGroup', {
|
package/src/events/index.ts
CHANGED
package/src/events/messaging.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { InteractiveResponseSchema, FormResponseSchema } from '../interactive';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { defineListenerV2 } from './registry';
|
|
4
|
-
import { MessageSchema
|
|
4
|
+
import { MessageSchema } from '../common-types';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// Acknowledgements carry a message snapshot. Validate the delivery identity but
|
|
7
|
+
// retain every message field, including fields absent from the static schema.
|
|
8
|
+
// Requiring all received-message fields would discard updates for partially
|
|
9
|
+
// loaded messages in WhatsApp's store.
|
|
10
|
+
const AckSchema = MessageSchema.pick({ id: true, ack: true }).passthrough()
|
|
11
|
+
.describe('The full available message snapshot at acknowledgement time, including id, ack, body, sender and chat when supplied by WhatsApp.');
|
|
12
12
|
|
|
13
13
|
export const messageEvent = defineListenerV2('message', {
|
|
14
14
|
legacyName: 'onMessage',
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PollVoteSchema } from '../polls';
|
|
2
|
+
import { defineListenerV2 } from './registry';
|
|
3
|
+
|
|
4
|
+
export const pollVoteEvent = defineListenerV2('pollVote', {
|
|
5
|
+
legacyName: 'onPollVote',
|
|
6
|
+
meta: {
|
|
7
|
+
namespace: 'messages', license: 'none', status: 'beta',
|
|
8
|
+
description: 'A decrypted poll vote added or changed in the synced store. Hydration can emit old votes. Hidden-voter polls omit sender and message identifiers. Deduplicate ordinary votes by id and timestamp; refresh getPollResults for current totals.',
|
|
9
|
+
},
|
|
10
|
+
payload: PollVoteSchema, defaultQueueOptions: { concurrency: 1 },
|
|
11
|
+
});
|
package/src/events/registry.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type EventStatus = 'stable' | 'beta' | 'deprecated' | 'experimental';
|
|
|
18
18
|
export interface EventMetadata {
|
|
19
19
|
eventName: string;
|
|
20
20
|
legacyName: string;
|
|
21
|
+
aliases?: string[];
|
|
21
22
|
description?: string;
|
|
22
23
|
namespace?: string;
|
|
23
24
|
status?: EventStatus;
|
|
@@ -56,7 +57,7 @@ export const eventRegistry = {
|
|
|
56
57
|
|
|
57
58
|
getByLegacyName(legacyName: string): EventDefinition | undefined {
|
|
58
59
|
for (const def of eventsByName.values()) {
|
|
59
|
-
if (def.meta.legacyName === legacyName) return def;
|
|
60
|
+
if (def.meta.legacyName === legacyName || def.meta.aliases?.includes(legacyName)) return def;
|
|
60
61
|
}
|
|
61
62
|
return undefined;
|
|
62
63
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WhatsAppEventRegistrySchema, EventResponseRegistrySchema } from '../whatsapp-event-registry';
|
|
2
|
+
import { defineListenerV2 } from './registry';
|
|
3
|
+
|
|
4
|
+
export const whatsappEvent = defineListenerV2('event', {
|
|
5
|
+
legacyName: 'onEvent',
|
|
6
|
+
meta: { namespace: 'events', license: 'none', status: 'beta', description: 'A native event added or changed in the synced message store, including this account’s events.' },
|
|
7
|
+
payload: WhatsAppEventRegistrySchema, defaultQueueOptions: { concurrency: 1 },
|
|
8
|
+
});
|
|
9
|
+
export const eventResponseEvent = defineListenerV2('eventResponse', {
|
|
10
|
+
legacyName: 'onEventResponse',
|
|
11
|
+
meta: { namespace: 'events', license: 'none', status: 'beta', description: 'A decrypted RSVP added or changed in WhatsApp’s dedicated event-response collection. History loads may emit responses too; deduplicate by id and timestamp.' },
|
|
12
|
+
payload: EventResponseRegistrySchema, defaultQueueOptions: { concurrency: 1 },
|
|
13
|
+
});
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Do not edit this file manually.
|
|
5
5
|
*/
|
|
6
6
|
export const clientMethodAliasMap = {
|
|
7
|
+
"messages.sendSticker": "sendSticker",
|
|
8
|
+
"messages.sendAlbum": "sendAlbum",
|
|
7
9
|
"messages.sendText": "sendText",
|
|
8
10
|
"messages.sendTextWithMentions": "sendTextWithMentions",
|
|
9
11
|
"messages.sendReplyWithMentions": "sendReplyWithMentions",
|
|
@@ -26,6 +28,10 @@ export const clientMethodAliasMap = {
|
|
|
26
28
|
"sendList": "sendListMessage",
|
|
27
29
|
"messages.sendList": "sendListMessage",
|
|
28
30
|
"messages.sendPoll": "sendPoll",
|
|
31
|
+
"messages.voteOnPoll": "voteOnPoll",
|
|
32
|
+
"messages.getPollResults": "getPollResults",
|
|
33
|
+
"messages.pin": "pinMessage",
|
|
34
|
+
"messages.unpin": "unpinMessage",
|
|
29
35
|
"messages.sendBanner": "sendBanner",
|
|
30
36
|
"sendYoutubeLink": "sendYouTubeLink",
|
|
31
37
|
"messages.sendYouTubeLink": "sendYouTubeLink",
|
|
@@ -41,6 +47,7 @@ export const clientMethodAliasMap = {
|
|
|
41
47
|
"getMessage": "getMessageById",
|
|
42
48
|
"messages.get": "getMessageById",
|
|
43
49
|
"messages.getById": "getMessageById",
|
|
50
|
+
"messages.getAlbum": "getAlbumMessages",
|
|
44
51
|
"listMessages": "getAllMessages",
|
|
45
52
|
"messages.getAll": "getAllMessages",
|
|
46
53
|
"messages.all": "getAllMessages",
|
|
@@ -55,6 +62,7 @@ export const clientMethodAliasMap = {
|
|
|
55
62
|
"messages.getGptArray": "getMessagesForLLM",
|
|
56
63
|
"messages.star": "starMessage",
|
|
57
64
|
"messages.unstar": "unstarMessage",
|
|
65
|
+
"messages.edit": "editMessage",
|
|
58
66
|
"messages.react": "react",
|
|
59
67
|
"messages.sendSeen": "sendSeen",
|
|
60
68
|
"loadOlderMessages": "loadEarlierMessages",
|
|
@@ -86,6 +94,8 @@ export const clientMethodAliasMap = {
|
|
|
86
94
|
"chats.markAsUnread": "markAsUnread",
|
|
87
95
|
"chats.setEphemeral": "setChatEphemeral",
|
|
88
96
|
"chats.isOnline": "isChatOnline",
|
|
97
|
+
"contacts.requestPhoneNumber": "requestPhoneNumber",
|
|
98
|
+
"contacts.sharePhoneNumber": "sharePhoneNumber",
|
|
89
99
|
"listContacts": "getAllContacts",
|
|
90
100
|
"contacts.getAll": "getAllContacts",
|
|
91
101
|
"contacts.all": "getAllContacts",
|
|
@@ -187,6 +197,7 @@ export const clientMethodAliasMap = {
|
|
|
187
197
|
"session.getIsPlugged": "isPlugged",
|
|
188
198
|
"session.getFeatures": "getFeatures",
|
|
189
199
|
"session.getLicenseType": "getLicenseType",
|
|
200
|
+
"session.getLicenseFeatures": "getLicenseFeatures",
|
|
190
201
|
"getGeneratedUserAgent": "getUserAgent",
|
|
191
202
|
"session.getUserAgent": "getUserAgent",
|
|
192
203
|
"session.getGeneratedUserAgent": "getUserAgent",
|
|
@@ -212,5 +223,23 @@ export const clientMethodAliasMap = {
|
|
|
212
223
|
"media.decrypt": "decryptMedia",
|
|
213
224
|
"media.download": "downloadMedia",
|
|
214
225
|
"messages.sendInteractive": "sendInteractive",
|
|
215
|
-
"messages.sendRaw": "sendRawMessage"
|
|
226
|
+
"messages.sendRaw": "sendRawMessage",
|
|
227
|
+
"calls.getCallCapabilities": "getCallCapabilities",
|
|
228
|
+
"calls.getActiveCall": "getActiveCall",
|
|
229
|
+
"calls.acceptCall": "acceptCall",
|
|
230
|
+
"calls.startCall": "startCall",
|
|
231
|
+
"calls.rejectCall": "rejectCall",
|
|
232
|
+
"calls.endCall": "endCall",
|
|
233
|
+
"calls.muteCall": "muteCall",
|
|
234
|
+
"calls.clearCallAudio": "clearCallAudio",
|
|
235
|
+
"calls.setCallMedia": "setCallMedia",
|
|
236
|
+
"calls.observeCallAudio": "observeCallAudio",
|
|
237
|
+
"calls.stopCallAudioObserver": "stopCallAudioObserver",
|
|
238
|
+
"events.sendEvent": "sendEvent",
|
|
239
|
+
"events.getEvent": "getEvent",
|
|
240
|
+
"events.get": "getEvents",
|
|
241
|
+
"events.getEventResponses": "getEventResponses",
|
|
242
|
+
"events.editEvent": "editEvent",
|
|
243
|
+
"events.cancelEvent": "cancelEvent",
|
|
244
|
+
"events.respondToEvent": "respondToEvent"
|
|
216
245
|
} as const;
|