@open-wa/schema 5.4.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.
Files changed (74) hide show
  1. package/dist/calling-media--BLrFrPc.cjs +113 -0
  2. package/dist/calling-media--BLrFrPc.cjs.map +1 -0
  3. package/dist/calling-media-BNTYvogE.mjs +60 -0
  4. package/dist/calling-media-BNTYvogE.mjs.map +1 -0
  5. package/dist/calling-media-CeGgSzhw.d.cts +48 -0
  6. package/dist/calling-media-CeGgSzhw.d.cts.map +1 -0
  7. package/dist/calling-media-CeGgSzhw.d.mts +48 -0
  8. package/dist/calling-media-CeGgSzhw.d.mts.map +1 -0
  9. package/dist/calling-media.cjs +8 -0
  10. package/dist/calling-media.d.cts +2 -0
  11. package/dist/calling-media.d.mts +2 -0
  12. package/dist/calling-media.mjs +2 -0
  13. package/dist/generated/index.cjs +94 -3
  14. package/dist/generated/index.cjs.map +1 -1
  15. package/dist/generated/index.d.cts +2328 -133
  16. package/dist/generated/index.d.cts.map +1 -1
  17. package/dist/generated/index.d.mts +2328 -133
  18. package/dist/generated/index.d.mts.map +1 -1
  19. package/dist/generated/index.mjs +94 -3
  20. package/dist/generated/index.mjs.map +1 -1
  21. package/dist/{index-C9Ad0lEr.d.cts → index-BWvNXopK.d.cts} +2375 -41
  22. package/dist/index-BWvNXopK.d.cts.map +1 -0
  23. package/dist/{index-D0QN2PaW.d.mts → index-Co8HQxm8.d.mts} +2375 -41
  24. package/dist/index-Co8HQxm8.d.mts.map +1 -0
  25. package/dist/index.cjs +191 -20
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +3 -2
  28. package/dist/index.d.mts +3 -2
  29. package/dist/index.mjs +105 -21
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/methods/index.cjs +34 -1
  32. package/dist/methods/index.d.cts +2 -2
  33. package/dist/methods/index.d.mts +2 -2
  34. package/dist/methods/index.mjs +2 -2
  35. package/dist/{methods-BhLsQNtL.mjs → methods-BH7nDC3z.mjs} +816 -51
  36. package/dist/methods-BH7nDC3z.mjs.map +1 -0
  37. package/dist/{methods-BGmdzjd3.cjs → methods-DpDzgsbe.cjs} +1284 -63
  38. package/dist/methods-DpDzgsbe.cjs.map +1 -0
  39. package/package.json +15 -4
  40. package/src/calling-media.ts +64 -0
  41. package/src/calling-wire.ts +17 -0
  42. package/src/calling.ts +61 -0
  43. package/src/common-types.ts +16 -0
  44. package/src/effect-projection.ts +67 -0
  45. package/src/events/calls.ts +12 -0
  46. package/src/events/groups.ts +30 -6
  47. package/src/events/index.ts +4 -0
  48. package/src/events/messaging.ts +7 -7
  49. package/src/events/polls.ts +11 -0
  50. package/src/events/registry.ts +2 -1
  51. package/src/events/whatsapp-events.ts +13 -0
  52. package/src/generated/AliasMap.ts +30 -1
  53. package/src/generated/BaseClient.ts +153 -8
  54. package/src/generated/BaseNamespacedClient.ts +36 -1
  55. package/src/generated/openapi.json +22999 -12765
  56. package/src/generated/types.ts +87 -0
  57. package/src/index.ts +10 -0
  58. package/src/license.ts +10 -0
  59. package/src/media-options.ts +46 -0
  60. package/src/methods/calls.ts +23 -0
  61. package/src/methods/contacts.ts +10 -1
  62. package/src/methods/groups.ts +9 -3
  63. package/src/methods/index.ts +2 -0
  64. package/src/methods/messaging.ts +159 -45
  65. package/src/methods/session.ts +10 -0
  66. package/src/methods/whatsapp-events.ts +35 -0
  67. package/src/polls.ts +37 -0
  68. package/src/session-refresh.ts +15 -0
  69. package/src/whatsapp-event-registry.ts +17 -0
  70. package/src/whatsapp-events.ts +91 -0
  71. package/dist/index-C9Ad0lEr.d.cts.map +0 -1
  72. package/dist/index-D0QN2PaW.d.mts.map +0 -1
  73. package/dist/methods-BGmdzjd3.cjs.map +0 -1
  74. package/dist/methods-BhLsQNtL.mjs.map +0 -1
@@ -7,6 +7,12 @@
7
7
  import type * as Zod from 'zod';
8
8
  import type * as Methods from '../methods';
9
9
 
10
+ export type SendStickerInput = Zod.input<typeof Methods.sendSticker.openWAInput>;
11
+ export type SendStickerOutput = Zod.output<typeof Methods.sendSticker.openWAOutput>;
12
+
13
+ export type SendAlbumInput = Zod.input<typeof Methods.sendAlbum.openWAInput>;
14
+ export type SendAlbumOutput = Zod.output<typeof Methods.sendAlbum.openWAOutput>;
15
+
10
16
  export type SendTextInput = Zod.input<typeof Methods.sendText.openWAInput>;
11
17
  export type SendTextOutput = Zod.output<typeof Methods.sendText.openWAOutput>;
12
18
 
@@ -58,6 +64,18 @@ export type SendListMessageOutput = Zod.output<typeof Methods.sendListMessage.op
58
64
  export type SendPollInput = Zod.input<typeof Methods.sendPoll.openWAInput>;
59
65
  export type SendPollOutput = Zod.output<typeof Methods.sendPoll.openWAOutput>;
60
66
 
67
+ export type VoteOnPollInput = Zod.input<typeof Methods.voteOnPoll.openWAInput>;
68
+ export type VoteOnPollOutput = Zod.output<typeof Methods.voteOnPoll.openWAOutput>;
69
+
70
+ export type GetPollResultsInput = Zod.input<typeof Methods.getPollResults.openWAInput>;
71
+ export type GetPollResultsOutput = Zod.output<typeof Methods.getPollResults.openWAOutput>;
72
+
73
+ export type PinMessageInput = Zod.input<typeof Methods.pinMessage.openWAInput>;
74
+ export type PinMessageOutput = Zod.output<typeof Methods.pinMessage.openWAOutput>;
75
+
76
+ export type UnpinMessageInput = Zod.input<typeof Methods.unpinMessage.openWAInput>;
77
+ export type UnpinMessageOutput = Zod.output<typeof Methods.unpinMessage.openWAOutput>;
78
+
61
79
  export type SendBannerInput = Zod.input<typeof Methods.sendBanner.openWAInput>;
62
80
  export type SendBannerOutput = Zod.output<typeof Methods.sendBanner.openWAOutput>;
63
81
 
@@ -79,6 +97,9 @@ export type DeleteMessageOutput = Zod.output<typeof Methods.deleteMessage.openWA
79
97
  export type GetMessageByIdInput = Zod.input<typeof Methods.getMessageById.openWAInput>;
80
98
  export type GetMessageByIdOutput = Zod.output<typeof Methods.getMessageById.openWAOutput>;
81
99
 
100
+ export type GetAlbumMessagesInput = Zod.input<typeof Methods.getAlbumMessages.openWAInput>;
101
+ export type GetAlbumMessagesOutput = Zod.output<typeof Methods.getAlbumMessages.openWAOutput>;
102
+
82
103
  export type GetAllMessagesInput = Zod.input<typeof Methods.getAllMessages.openWAInput>;
83
104
  export type GetAllMessagesOutput = Zod.output<typeof Methods.getAllMessages.openWAOutput>;
84
105
 
@@ -106,6 +127,9 @@ export type StarMessageOutput = Zod.output<typeof Methods.starMessage.openWAOutp
106
127
  export type UnstarMessageInput = Zod.input<typeof Methods.unstarMessage.openWAInput>;
107
128
  export type UnstarMessageOutput = Zod.output<typeof Methods.unstarMessage.openWAOutput>;
108
129
 
130
+ export type EditMessageInput = Zod.input<typeof Methods.editMessage.openWAInput>;
131
+ export type EditMessageOutput = Zod.output<typeof Methods.editMessage.openWAOutput>;
132
+
109
133
  export type ReactInput = Zod.input<typeof Methods.react.openWAInput>;
110
134
  export type ReactOutput = Zod.output<typeof Methods.react.openWAOutput>;
111
135
 
@@ -166,6 +190,12 @@ export type SetChatEphemeralOutput = Zod.output<typeof Methods.setChatEphemeral.
166
190
  export type IsChatOnlineInput = Zod.input<typeof Methods.isChatOnline.openWAInput>;
167
191
  export type IsChatOnlineOutput = Zod.output<typeof Methods.isChatOnline.openWAOutput>;
168
192
 
193
+ export type RequestPhoneNumberInput = Zod.input<typeof Methods.requestPhoneNumber.openWAInput>;
194
+ export type RequestPhoneNumberOutput = Zod.output<typeof Methods.requestPhoneNumber.openWAOutput>;
195
+
196
+ export type SharePhoneNumberInput = Zod.input<typeof Methods.sharePhoneNumber.openWAInput>;
197
+ export type SharePhoneNumberOutput = Zod.output<typeof Methods.sharePhoneNumber.openWAOutput>;
198
+
169
199
  export type GetAllContactsInput = Zod.input<typeof Methods.getAllContacts.openWAInput>;
170
200
  export type GetAllContactsOutput = Zod.output<typeof Methods.getAllContacts.openWAOutput>;
171
201
 
@@ -346,6 +376,9 @@ export type GetFeaturesOutput = Zod.output<typeof Methods.getFeatures.openWAOutp
346
376
  export type GetLicenseTypeInput = Zod.input<typeof Methods.getLicenseType.openWAInput>;
347
377
  export type GetLicenseTypeOutput = Zod.output<typeof Methods.getLicenseType.openWAOutput>;
348
378
 
379
+ export type GetLicenseFeaturesInput = Zod.input<typeof Methods.getLicenseFeatures.openWAInput>;
380
+ export type GetLicenseFeaturesOutput = Zod.output<typeof Methods.getLicenseFeatures.openWAOutput>;
381
+
349
382
  export type GetUserAgentInput = Zod.input<typeof Methods.getUserAgent.openWAInput>;
350
383
  export type GetUserAgentOutput = Zod.output<typeof Methods.getUserAgent.openWAOutput>;
351
384
 
@@ -381,3 +414,57 @@ export type SendInteractiveOutput = Zod.output<typeof Methods.sendInteractive.op
381
414
 
382
415
  export type SendRawMessageInput = Zod.input<typeof Methods.sendRawMessage.openWAInput>;
383
416
  export type SendRawMessageOutput = Zod.output<typeof Methods.sendRawMessage.openWAOutput>;
417
+
418
+ export type GetCallCapabilitiesInput = Zod.input<typeof Methods.getCallCapabilities.openWAInput>;
419
+ export type GetCallCapabilitiesOutput = Zod.output<typeof Methods.getCallCapabilities.openWAOutput>;
420
+
421
+ export type GetActiveCallInput = Zod.input<typeof Methods.getActiveCall.openWAInput>;
422
+ export type GetActiveCallOutput = Zod.output<typeof Methods.getActiveCall.openWAOutput>;
423
+
424
+ export type AcceptCallInput = Zod.input<typeof Methods.acceptCall.openWAInput>;
425
+ export type AcceptCallOutput = Zod.output<typeof Methods.acceptCall.openWAOutput>;
426
+
427
+ export type StartCallInput = Zod.input<typeof Methods.startCall.openWAInput>;
428
+ export type StartCallOutput = Zod.output<typeof Methods.startCall.openWAOutput>;
429
+
430
+ export type RejectCallInput = Zod.input<typeof Methods.rejectCall.openWAInput>;
431
+ export type RejectCallOutput = Zod.output<typeof Methods.rejectCall.openWAOutput>;
432
+
433
+ export type EndCallInput = Zod.input<typeof Methods.endCall.openWAInput>;
434
+ export type EndCallOutput = Zod.output<typeof Methods.endCall.openWAOutput>;
435
+
436
+ export type MuteCallInput = Zod.input<typeof Methods.muteCall.openWAInput>;
437
+ export type MuteCallOutput = Zod.output<typeof Methods.muteCall.openWAOutput>;
438
+
439
+ export type ClearCallAudioInput = Zod.input<typeof Methods.clearCallAudio.openWAInput>;
440
+ export type ClearCallAudioOutput = Zod.output<typeof Methods.clearCallAudio.openWAOutput>;
441
+
442
+ export type SetCallMediaInput = Zod.input<typeof Methods.setCallMedia.openWAInput>;
443
+ export type SetCallMediaOutput = Zod.output<typeof Methods.setCallMedia.openWAOutput>;
444
+
445
+ export type ObserveCallAudioInput = Zod.input<typeof Methods.observeCallAudio.openWAInput>;
446
+ export type ObserveCallAudioOutput = Zod.output<typeof Methods.observeCallAudio.openWAOutput>;
447
+
448
+ export type StopCallAudioObserverInput = Zod.input<typeof Methods.stopCallAudioObserver.openWAInput>;
449
+ export type StopCallAudioObserverOutput = Zod.output<typeof Methods.stopCallAudioObserver.openWAOutput>;
450
+
451
+ export type SendEventInput = Zod.input<typeof Methods.sendEvent.openWAInput>;
452
+ export type SendEventOutput = Zod.output<typeof Methods.sendEvent.openWAOutput>;
453
+
454
+ export type GetEventInput = Zod.input<typeof Methods.getEvent.openWAInput>;
455
+ export type GetEventOutput = Zod.output<typeof Methods.getEvent.openWAOutput>;
456
+
457
+ export type GetEventsInput = Zod.input<typeof Methods.getEvents.openWAInput>;
458
+ export type GetEventsOutput = Zod.output<typeof Methods.getEvents.openWAOutput>;
459
+
460
+ export type GetEventResponsesInput = Zod.input<typeof Methods.getEventResponses.openWAInput>;
461
+ export type GetEventResponsesOutput = Zod.output<typeof Methods.getEventResponses.openWAOutput>;
462
+
463
+ export type EditEventInput = Zod.input<typeof Methods.editEvent.openWAInput>;
464
+ export type EditEventOutput = Zod.output<typeof Methods.editEvent.openWAOutput>;
465
+
466
+ export type CancelEventInput = Zod.input<typeof Methods.cancelEvent.openWAInput>;
467
+ export type CancelEventOutput = Zod.output<typeof Methods.cancelEvent.openWAOutput>;
468
+
469
+ export type RespondToEventInput = Zod.input<typeof Methods.respondToEvent.openWAInput>;
470
+ export type RespondToEventOutput = Zod.output<typeof Methods.respondToEvent.openWAOutput>;
package/src/index.ts CHANGED
@@ -44,3 +44,13 @@ export {
44
44
  export * from './parameters';
45
45
  export * from './http-manifest';
46
46
  export * from './interactive';
47
+ export * from './calling';
48
+ export * from './calling-media';
49
+
50
+ export * from './calling-wire';
51
+ export * from './license';
52
+ export * from './whatsapp-events';
53
+
54
+ export * from './media-options';
55
+ export * from './polls';
56
+ export * from './session-refresh';
package/src/license.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { Schema } from 'effect';
2
+
3
+ /** Licence access selected by the server, distinct from WhatsApp feature flags. */
4
+ export const LicenseFeaturesSchema = Schema.Struct({
5
+ status: Schema.Literals(['valid', 'missing', 'invalid', 'expired', 'metadata_only']),
6
+ keyType: Schema.NullOr(Schema.String),
7
+ expiresAt: Schema.NullOr(Schema.Number),
8
+ features: Schema.Record(Schema.String, Schema.Boolean),
9
+ });
10
+ export type LicenseFeatures = typeof LicenseFeaturesSchema.Type;
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { MessageIdSchema } from './common-types';
3
+
4
+ const quote = { quotedMsgId: MessageIdSchema.optional().describe('A message in the destination chat to quote') };
5
+ const caption = { caption: z.string().optional().describe('Caption for the attachment') };
6
+ const viewOnce = { viewOnce: z.boolean().optional().describe('Use WhatsApp view-once media') };
7
+
8
+ export const ImageSendOptionsSchema = z.strictObject({
9
+ type: z.literal('image'), ...caption, ...quote, ...viewOnce,
10
+ });
11
+ export const VideoSendOptionsSchema = z.strictObject({
12
+ type: z.literal('video'), ...caption, ...quote, ...viewOnce,
13
+ isGif: z.boolean().optional().describe('Loop an MP4 as a WhatsApp GIF'),
14
+ videoNote: z.boolean().optional().describe('Send a square MP4, at most 60 seconds, as a circular video note (PTV)'),
15
+ }).superRefine((options, ctx) => {
16
+ if (options.videoNote && options.isGif) ctx.addIssue({ code: 'custom', path: ['isGif'], message: 'A video note cannot also be a GIF' });
17
+ if (options.isGif && options.viewOnce) ctx.addIssue({ code: 'custom', path: ['viewOnce'], message: 'A GIF cannot be view once' });
18
+ if (options.videoNote && options.caption) ctx.addIssue({ code: 'custom', path: ['caption'], message: 'Video notes do not support captions' });
19
+ });
20
+ export const AudioSendOptionsSchema = z.strictObject({
21
+ type: z.literal('audio'), ...quote, ...viewOnce,
22
+ ptt: z.boolean().optional().describe('Send audio as a voice note; does not transcode it'),
23
+ }).refine(options => !options.viewOnce || options.ptt === true, {
24
+ path: ['viewOnce'], message: 'View-once audio must be a voice note (ptt: true)',
25
+ });
26
+ export const DocumentSendOptionsSchema = z.strictObject({
27
+ type: z.literal('document'), ...caption, ...quote,
28
+ }).describe('Force document presentation, even for an image, video or audio file');
29
+ export const AutoMediaSendOptionsSchema = z.strictObject({
30
+ type: z.literal('auto').optional(), ...caption, ...quote, ...viewOnce,
31
+ }).describe('Detect presentation from the file MIME type; view once requires an image or video');
32
+ export const MediaSendOptionsSchema = z.discriminatedUnion('type', [
33
+ AutoMediaSendOptionsSchema, ImageSendOptionsSchema, VideoSendOptionsSchema,
34
+ AudioSendOptionsSchema, DocumentSendOptionsSchema,
35
+ ]);
36
+ export type MediaSendOptions = z.infer<typeof MediaSendOptionsSchema>;
37
+ export type ImageSendOptions = z.infer<typeof ImageSendOptionsSchema>;
38
+ export type VideoSendOptions = z.infer<typeof VideoSendOptionsSchema>;
39
+ export type AudioSendOptions = z.infer<typeof AudioSendOptionsSchema>;
40
+
41
+ export const AudioAttachmentOptionsSchema = z.strictObject({ ...quote });
42
+ export const VoiceNoteOptionsSchema = z.strictObject({ ...quote, ...viewOnce });
43
+ export const GifSendOptionsSchema = z.strictObject({ ...caption, ...quote });
44
+ export type AudioAttachmentOptions = z.infer<typeof AudioAttachmentOptionsSchema>;
45
+ export type VoiceNoteOptions = z.infer<typeof VoiceNoteOptionsSchema>;
46
+ export type GifSendOptions = z.infer<typeof GifSendOptionsSchema>;
@@ -0,0 +1,23 @@
1
+ import { Schema } from 'effect';
2
+ import { z } from 'zod';
3
+ import { defineMethodV2 } from '../registry';
4
+ import { projectEffectSchema } from '../effect-projection';
5
+ import { CallActionResultSchema, CallCapabilitiesSchema, CallMediaOptionsSchema, CallIdentitySchema, CallSnapshotSchema } from '../calling';
6
+
7
+ const media = Schema.optional(Schema.Unknown);
8
+ const actionInput = Schema.Struct({ call: CallIdentitySchema, media: Schema.optional(CallMediaOptionsSchema) });
9
+ const register = (name: string, input: Schema.Top, output: Schema.Top, parameters: string[], description: string) => defineMethodV2(name, {
10
+ meta: { namespace: 'calls', action: 'update', httpMethod: 'POST', license: name === 'getCallCapabilities' ? 'none' : 'restricted', functionality: 'both', description },
11
+ input: projectEffectSchema(input) as z.ZodObject<any>, parameterOrder: parameters, output: projectEffectSchema(output),
12
+ });
13
+ export const getCallCapabilities = register('getCallCapabilities', Schema.Struct({}), CallCapabilitiesSchema, [], 'Optional calling availability for UI and diagnostics. Actions perform admission automatically.');
14
+ export const getActiveCall = register('getActiveCall', Schema.Struct({}), Schema.NullOr(CallSnapshotSchema), [], 'Get the current call snapshot. SDK clients hydrate its bound methods.');
15
+ export const acceptCall = register('acceptCall', actionInput, CallActionResultSchema, ['call', 'media'], 'Prepare media and accept this incoming call.');
16
+ export const startCall = register('startCall', Schema.Struct({ to: Schema.String, microphone: media, speaker: media, camera: media }), CallActionResultSchema, ['to', 'microphone', 'speaker', 'camera'], 'Prepare media and place an outgoing audio or video call.');
17
+ export const rejectCall = register('rejectCall', Schema.Struct({ call: CallIdentitySchema }), CallActionResultSchema, ['call'], 'Reject this call with native state confirmation.');
18
+ export const endCall = register('endCall', Schema.Struct({ call: CallIdentitySchema }), CallActionResultSchema, ['call'], 'Request hangup for this call.');
19
+ export const muteCall = register('muteCall', Schema.Struct({ call: CallIdentitySchema, muted: Schema.Boolean }), CallActionResultSchema, ['call', 'muted'], 'Mute or unmute the microphone without ending reception.');
20
+ export const clearCallAudio = register('clearCallAudio', Schema.Struct({ call: CallIdentitySchema }), CallActionResultSchema, ['call'], 'Discard queued outgoing audio.');
21
+ export const setCallMedia = register('setCallMedia', actionInput, CallActionResultSchema, ['call', 'media'], 'Prepare a replacement before releasing the working media.');
22
+ export const observeCallAudio = register('observeCallAudio', Schema.Struct({ call: CallIdentitySchema, speaker: Schema.Unknown }), Schema.Union([Schema.Struct({ ok: Schema.Literal(true), status: Schema.Literal('requested'), observerId: Schema.String }), CallActionResultSchema]), ['call', 'speaker'], 'Attach an isolated receive-only audio sink. Its failure does not interrupt the call owner.');
23
+ export const stopCallAudioObserver = register('stopCallAudioObserver', Schema.Struct({ call: CallIdentitySchema, observerId: Schema.String }), CallActionResultSchema, ['call', 'observerId'], 'Stop an audio observer and finalize its sink.');
@@ -2,7 +2,16 @@ import { ContactIdSchema, ContactSchema } from '../common-types';
2
2
  import { CommonGroupSchema, NumberCheckSchema, NumberProfileSchema } from '../return-types';
3
3
  import { z } from 'zod';
4
4
  import { defineMethodV2 } from '../registry';
5
- import { chatIdParam, contactIdParam } from '../parameters';
5
+ import { chatIdParam, contactIdParam, toParam, messageIdParam } from '../parameters';
6
+
7
+ export const requestPhoneNumber = defineMethodV2('requestPhoneNumber', {
8
+ meta: { description: 'Ask a direct LID chat to voluntarily share their phone number. A submitted request does not confirm sharing.', action: 'send', namespace: 'contacts', license: 'none', functionality: 'both', httpMethod: 'POST' },
9
+ input: z.object({ to: toParam }), parameterOrder: ['to'], output: messageIdParam,
10
+ });
11
+ export const sharePhoneNumber = defineMethodV2('sharePhoneNumber', {
12
+ meta: { description: 'Share the signed-in account’s own phone number with a direct LID chat using WhatsApp’s native protocol. No arbitrary phone number is accepted.', action: 'send', namespace: 'contacts', license: 'none', functionality: 'both', httpMethod: 'POST' },
13
+ input: z.object({ to: toParam }), parameterOrder: ['to'], output: messageIdParam,
14
+ });
6
15
 
7
16
  export const getAllContacts = defineMethodV2('getAllContacts', {
8
17
  meta: {
@@ -1,4 +1,4 @@
1
- import { ChatSchema, ContactIdSchema, ContactSchema, GroupChatIdSchema, GroupMetadataSchema } from '../common-types';
1
+ import { ChatSchema, ContactIdSchema, ContactSchema, GroupChatIdSchema } from '../common-types';
2
2
  import { GroupCreationResultSchema } from '../return-types';
3
3
  import { z } from 'zod';
4
4
  import { defineMethodV2 } from '../registry';
@@ -50,9 +50,15 @@ export const getGroupMembersId = defineMethodV2('getGroupMembersId', {
50
50
  output: z.array(ContactIdSchema),
51
51
  });
52
52
 
53
+ export const GroupInfoSchema = z.object({
54
+ title: z.string(),
55
+ description: z.string().nullish(),
56
+ }).passthrough().describe('Group title and description returned by the private getGroupInfo patch.');
57
+ export type GroupInfo = z.infer<typeof GroupInfoSchema>;
58
+
53
59
  export const getGroupInfo = defineMethodV2('getGroupInfo', {
54
60
  meta: {
55
- description: 'Get group metadata',
61
+ description: 'Get the group title and description through the installed private patch',
56
62
  action: 'read',
57
63
  namespace: 'groups',
58
64
  license: 'none',
@@ -61,7 +67,7 @@ export const getGroupInfo = defineMethodV2('getGroupInfo', {
61
67
  },
62
68
  input: z.object({ groupId: groupIdParam }),
63
69
  parameterOrder: ['groupId'],
64
- output: GroupMetadataSchema.nullable(),
70
+ output: GroupInfoSchema.or(z.string()).nullable(),
65
71
  });
66
72
 
67
73
  export const getGroupAdmins = defineMethodV2('getGroupAdmins', {
@@ -32,3 +32,5 @@ export * from './session';
32
32
  // Media Methods
33
33
  export * from './media';
34
34
  export * from './interactive';
35
+ export * from './calls';
36
+ export * from './whatsapp-events';
@@ -1,7 +1,9 @@
1
- import { MessageIdReturnSchema, MessageSchema } from '../common-types';
1
+ import { MessageIdReturnSchema, MessageIdSchema, MessageSchema } from '../common-types';
2
2
  import { LLMMessageSchema, MessageInfoSchema } from '../return-types';
3
3
  import { z } from 'zod';
4
4
  import { defineMethodV2 } from '../registry';
5
+ import { MediaSendOptionsSchema, AudioAttachmentOptionsSchema, VoiceNoteOptionsSchema, GifSendOptionsSchema } from '../media-options';
6
+ import { PollSendOptionsSchema, PollResultsSchema, PinDurationSchema } from '../polls';
5
7
 
6
8
  import {
7
9
  chatIdParam,
@@ -35,6 +37,70 @@ export const SendTextResultSchema = z.string()
35
37
  .brand('MessageId')
36
38
  .describe('Validated serialized message ID. This confirms the send returned an ID, not delivery or reading.');
37
39
 
40
+ export const StickerJobSchema = z.object({
41
+ effects: z.array(z.union([z.string(), z.object({ name: z.string(), options: z.record(z.string(), z.unknown()).optional() }).strict()])).max(8).optional(),
42
+ backend: z.enum(['auto','browser','standalone']).optional().describe('Defaults to browser when it supports the entire job; otherwise the entire job runs standalone.'),
43
+ quality: z.number().min(0.01).max(1).optional().describe('Maximum encoding quality; encoding can reduce quality to meet sticker byte limits.'),
44
+ fit: z.enum(['contain','cover']).optional(),
45
+ circle: z.boolean().optional(), background: z.string().max(64).optional(),
46
+ trim: z.tuple([z.number().nonnegative(),z.number().positive()]).refine(([start,end])=>end>start).optional(),
47
+ fps: z.number().int().min(1).max(30).optional(),
48
+ loopCount: z.number().int().min(0).max(65535).optional(),
49
+ author: z.string().max(128).optional(), pack: z.string().max(128).optional(),
50
+ quotedMsgId: messageIdParam.optional().describe('Reply with the sticker to a loaded message in the destination chat.'),
51
+ }).strict();
52
+
53
+ export const sendSticker = defineMethodV2('sendSticker', {
54
+ meta: {
55
+ description: 'Render a sticker locally using automatic whole-job backend selection and ordered effects, then submit through the private donor finalizer. Author and pack labels are configurable; donor app links are owned by the installed patch. Returns a submitted message ID, not a delivery receipt. Unknown send outcomes must be reconciled before retrying.',
56
+ action: 'send', namespace: 'messages', license: 'none', functionality: 'both', httpMethod: 'POST',
57
+ wapiOverride: 'sendStickerJob',
58
+ },
59
+ input: z.object({
60
+ to: toParam,
61
+ input: z.string().regex(/^(?:data:(?:image|video)\/[^;,]+;base64,[A-Za-z0-9+/]+={0,2}|https?:\/\/\S+)$/).describe('A media data URL or HTTP(S) URL. The local library additionally accepts bytes, Blob and local filenames.'),
62
+ job: StickerJobSchema.optional(),
63
+ }),
64
+ parameterOrder: ['to','input','job'],
65
+ output: SendTextResultSchema,
66
+ });
67
+
68
+ export const AlbumMediaSchema = z.object({
69
+ file: z.string().regex(/^data:(image|video)\/[^;,]+;base64,[A-Za-z0-9+/]+={0,2}$/)
70
+ .describe('Image or video as a base64 data URL. For a WhatsApp GIF, supply an MP4 video and set isGif to true.'),
71
+ filename: z.string().min(1).describe('Filename including its extension'),
72
+ isGif: z.boolean().optional().describe('Send an MP4 video as a looping WhatsApp GIF'),
73
+ }).refine(media => !media.isGif || media.file.startsWith('data:video/mp4;base64,'), {
74
+ message: 'GIF album items require MP4 video data',
75
+ path: ['file'],
76
+ });
77
+ export type AlbumMedia = z.infer<typeof AlbumMediaSchema>;
78
+
79
+ export const AlbumSendResultSchema = z.object({
80
+ albumId: MessageIdSchema,
81
+ messageIds: z.array(MessageIdSchema).min(2),
82
+ }).describe('Submitted album parent and child message IDs, in input order. Submission does not confirm recipient delivery. Runtime failures include the album ID and submitted child IDs when available. A lost connection can leave the send outcome unknown; inspect the chat before retrying.');
83
+ export type AlbumSendResult = z.infer<typeof AlbumSendResultSchema>;
84
+
85
+ export const sendAlbum = defineMethodV2('sendAlbum', {
86
+ meta: {
87
+ description: 'Sends images and videos together as a native WhatsApp album with one caption on its first item. GIFs use MP4 video data with isGif: true. Documents are rejected. Phone-number IDs are resolved to LIDs; the destination chat must already be loaded and allow sending. WhatsApp controls the minimum item count and upload limits. Runtime failures include the parent and submitted child IDs when available; inspect the chat before retrying.',
88
+ action: 'send',
89
+ namespace: 'messages',
90
+ license: 'none',
91
+ functionality: 'both',
92
+ httpMethod: 'POST',
93
+ },
94
+ input: z.object({
95
+ to: toParam,
96
+ media: z.array(AlbumMediaSchema).min(2).describe('Album items in send order'),
97
+ caption: captionParam.optional().default(''),
98
+ quotedMsgId: messageIdParam.optional().describe('Message to quote on the first album item'),
99
+ }),
100
+ parameterOrder: ['to', 'media', 'caption', 'quotedMsgId'],
101
+ output: AlbumSendResultSchema,
102
+ });
103
+
38
104
  /**
39
105
  * Sends a text message to a chat
40
106
  */
@@ -128,7 +194,7 @@ export const sendPaymentRequest = defineMethodV2('sendPaymentRequest', {
128
194
  */
129
195
  export const sendImage = defineMethodV2('sendImage', {
130
196
  meta: {
131
- description: 'Sends an image to a chat',
197
+ description: 'Sends media through the native attachment pipeline, including images and videos. Options select presentation, view once, GIF playback or circular video notes; media is not transcoded. Returns submission status, not a delivery receipt.',
132
198
  action: 'send',
133
199
  namespace: 'messages',
134
200
  license: 'none',
@@ -137,14 +203,12 @@ export const sendImage = defineMethodV2('sendImage', {
137
203
  },
138
204
  input: z.object({
139
205
  to: toParam,
140
- imgData: imageDataParam,
141
- filename: filenameParam,
142
- caption: captionParam,
143
- id: messageIdParam.optional(),
144
- waitForId: waitForIdParam
206
+ file: fileDataParam,
207
+ filename: filenameParam.optional(),
208
+ options: MediaSendOptionsSchema.optional().default({}),
145
209
  }),
146
- parameterOrder: ['to', 'imgData', 'filename', 'caption', 'id', 'waitForId'],
147
- output: MessageIdReturnSchema.or(z.boolean()).or(z.string())
210
+ parameterOrder: ['to', 'file', 'filename', 'options'],
211
+ output: MessageIdReturnSchema.or(z.boolean())
148
212
  });
149
213
 
150
214
  /**
@@ -152,7 +216,7 @@ export const sendImage = defineMethodV2('sendImage', {
152
216
  */
153
217
  export const sendFile = defineMethodV2('sendFile', {
154
218
  meta: {
155
- description: 'Sends a file or document to a chat',
219
+ description: 'Sends an image, video, audio file or document using MIME detection or an explicit typed presentation. Incompatible options are rejected before sending. Media is not transcoded.',
156
220
  action: 'send',
157
221
  namespace: 'messages',
158
222
  license: 'none',
@@ -162,11 +226,11 @@ export const sendFile = defineMethodV2('sendFile', {
162
226
  input: z.object({
163
227
  to: toParam,
164
228
  file: fileDataParam,
165
- filename: filenameParam,
166
- caption: captionParam
229
+ filename: filenameParam.optional(),
230
+ options: MediaSendOptionsSchema.optional().default({}),
167
231
  }),
168
- parameterOrder: ['to', 'file', 'filename', 'caption'],
169
- output: MessageIdReturnSchema.or(z.string())
232
+ parameterOrder: ['to', 'file', 'filename', 'options'],
233
+ output: MessageIdReturnSchema.or(z.boolean())
170
234
  });
171
235
 
172
236
  /**
@@ -174,7 +238,7 @@ export const sendFile = defineMethodV2('sendFile', {
174
238
  */
175
239
  export const sendAudio = defineMethodV2('sendAudio', {
176
240
  meta: {
177
- description: 'Sends an audio file to a chat',
241
+ description: 'Sends an audio attachment with an optional quoted message. Use sendPtt for voice notes and view-once audio.',
178
242
  action: 'send',
179
243
  namespace: 'messages',
180
244
  license: 'none',
@@ -184,10 +248,10 @@ export const sendAudio = defineMethodV2('sendAudio', {
184
248
  input: z.object({
185
249
  to: toParam,
186
250
  file: audioDataParam,
187
- filename: filenameParam,
188
- quotedMsgId: messageIdParam.optional()
251
+ filename: filenameParam.optional(),
252
+ options: AudioAttachmentOptionsSchema.optional().default({}),
189
253
  }),
190
- parameterOrder: ['to', 'file', 'filename', 'quotedMsgId'],
254
+ parameterOrder: ['to', 'file', 'filename', 'options'],
191
255
  output: MessageIdReturnSchema.or(z.boolean())
192
256
  });
193
257
 
@@ -196,7 +260,7 @@ export const sendAudio = defineMethodV2('sendAudio', {
196
260
  */
197
261
  export const sendPtt = defineMethodV2('sendPtt', {
198
262
  meta: {
199
- description: 'Sends a voice note (push-to-talk) to a chat',
263
+ description: 'Sends prepared audio as a voice note, optionally view once. It does not transcode the input; use suitable voice-note audio such as Ogg Opus.',
200
264
  action: 'send',
201
265
  namespace: 'messages',
202
266
  license: 'none',
@@ -209,9 +273,9 @@ export const sendPtt = defineMethodV2('sendPtt', {
209
273
  input: z.object({
210
274
  to: toParam,
211
275
  file: audioDataParam,
212
- quotedMsgId: messageIdParam.optional()
276
+ options: VoiceNoteOptionsSchema.optional().default({}),
213
277
  }),
214
- parameterOrder: ['to', 'file', 'quotedMsgId'],
278
+ parameterOrder: ['to', 'file', 'options'],
215
279
  output: MessageIdReturnSchema.or(z.boolean())
216
280
  });
217
281
 
@@ -220,7 +284,7 @@ export const sendPtt = defineMethodV2('sendPtt', {
220
284
  */
221
285
  export const sendVideoAsGif = defineMethodV2('sendVideoAsGif', {
222
286
  meta: {
223
- description: 'Sends a video as an animated GIF',
287
+ description: 'Sends MP4 video with WhatsApp GIF playback. GIF is a video presentation flag; this method does not convert a GIF image or transcode video.',
224
288
  action: 'send',
225
289
  namespace: 'messages',
226
290
  license: 'none',
@@ -230,11 +294,10 @@ export const sendVideoAsGif = defineMethodV2('sendVideoAsGif', {
230
294
  input: z.object({
231
295
  to: toParam,
232
296
  file: videoDataParam,
233
- filename: filenameParam,
234
- caption: captionParam,
235
- quotedMsgId: messageIdParam.optional()
297
+ filename: filenameParam.optional(),
298
+ options: GifSendOptionsSchema.optional().default({}),
236
299
  }),
237
- parameterOrder: ['to', 'file', 'filename', 'caption', 'quotedMsgId'],
300
+ parameterOrder: ['to', 'file', 'filename', 'options'],
238
301
  output: MessageIdReturnSchema.or(z.boolean())
239
302
  });
240
303
 
@@ -281,7 +344,7 @@ export const sendVCard = defineMethodV2('sendVCard', {
281
344
  contactNumber: z.string().optional().describe('Contact number with country code')
282
345
  }),
283
346
  parameterOrder: ['to', 'vcard', 'contactName', 'contactNumber'],
284
- output: z.boolean()
347
+ output: MessageIdReturnSchema.or(z.boolean())
285
348
  });
286
349
 
287
350
  /**
@@ -301,7 +364,7 @@ export const sendContact = defineMethodV2('sendContact', {
301
364
  contactId: contactIdParam.or(z.array(contactIdParam))
302
365
  }),
303
366
  parameterOrder: ['to', 'contactId'],
304
- output: MessageIdReturnSchema.or(z.boolean()).or(z.void())
367
+ output: MessageIdReturnSchema.or(z.boolean()).or(z.array(MessageIdReturnSchema.or(z.boolean())))
305
368
  });
306
369
 
307
370
  /**
@@ -322,7 +385,7 @@ export const sendMultipleContacts = defineMethodV2('sendMultipleContacts', {
322
385
  },
323
386
  input: z.object({
324
387
  to: toParam,
325
- contactIds: z.array(contactIdParam)
388
+ contactIds: z.array(contactIdParam).min(1)
326
389
  }),
327
390
  parameterOrder: ['to', 'contactIds'],
328
391
  output: MessageIdReturnSchema.or(z.boolean())
@@ -406,21 +469,40 @@ export const sendListMessage = defineMethodV2('sendListMessage', {
406
469
  */
407
470
  export const sendPoll = defineMethodV2('sendPoll', {
408
471
  meta: {
409
- description: 'Sends a poll message',
410
- action: 'send',
411
- namespace: 'messages',
412
- license: 'none',
413
- functionality: 'both',
414
- httpMethod: 'POST',
472
+ description: 'Sends a text poll with a selection limit, quote, optional closing time in Unix milliseconds and hidden voter names. Closing time and hidden names require native WhatsApp support for the sending account/chat. These fields select the native V6 poll payload.',
473
+ action: 'send', namespace: 'messages', license: 'none', functionality: 'both', httpMethod: 'POST',
415
474
  },
416
475
  input: z.object({
417
476
  to: toParam,
418
- name: z.string().describe('Poll question'),
419
- options: z.array(z.string()).min(2).max(12).describe('Poll options (2-12)'),
420
- selectableCount: z.number().optional().default(1).describe('Number of selectable options')
477
+ name: z.string().trim().min(1).max(500).describe('Poll question'),
478
+ options: z.array(z.string().trim().min(1).max(255)).min(2).max(20).describe('Poll choices; the account may have a lower native limit'),
479
+ config: PollSendOptionsSchema.optional().default({}),
480
+ }).refine(input => (input.config.selectableCount ?? 1) <= input.options.length, {
481
+ path: ['config', 'selectableCount'], message: 'Selection limit cannot exceed the number of poll options',
482
+ }).refine(input => new Set(input.options).size === input.options.length, {
483
+ path: ['options'], message: 'Poll choices must be unique',
421
484
  }),
422
- parameterOrder: ['to', 'name', 'options', 'selectableCount'],
423
- output: MessageIdReturnSchema.or(z.boolean())
485
+ parameterOrder: ['to', 'name', 'options', 'config'],
486
+ output: MessageIdReturnSchema.or(z.boolean()),
487
+ });
488
+
489
+ export const voteOnPoll = defineMethodV2('voteOnPoll', {
490
+ meta: { description: 'Votes using option IDs returned by getPollResults; an empty array removes the current vote. The poll must be open and allow this account to vote.', action: 'send', namespace: 'messages', license: 'none', functionality: 'both', httpMethod: 'POST' },
491
+ input: z.object({ messageId: messageIdParam, optionIds: z.array(z.number().int().nonnegative()).max(20) }).refine(input => new Set(input.optionIds).size === input.optionIds.length, { path: ['optionIds'], message: 'Duplicate poll choices are not allowed' }),
492
+ parameterOrder: ['messageId', 'optionIds'], output: z.boolean(),
493
+ });
494
+ export const getPollResults = defineMethodV2('getPollResults', {
495
+ meta: { description: 'Hydrates the local poll vote store and returns synced counts, choices and votes. Hidden-voter polls omit voter identities and the votes array. Unsynced votes may be absent.', action: 'get', namespace: 'messages', license: 'none', functionality: 'both', httpMethod: 'POST' },
496
+ input: z.object({ messageId: messageIdParam }), parameterOrder: ['messageId'], output: PollResultsSchema,
497
+ });
498
+ export const pinMessage = defineMethodV2('pinMessage', {
499
+ meta: { description: 'Pins a message in its chat for everyone, subject to native permissions. This differs from pinChat, which changes the current account chat list.', action: 'set', namespace: 'messages', license: 'none', functionality: 'both', httpMethod: 'POST' },
500
+ input: z.object({ messageId: messageIdParam, duration: PinDurationSchema.optional().default('SevenDays') }),
501
+ parameterOrder: ['messageId', 'duration'], output: z.boolean(),
502
+ });
503
+ export const unpinMessage = defineMethodV2('unpinMessage', {
504
+ meta: { description: 'Removes a message pin for everyone, subject to native chat permissions.', action: 'set', namespace: 'messages', license: 'none', functionality: 'both', httpMethod: 'POST' },
505
+ input: z.object({ messageId: messageIdParam }), parameterOrder: ['messageId'], output: z.boolean(),
424
506
  });
425
507
 
426
508
  /**
@@ -608,6 +690,21 @@ export const getMessageById = defineMethodV2('getMessageById', {
608
690
  output: MessageSchema.nullable().or(z.literal(false)),
609
691
  });
610
692
 
693
+ export const getAlbumMessages = defineMethodV2('getAlbumMessages', {
694
+ meta: {
695
+ description: 'Returns currently loaded image and video messages associated with an album, including GIF videos. The album can arrive before its media, so the array may be incomplete. Returns false if the album is not loaded or the ID belongs to another message type.',
696
+ action: 'read',
697
+ namespace: 'messages',
698
+ license: 'none',
699
+ functionality: 'both',
700
+ httpMethod: 'GET',
701
+ },
702
+ input: z.object({ messageId: messageIdParam.describe('Album container message ID') }),
703
+ parameterOrder: ['messageId'],
704
+ output: z.array(MessageSchema).or(z.literal(false))
705
+ .describe('A snapshot of currently loaded album media. An empty or partial array does not mean that the sender sent an empty or partial album. Each item retains its caption and can be passed to decryptMedia or downloadMedia.'),
706
+ });
707
+
611
708
  /**
612
709
  * Retrieves all messages in the session
613
710
  */
@@ -760,6 +857,23 @@ export const unstarMessage = defineMethodV2('unstarMessage', {
760
857
  output: z.boolean(),
761
858
  });
762
859
 
860
+ export const editMessage = defineMethodV2('editMessage', {
861
+ meta: {
862
+ description: 'Edits the text of a message through the installed private patch',
863
+ action: 'update',
864
+ namespace: 'messages',
865
+ license: 'none',
866
+ functionality: 'both',
867
+ httpMethod: 'PUT',
868
+ },
869
+ input: z.object({
870
+ messageId: messageIdParam,
871
+ newContent: z.string().describe('Replacement message text'),
872
+ }),
873
+ parameterOrder: ['messageId', 'newContent'],
874
+ output: z.boolean(),
875
+ });
876
+
763
877
  export const react = defineMethodV2('react', {
764
878
  meta: {
765
879
  description: 'React to message with emoji',
@@ -817,7 +931,7 @@ export const loadEarlierMessages = defineMethodV2('loadEarlierMessages', {
817
931
 
818
932
  export const sendFileFromUrl = defineMethodV2('sendFileFromUrl', {
819
933
  meta: {
820
- description: 'Downloads a file from a URL and sends it to a chat',
934
+ description: 'Downloads media and sends it through sendFile with the same typed presentation options.',
821
935
  action: 'send',
822
936
  namespace: 'messages',
823
937
  license: 'none',
@@ -827,10 +941,10 @@ export const sendFileFromUrl = defineMethodV2('sendFileFromUrl', {
827
941
  input: z.object({
828
942
  to: toParam,
829
943
  url: z.string().url().describe('URL of the file to download'),
830
- filename: z.string().describe('Filename for the sent file'),
831
- caption: z.string().optional().describe('Caption for the file'),
944
+ filename: filenameParam.optional(),
945
+ options: MediaSendOptionsSchema.optional().default({}),
832
946
  headers: z.record(z.string(), z.string()).optional().describe('HTTP headers for the download request'),
833
947
  }),
834
- parameterOrder: ['to', 'url', 'filename', 'caption', 'headers'],
835
- output: z.string().or(z.boolean()).describe('Message ID or success status'),
948
+ parameterOrder: ['to', 'url', 'filename', 'options', 'headers'],
949
+ output: MessageIdReturnSchema.or(z.string()).or(z.boolean()).describe('Message ID or success status'),
836
950
  });