@whanext/core 0.19.21 → 0.19.23
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 +14 -0
- package/dist/index.d.ts +14 -12
- package/dist/index.js +49 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.19.23
|
|
4
|
+
|
|
5
|
+
### Adicionado
|
|
6
|
+
- `UserService.profilePictureUrl()` para consultar a foto de perfil de um usuário quando o provider oferecer suporte.
|
|
7
|
+
- Provider Zapo agora usa `WaClient.profile.getProfilePicture()` para expor a URL da foto de perfil sem vazar a API do provider.
|
|
8
|
+
|
|
9
|
+
### Corrigido
|
|
10
|
+
- Incluído o type import de `Message` usado pelo filtro de shells vazios do Zapo.
|
|
11
|
+
|
|
12
|
+
## 0.19.22
|
|
13
|
+
### Fixed
|
|
14
|
+
- Corrige falsos `duplicate` em mensagens de grupo quando o Zapo emite primeiro um shell interno de Sender Key/protocolo sem conteúdo e depois a mensagem real reutilizando o mesmo stanza ID.
|
|
15
|
+
- Shells vazios `unknown` não são mais publicados nem consomem a chave de deduplicação; a mensagem real de texto/mídia continua chegando normalmente ao dispatcher.
|
|
16
|
+
|
|
3
17
|
## 0.19.21
|
|
4
18
|
|
|
5
19
|
### Added
|
package/dist/index.d.ts
CHANGED
|
@@ -243,6 +243,17 @@ interface StickerContent {
|
|
|
243
243
|
}
|
|
244
244
|
type MessageContent = TextContent | ButtonsContent | ListContent | PollContent | ImageContent | VideoContent | AudioContent | StickerContent;
|
|
245
245
|
|
|
246
|
+
type CallStatus = 'offer' | 'ringing' | 'preaccept' | 'timeout' | 'reject' | 'accept';
|
|
247
|
+
interface CallEvent {
|
|
248
|
+
id: string;
|
|
249
|
+
chatId: string;
|
|
250
|
+
from: string;
|
|
251
|
+
status: CallStatus;
|
|
252
|
+
isVideo: boolean;
|
|
253
|
+
isGroup: boolean;
|
|
254
|
+
date: Date;
|
|
255
|
+
}
|
|
256
|
+
|
|
246
257
|
type GroupAccess = 'open' | 'closed';
|
|
247
258
|
type GroupRole = 'member' | 'admin' | 'owner';
|
|
248
259
|
type GroupAddressingMode = 'lid' | 'pn';
|
|
@@ -284,17 +295,6 @@ interface InviteResult {
|
|
|
284
295
|
type MemberAction = 'removed' | 'promoted' | 'demoted';
|
|
285
296
|
type MemberActionState = MemberAction | 'already_removed' | 'already_admin' | 'not_admin' | 'not_in_group';
|
|
286
297
|
|
|
287
|
-
type CallStatus = 'offer' | 'ringing' | 'preaccept' | 'timeout' | 'reject' | 'accept';
|
|
288
|
-
interface CallEvent {
|
|
289
|
-
id: string;
|
|
290
|
-
chatId: string;
|
|
291
|
-
from: string;
|
|
292
|
-
status: CallStatus;
|
|
293
|
-
isVideo: boolean;
|
|
294
|
-
isGroup: boolean;
|
|
295
|
-
date: Date;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
298
|
type ConnectionState = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'closed';
|
|
299
299
|
type StabilityHealthStatus = 'healthy' | 'degraded' | 'reconnecting' | 'offline';
|
|
300
300
|
type CryptoAccelerationBackend = 'napi' | 'wasm' | 'js' | 'unknown';
|
|
@@ -487,6 +487,7 @@ interface WhatsAppProvider {
|
|
|
487
487
|
repostMessage(source: MessageKey, chatId: string, options?: RepostMessageOptions): Promise<SentMessage>;
|
|
488
488
|
reactToMessage(key: MessageKey, emoji?: string): Promise<SentMessage>;
|
|
489
489
|
downloadMedia(key: MessageKey): Promise<DownloadedMedia>;
|
|
490
|
+
getProfilePictureUrl?(userId: string): Promise<string | undefined>;
|
|
490
491
|
editMessage(key: MessageKey, content: string, options?: EditMessageOptions): Promise<SentMessage>;
|
|
491
492
|
deleteMessage(key: MessageKey): Promise<void>;
|
|
492
493
|
getGroup(groupId: string): Promise<GroupSnapshot>;
|
|
@@ -517,8 +518,9 @@ declare class GroupService {
|
|
|
517
518
|
|
|
518
519
|
declare class UserService {
|
|
519
520
|
#private;
|
|
520
|
-
constructor(group: GroupService);
|
|
521
|
+
constructor(group: GroupService, provider?: WhatsAppProvider);
|
|
521
522
|
resolve(message: Message, args: ArgsParser): Promise<User>;
|
|
523
|
+
profilePictureUrl(user: string | User): Promise<string | undefined>;
|
|
522
524
|
from(identity: string): User;
|
|
523
525
|
}
|
|
524
526
|
|
package/dist/index.js
CHANGED
|
@@ -866,8 +866,10 @@ var TypedEventEmitter = class {
|
|
|
866
866
|
// src/services/user-service.ts
|
|
867
867
|
var UserService = class {
|
|
868
868
|
#group;
|
|
869
|
-
|
|
869
|
+
#provider;
|
|
870
|
+
constructor(group, provider) {
|
|
870
871
|
this.#group = group;
|
|
872
|
+
this.#provider = provider;
|
|
871
873
|
}
|
|
872
874
|
async resolve(message, args) {
|
|
873
875
|
const mentioned = message.mentionedUsers[0];
|
|
@@ -884,6 +886,26 @@ var UserService = class {
|
|
|
884
886
|
}
|
|
885
887
|
return this.#group.resolveUser(message.chatId, user);
|
|
886
888
|
}
|
|
889
|
+
async profilePictureUrl(user) {
|
|
890
|
+
const provider = this.#provider;
|
|
891
|
+
if (!provider?.getProfilePictureUrl) return void 0;
|
|
892
|
+
const target = typeof user === "string" ? this.from(user) : user;
|
|
893
|
+
const identities = [
|
|
894
|
+
target.jid,
|
|
895
|
+
target.phoneNumber,
|
|
896
|
+
target.lid,
|
|
897
|
+
target.id,
|
|
898
|
+
...target.identities
|
|
899
|
+
].filter((identity, index, values) => identity !== void 0 && values.indexOf(identity) === index);
|
|
900
|
+
for (const identity of identities) {
|
|
901
|
+
try {
|
|
902
|
+
const url = await provider.getProfilePictureUrl(identity);
|
|
903
|
+
if (url) return url;
|
|
904
|
+
} catch {
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return void 0;
|
|
908
|
+
}
|
|
887
909
|
from(identity) {
|
|
888
910
|
if (!identity.includes("@")) {
|
|
889
911
|
return User.fromPhoneNumber(identity);
|
|
@@ -2305,7 +2327,7 @@ var WhaNextApp = class {
|
|
|
2305
2327
|
this.message = new MessageService(provider);
|
|
2306
2328
|
this.media = new MediaService(provider);
|
|
2307
2329
|
this.chat = new ChatService(provider);
|
|
2308
|
-
this.user = new UserService(this.group);
|
|
2330
|
+
this.user = new UserService(this.group, provider);
|
|
2309
2331
|
const muteEnabled = options.mute?.enabled === true || options.mute?.store !== void 0;
|
|
2310
2332
|
const muteStore = muteEnabled ? options.mute?.store ?? new SqliteMuteStore(options.mute?.database) : void 0;
|
|
2311
2333
|
this.mute = new MuteService(provider, muteStore);
|
|
@@ -3491,6 +3513,16 @@ var ZapoProvider = class {
|
|
|
3491
3513
|
);
|
|
3492
3514
|
}
|
|
3493
3515
|
}
|
|
3516
|
+
async getProfilePictureUrl(userId) {
|
|
3517
|
+
const target = userId.trim();
|
|
3518
|
+
if (!target) return void 0;
|
|
3519
|
+
try {
|
|
3520
|
+
const picture = await this.#requireClient().profile.getProfilePicture(target, "image");
|
|
3521
|
+
return picture.url || void 0;
|
|
3522
|
+
} catch {
|
|
3523
|
+
return void 0;
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3494
3526
|
async editMessage(key, content, options = {}) {
|
|
3495
3527
|
return this.#trackOutgoing(async () => {
|
|
3496
3528
|
const result = await this.#requireClient().message.send(
|
|
@@ -3925,15 +3957,6 @@ var ZapoProvider = class {
|
|
|
3925
3957
|
});
|
|
3926
3958
|
return;
|
|
3927
3959
|
}
|
|
3928
|
-
if (stored.key.id && this.#deliveredMessageStore.has(deliveryKey)) {
|
|
3929
|
-
this.#duplicateMessages += 1;
|
|
3930
|
-
this.#emitMessageDiscarded("duplicate", stored.key);
|
|
3931
|
-
this.#logger.debug("Ignored duplicate Zapo message event.", {
|
|
3932
|
-
messageId: stored.key.id,
|
|
3933
|
-
chatId: stored.key.remoteJid ?? void 0
|
|
3934
|
-
});
|
|
3935
|
-
return;
|
|
3936
|
-
}
|
|
3937
3960
|
const message = normalizeZapoMessage(event);
|
|
3938
3961
|
if (!message) {
|
|
3939
3962
|
this.#normalizationFailures += 1;
|
|
@@ -3944,6 +3967,18 @@ var ZapoProvider = class {
|
|
|
3944
3967
|
});
|
|
3945
3968
|
return;
|
|
3946
3969
|
}
|
|
3970
|
+
if (this.#isEmptyMessageShell(message)) {
|
|
3971
|
+
return;
|
|
3972
|
+
}
|
|
3973
|
+
if (stored.key.id && this.#deliveredMessageStore.has(deliveryKey)) {
|
|
3974
|
+
this.#duplicateMessages += 1;
|
|
3975
|
+
this.#emitMessageDiscarded("duplicate", stored.key);
|
|
3976
|
+
this.#logger.debug("Ignored duplicate Zapo message event.", {
|
|
3977
|
+
messageId: stored.key.id,
|
|
3978
|
+
chatId: stored.key.remoteJid ?? void 0
|
|
3979
|
+
});
|
|
3980
|
+
return;
|
|
3981
|
+
}
|
|
3947
3982
|
if (stored.key.id) this.#rememberDeliveredMessage(deliveryKey);
|
|
3948
3983
|
this.#receivedMessages += 1;
|
|
3949
3984
|
this.#lastIncomingAt = /* @__PURE__ */ new Date();
|
|
@@ -5066,6 +5101,9 @@ var ZapoProvider = class {
|
|
|
5066
5101
|
return void 0;
|
|
5067
5102
|
}
|
|
5068
5103
|
}
|
|
5104
|
+
#isEmptyMessageShell(message) {
|
|
5105
|
+
return message.contentKind === "unknown" && message.text === void 0 && message.caption === void 0 && message.media === void 0 && message.interactive === void 0 && (message.protocolKinds?.length ?? 0) === 0 && (message.payloadKinds?.length ?? 0) === 0;
|
|
5106
|
+
}
|
|
5069
5107
|
#messageStoreKey(key) {
|
|
5070
5108
|
return `${key.remoteJid ?? ""}:${key.id ?? ""}:${key.participant ?? key.participantAlt ?? ""}`;
|
|
5071
5109
|
}
|