Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions src/core/engines/gows/session.gows.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { parseMessageIdSerialized } from '@waha/core/utils/ids';
import {
isJidBroadcast,
isJidGroup,
isLidUser,
toCusFormat,
toJID,
} from '@waha/core/utils/jids';
Expand Down Expand Up @@ -1865,15 +1866,43 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
}

protected async fetchChatSummary(chat): Promise<ChatSummary> {
const id = toCusFormat(chat.id);
const name = chat.name;
const originalId = chat.id;
let id = toCusFormat(chat.id);
let name = chat.name;
if (!name) {
try {
const jid = toJID(chat.id);
const request = new messages.EntityByIdRequest({
session: this.session,
id: jid,
});
const response = await promisify(this.client.GetContactById)(request);
const contactData = parseJson(response);
if (contactData) {
name = contactData.Name || contactData.PushName;
}
} catch (e) {
// Ignore contact lookup errors
}
}
// Resolve LID to phone number if possible
if (isLidUser(originalId)) {
try {
const resolved = await this.findPNByLid(originalId);
if (resolved.pn) {
id = resolved.pn;
}
} catch (e) {
// Keep LID format if resolution fails
}
}
const picture = await this.getContactProfilePicture(chat.id, false);
const messages = await this.getChatMessages(
const chatMessages = await this.getChatMessages(
chat.id,
{ limit: 1, offset: 0, downloadMedia: false },
{},
);
const message = messages.length > 0 ? messages[0] : null;
const message = chatMessages.length > 0 ? chatMessages[0] : null;
return {
id: id,
name: name || null,
Expand Down
17 changes: 15 additions & 2 deletions src/core/engines/webjs/session.webjs.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ import { WAJSPresenceChatStateType, WebJSPresence } from './types';
import {
isJidGroup,
isJidStatusBroadcast,
isLidUser,
normalizeJid,
toCusFormat,
} from '@waha/core/utils/jids';
Expand Down Expand Up @@ -1543,14 +1544,26 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {

@Activity()
public async getPresence(id: string): Promise<WAHAChatPresences> {
const chatId = toCusFormat(id);
let chatId = toCusFormat(id);
if (isLidUser(chatId)) {
const pn = await this.whatsapp.findPNByLid(chatId);
if (pn) {
chatId = toCusFormat(pn);
}
}
const presences = await this.whatsapp.getPresence(chatId);
return this.toWahaPresences(chatId, presences);
}

@Activity()
public async subscribePresence(id: string): Promise<any> {
const chatId = toCusFormat(id);
let chatId = toCusFormat(id);
if (isLidUser(chatId)) {
const pn = await this.whatsapp.findPNByLid(chatId);
if (pn) {
chatId = toCusFormat(pn);
}
}
await this.whatsapp.subscribePresence(chatId);
}

Expand Down