@whanext/core 0.16.0 → 0.17.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/CHANGELOG.md +15 -0
- package/README.md +14 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +47 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
### Adicionado
|
|
6
|
+
|
|
7
|
+
- Novo evento público `messageEdited` em `app.on()` e `multi.on()`.
|
|
8
|
+
- Novo tipo `MessageEdited`, com versão anterior quando ainda estiver no cache, versão atual, identidade responsável e horário da edição.
|
|
9
|
+
- O provider Baileys passa a interpretar atualizações `editedMessage` recebidas em `messages.update`.
|
|
10
|
+
- O cache recente é atualizado após cada edição, permitindo acompanhar múltiplas alterações da mesma mensagem em sequência.
|
|
11
|
+
|
|
12
|
+
### Compatibilidade
|
|
13
|
+
|
|
14
|
+
- A mudança é aditiva para consumidores da API pública.
|
|
15
|
+
- Providers customizados passam a incluir `messageEdited` em `ProviderEvents`.
|
|
16
|
+
- Quando a versão anterior já saiu do cache, o evento continua sendo emitido sem o campo `previous`.
|
|
17
|
+
|
|
3
18
|
|
|
4
19
|
## 0.16.0
|
|
5
20
|
|
package/README.md
CHANGED
|
@@ -173,6 +173,20 @@ app.on('messageDeleted', async ({ message, deletedByMe }) => {
|
|
|
173
173
|
|
|
174
174
|
O evento também informa `deletedById` quando o WhatsApp fornece a identidade responsável pela revogação.
|
|
175
175
|
|
|
176
|
+
## Mensagens editadas
|
|
177
|
+
|
|
178
|
+
Edições recebidas pelo WhatsApp são expostas pelo evento `messageEdited`. Quando a versão anterior ainda estiver no cache recente, o payload inclui `previous`; `message` contém a versão atual.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
app.on('messageEdited', async ({ previous, message, editedByMe }) => {
|
|
182
|
+
if (!previous || editedByMe) return;
|
|
183
|
+
|
|
184
|
+
console.log(previous.text, message.text);
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Após cada edição, a nova versão substitui a anterior no cache recente. Assim, edições consecutivas da mesma mensagem sempre comparam a versão atual com a imediatamente anterior.
|
|
189
|
+
|
|
176
190
|
## Logging
|
|
177
191
|
|
|
178
192
|
O nível padrão é `info`. Estão disponíveis `debug`, `info`, `warn`, `error` e `silent`.
|
package/dist/index.d.ts
CHANGED
|
@@ -97,6 +97,14 @@ interface MessageDeleted {
|
|
|
97
97
|
deletedById?: string;
|
|
98
98
|
deletedAt: Date;
|
|
99
99
|
}
|
|
100
|
+
interface MessageEdited {
|
|
101
|
+
key: MessageKey;
|
|
102
|
+
previous?: Message;
|
|
103
|
+
message: Message;
|
|
104
|
+
editedByMe: boolean;
|
|
105
|
+
editedById?: string;
|
|
106
|
+
editedAt: Date;
|
|
107
|
+
}
|
|
100
108
|
interface Message {
|
|
101
109
|
id: string;
|
|
102
110
|
jid: string;
|
|
@@ -255,6 +263,7 @@ interface ConnectionUpdate {
|
|
|
255
263
|
interface ProviderEvents {
|
|
256
264
|
message: Message;
|
|
257
265
|
messageDeleted: MessageDeleted;
|
|
266
|
+
messageEdited: MessageEdited;
|
|
258
267
|
connection: ConnectionUpdate;
|
|
259
268
|
groupChanged: {
|
|
260
269
|
groupId: string;
|
|
@@ -755,6 +764,7 @@ declare class AccountService {
|
|
|
755
764
|
interface AppEvents {
|
|
756
765
|
message: Message;
|
|
757
766
|
messageDeleted: MessageDeleted;
|
|
767
|
+
messageEdited: MessageEdited;
|
|
758
768
|
connection: ConnectionUpdate;
|
|
759
769
|
error: WhaNextError;
|
|
760
770
|
mute: MuteEnforcement;
|
|
@@ -914,4 +924,4 @@ declare class SqliteMuteStore implements MuteStore {
|
|
|
914
924
|
close(): void;
|
|
915
925
|
}
|
|
916
926
|
|
|
917
|
-
export { AccountService, type AddMuteOptions, type AddMuteResult, type AppEvents, type AppHealth, type AppHealthStatus, ArgsParser, type AudioContent, type BooleanOption, Browser, type ButtonsContent, type CacheOptions, type CacheStore, type CallEvent, type CallStatus, type ChangeResult, type CommandAccountContext, type CommandCatalogOptions, type CommandCatalogView, type CommandChatContext, type CommandConcurrency, type CommandContext, type CommandCooldown, type CommandDefinition, type CommandErrorHandler, type CommandGroupContext, type CommandGroupDefinition, type CommandGuard, type CommandHelpOptions, type CommandHooks, type CommandLocalization, type CommandMetadata, type CommandMiddleware, type CommandOptionDefinition, type CommandOptionSchema, type CommandOptionValue, type CommandOptionValues, type CommandRegistrar, CommandRouter, type CommandRuntimeServices, type CommandScope, type ConcurrencyStrategy, type ConnectionState, type ConnectionUpdate, type CopyCodeButton, type CreateMultiOptions, type CreateOptions, DeferredReply, type DownloadedMedia, type DurationOption, type EnumOption, type ExecutableCommandDefinition, type GroupAccess, type GroupAddressingMode, type GroupParticipant, type GroupParticipantAction, type GroupParticipantsChanged, type GroupRole, type GroupSnapshot, type GuardResult, type ImageContent, type InviteResult, type LinkButton, type LoadCommandsOptions, type LoadCommandsResult, type LoadedCommand, type LogContext, type LogEntry, type LogFormat, type LogLevel, type LogWriter, Logger, type LoggerConfig, type LoggerOptions, type LoginOptions, type MediaKind, type MediaSource, type MemberActionState, MemoryCache, type MemoryCacheStats, type MentionTarget, type Message, type MessageButton, type MessageContent, type MessageContentKind, type MessageDeleted, type MessageKey, type MessageMedia, type MultiAccountOptions, type MultiAppEvent, type MultiAppHealth, MultiCommandRouter, type MultiLoadCommandsResult, type MultiLoginOptions, type MuteChangeResult, type MuteEnforcement, type MuteOptions, type MuteRecord, MuteService, type MuteStore, type NumberOption, ParsedCommandOptions, type ParticipantUpdateResult, type PresenceState, type QuotedMessage, type ReconnectOptions, type RegisteredCommand, type RemoveMuteResult, type ReplyOptions, type RepostMessageOptions, type RouterOptions, type SentMessage, SqliteMuteStore, type StickerContent, type StoredMute, type StringOption, type TextContent, User, type UserData, type UserOption, type VideoContent, WhaNextApp, WhaNextError, type WhaNextErrorCode, WhaNextMultiApp, type WhatsAppProvider, create, createMulti, defineCommand, defineCommandGroup, defineCommands, defineSubcommand, guards, isCommandGroup, loadCommands, option, toWhaNextError };
|
|
927
|
+
export { AccountService, type AddMuteOptions, type AddMuteResult, type AppEvents, type AppHealth, type AppHealthStatus, ArgsParser, type AudioContent, type BooleanOption, Browser, type ButtonsContent, type CacheOptions, type CacheStore, type CallEvent, type CallStatus, type ChangeResult, type CommandAccountContext, type CommandCatalogOptions, type CommandCatalogView, type CommandChatContext, type CommandConcurrency, type CommandContext, type CommandCooldown, type CommandDefinition, type CommandErrorHandler, type CommandGroupContext, type CommandGroupDefinition, type CommandGuard, type CommandHelpOptions, type CommandHooks, type CommandLocalization, type CommandMetadata, type CommandMiddleware, type CommandOptionDefinition, type CommandOptionSchema, type CommandOptionValue, type CommandOptionValues, type CommandRegistrar, CommandRouter, type CommandRuntimeServices, type CommandScope, type ConcurrencyStrategy, type ConnectionState, type ConnectionUpdate, type CopyCodeButton, type CreateMultiOptions, type CreateOptions, DeferredReply, type DownloadedMedia, type DurationOption, type EnumOption, type ExecutableCommandDefinition, type GroupAccess, type GroupAddressingMode, type GroupParticipant, type GroupParticipantAction, type GroupParticipantsChanged, type GroupRole, type GroupSnapshot, type GuardResult, type ImageContent, type InviteResult, type LinkButton, type LoadCommandsOptions, type LoadCommandsResult, type LoadedCommand, type LogContext, type LogEntry, type LogFormat, type LogLevel, type LogWriter, Logger, type LoggerConfig, type LoggerOptions, type LoginOptions, type MediaKind, type MediaSource, type MemberActionState, MemoryCache, type MemoryCacheStats, type MentionTarget, type Message, type MessageButton, type MessageContent, type MessageContentKind, type MessageDeleted, type MessageEdited, type MessageKey, type MessageMedia, type MultiAccountOptions, type MultiAppEvent, type MultiAppHealth, MultiCommandRouter, type MultiLoadCommandsResult, type MultiLoginOptions, type MuteChangeResult, type MuteEnforcement, type MuteOptions, type MuteRecord, MuteService, type MuteStore, type NumberOption, ParsedCommandOptions, type ParticipantUpdateResult, type PresenceState, type QuotedMessage, type ReconnectOptions, type RegisteredCommand, type RemoveMuteResult, type ReplyOptions, type RepostMessageOptions, type RouterOptions, type SentMessage, SqliteMuteStore, type StickerContent, type StoredMute, type StringOption, type TextContent, User, type UserData, type UserOption, type VideoContent, WhaNextApp, WhaNextError, type WhaNextErrorCode, WhaNextMultiApp, type WhatsAppProvider, create, createMulti, defineCommand, defineCommandGroup, defineCommands, defineSubcommand, guards, isCommandGroup, loadCommands, option, toWhaNextError };
|
package/dist/index.js
CHANGED
|
@@ -2206,6 +2206,15 @@ var WhaNextApp = class {
|
|
|
2206
2206
|
});
|
|
2207
2207
|
await this.#events.emit("messageDeleted", deletion);
|
|
2208
2208
|
});
|
|
2209
|
+
this.#provider.on("messageEdited", async (edit) => {
|
|
2210
|
+
this.logger.debug("Message edited", {
|
|
2211
|
+
chatId: edit.key.chatId,
|
|
2212
|
+
messageId: edit.key.id,
|
|
2213
|
+
editedByMe: edit.editedByMe,
|
|
2214
|
+
cached: edit.previous !== void 0
|
|
2215
|
+
});
|
|
2216
|
+
await this.#events.emit("messageEdited", edit);
|
|
2217
|
+
});
|
|
2209
2218
|
this.#provider.on("message", async (message) => {
|
|
2210
2219
|
try {
|
|
2211
2220
|
const enforcement = await this.mute.enforce(message);
|
|
@@ -2859,18 +2868,45 @@ var BaileysProvider = class {
|
|
|
2859
2868
|
});
|
|
2860
2869
|
socket.ev.on("messages.update", (updates) => {
|
|
2861
2870
|
for (const { key, update } of updates) {
|
|
2862
|
-
if (
|
|
2871
|
+
if (!key.id || !key.remoteJid) continue;
|
|
2863
2872
|
const stored = this.#messageStore.get(this.#messageStoreKey(key));
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2873
|
+
if (update.message === null) {
|
|
2874
|
+
const message2 = stored ? normalizeBaileysMessage(stored) : void 0;
|
|
2875
|
+
const deletionKey = update.key;
|
|
2876
|
+
const deletedByMe = deletionKey?.fromMe === true;
|
|
2877
|
+
const deletedById = deletionKey?.participant ?? deletionKey?.participantAlt ?? (deletedByMe ? this.#socket?.user?.id : deletionKey?.remoteJid ?? void 0);
|
|
2878
|
+
void this.#events.emit("messageDeleted", {
|
|
2879
|
+
key: message2?.keys ?? normalizeKey(key),
|
|
2880
|
+
...message2 ? { message: message2 } : {},
|
|
2881
|
+
deletedByMe,
|
|
2882
|
+
...deletedById ? { deletedById } : {},
|
|
2883
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
2884
|
+
});
|
|
2885
|
+
continue;
|
|
2886
|
+
}
|
|
2887
|
+
if (!update.message?.editedMessage?.message) continue;
|
|
2888
|
+
const editedRaw = {
|
|
2889
|
+
...stored ?? {},
|
|
2890
|
+
key: {
|
|
2891
|
+
...stored?.key ?? {},
|
|
2892
|
+
...key
|
|
2893
|
+
},
|
|
2894
|
+
message: update.message,
|
|
2895
|
+
messageTimestamp: update.messageTimestamp ?? stored?.messageTimestamp ?? Math.floor(Date.now() / 1e3)
|
|
2896
|
+
};
|
|
2897
|
+
const previous = stored ? normalizeBaileysMessage(stored) : void 0;
|
|
2898
|
+
const message = normalizeBaileysMessage(editedRaw);
|
|
2899
|
+
if (!message) continue;
|
|
2900
|
+
this.#remember(editedRaw);
|
|
2901
|
+
const editedByMe = key.fromMe === true;
|
|
2902
|
+
const editedById = key.participant ?? key.participantAlt ?? (editedByMe ? this.#socket?.user?.id : key.remoteJid ?? void 0);
|
|
2903
|
+
void this.#events.emit("messageEdited", {
|
|
2904
|
+
key: message.keys,
|
|
2905
|
+
...previous ? { previous } : {},
|
|
2906
|
+
message,
|
|
2907
|
+
editedByMe,
|
|
2908
|
+
...editedById ? { editedById } : {},
|
|
2909
|
+
editedAt: message.timestamp
|
|
2874
2910
|
});
|
|
2875
2911
|
}
|
|
2876
2912
|
});
|