-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathEvents.ts
More file actions
161 lines (149 loc) · 6.1 KB
/
Events.ts
File metadata and controls
161 lines (149 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import type { Boom } from '@hapi/boom'
import { proto } from '../../WAProto/index.js'
import type { AuthenticationCreds, LIDMapping } from './Auth'
import type { WACallEvent } from './Call'
import type { Chat, ChatUpdate, PresenceData } from './Chat'
import type { Contact } from './Contact'
import type {
GroupMetadata,
GroupParticipant,
ParticipantAction,
RequestJoinAction,
RequestJoinMethod
} from './GroupMetadata'
import type { Label } from './Label'
import type { LabelAssociation } from './LabelAssociation'
import type { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message'
import type { ConnectionState } from './State'
// TODO: refactor this mess
export type BaileysEventMap = {
/** connection state has been updated -- WS closed, opened, connecting etc. */
'connection.update': Partial<ConnectionState>
/** credentials updated -- some metadata, keys or something */
'creds.update': Partial<AuthenticationCreds>
/** set chats (history sync), everything is reverse chronologically sorted */
'messaging-history.set': {
chats: Chat[]
contacts: Contact[]
messages: WAMessage[]
lidPnMappings?: LIDMapping[]
isLatest?: boolean
progress?: number | null
syncType?: proto.HistorySync.HistorySyncType | null
peerDataRequestSessionId?: string | null
}
/** upsert chats */
'chats.upsert': Chat[]
/** update the given chats */
'chats.update': ChatUpdate[]
'lid-mapping.update': LIDMapping
/** delete chats with given ID */
'chats.delete': string[]
/** presence of contact in a chat updated */
'presence.update': { id: string; presences: { [participant: string]: PresenceData } }
'contacts.upsert': Contact[]
'contacts.update': Partial<Contact>[]
'messages.delete': { keys: WAMessageKey[] } | { jid: string; all: true }
'messages.update': WAMessageUpdate[]
'messages.media-update': { key: WAMessageKey; media?: { ciphertext: Uint8Array; iv: Uint8Array }; error?: Boom }[]
/**
* add/update the given messages. If they were received while the connection was online,
* the update will have type: "notify"
* if requestId is provided, then the messages was received from the phone due to it being unavailable
* */
'messages.upsert': { messages: WAMessage[]; type: MessageUpsertType; requestId?: string }
/** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
'messages.reaction': { key: WAMessageKey; reaction: proto.IReaction }[]
'message-receipt.update': MessageUserReceiptUpdate[]
'groups.upsert': GroupMetadata[]
'groups.update': Partial<GroupMetadata>[]
/** apply an action to participants in a group */
'group-participants.update': {
id: string
author: string
authorPn?: string
authorUsername?: string
participants: GroupParticipant[]
action: ParticipantAction
}
'group.join-request': {
id: string
author: string
authorPn?: string
authorUsername?: string
participant: string
participantPn?: string
action: RequestJoinAction
method: RequestJoinMethod
}
/* update the labels assigned to a group participant */
'group.member-tag.update': {
groupId: string
participant: string
participantAlt?: string
label: string
messageTimestamp?: number
}
'blocklist.set': { blocklist: string[] }
'blocklist.update': { blocklist: string[]; type: 'add' | 'remove' }
/** Receive an update on a call, including when the call was received, rejected, accepted */
call: WACallEvent[]
'labels.edit': Label
'labels.association': { association: LabelAssociation; type: 'add' | 'remove' }
/** Newsletter-related events */
'newsletter.reaction': {
id: string
server_id: string
reaction: { code?: string; count?: number; removed?: boolean }
}
'newsletter.view': { id: string; server_id: string; count: number }
'newsletter-participants.update': { id: string; author: string; user: string; new_role: string; action: string }
'newsletter-settings.update': { id: string; update: any }
/** Settings and actions sync events */
'chats.lock': { id: string; locked: boolean }
'settings.update':
| { setting: 'unarchiveChats'; value: boolean }
| { setting: 'locale'; value: string }
| { setting: 'disableLinkPreviews'; value: proto.SyncActionValue.IPrivacySettingDisableLinkPreviewsAction }
| { setting: 'timeFormat'; value: proto.SyncActionValue.ITimeFormatAction }
| { setting: 'privacySettingRelayAllCalls'; value: proto.SyncActionValue.IPrivacySettingRelayAllCalls }
| { setting: 'statusPrivacy'; value: proto.SyncActionValue.IStatusPrivacyAction }
| {
setting: 'notificationActivitySetting'
value: proto.SyncActionValue.NotificationActivitySettingAction.NotificationActivitySetting
}
| {
setting: 'channelsPersonalisedRecommendation'
value: proto.SyncActionValue.IPrivacySettingChannelsPersonalisedRecommendationAction
}
}
export type BufferedEventData = {
historySets: {
chats: { [jid: string]: Chat }
contacts: { [jid: string]: Contact }
messages: { [uqId: string]: WAMessage }
empty: boolean
isLatest: boolean
progress?: number | null
syncType?: proto.HistorySync.HistorySyncType
peerDataRequestSessionId?: string
}
chatUpserts: { [jid: string]: Chat }
chatUpdates: { [jid: string]: ChatUpdate }
chatDeletes: Set<string>
contactUpserts: { [jid: string]: Contact }
contactUpdates: { [jid: string]: Partial<Contact> }
messageUpserts: { [key: string]: { type: MessageUpsertType; message: WAMessage } }
messageUpdates: { [key: string]: WAMessageUpdate }
messageDeletes: { [key: string]: WAMessageKey }
messageReactions: { [key: string]: { key: WAMessageKey; reactions: proto.IReaction[] } }
messageReceipts: { [key: string]: { key: WAMessageKey; userReceipt: proto.IUserReceipt[] } }
groupUpdates: { [jid: string]: Partial<GroupMetadata> }
}
export type BaileysEvent = keyof BaileysEventMap
export interface BaileysEventEmitter {
on<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void
off<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void
removeAllListeners<T extends keyof BaileysEventMap>(event: T): void
emit<T extends keyof BaileysEventMap>(event: T, arg: BaileysEventMap[T]): boolean
}