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
10 changes: 7 additions & 3 deletions src/api/abstract/abstract.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export abstract class RouterBroker {
const { request, ClassRef, schema, execute } = args;

const instance = request.params as unknown as InstanceDto;
const body = request.body;
// A GET without "Content-Type: application/json" arrives with request.body undefined,
// because express.json() only populates the body on JSON requests.
const body = request.body ?? {};

let groupJid = body?.groupJid;

Expand Down Expand Up @@ -169,7 +171,8 @@ export abstract class RouterBroker {
}

const instance = request.params as unknown as InstanceDto;
const body = request.body;
// A GET without "Content-Type: application/json" arrives with request.body undefined.
const body = request.body ?? {};

const ref = new ClassRef();

Expand Down Expand Up @@ -208,7 +211,8 @@ export abstract class RouterBroker {
}

const instance = request.params as unknown as InstanceDto;
const body = request.body;
// A GET without "Content-Type: application/json" arrives with request.body undefined.
const body = request.body ?? {};

const ref = new ClassRef();

Expand Down
16 changes: 11 additions & 5 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4920,14 +4920,14 @@ export class BaileysStartupService extends ChannelStartupService {
subjectOwner: group.subjectOwner,
subjectTime: group.subjectTime,
pictureUrl: picture.profilePictureUrl,
size: group.participants.length,
size: group.participants?.length ?? 0,
creation: group.creation,
owner: group.owner,
desc: group.desc,
descId: group.descId,
restrict: group.restrict,
announce: group.announce,
participants: group.participants,
participants: group.participants ?? [],
isCommunity: group.isCommunity,
isCommunityAnnounce: group.isCommunityAnnounce,
linkedParent: group.linkedParent,
Expand All @@ -4941,10 +4941,16 @@ export class BaileysStartupService extends ChannelStartupService {
}

public async fetchAllGroups(getParticipants: GetParticipant) {
const fetch = Object.values(await this?.client?.groupFetchAllParticipating());
// groupFetchAllParticipating() can resolve to undefined/null (for example when the Baileys
// store is not synced yet right after a reconnection), which made Object.values throw
// "Cannot convert undefined or null to object".
const allGroups = await this?.client?.groupFetchAllParticipating();
const fetch = allGroups ? Object.values(allGroups) : [];

let groups = [];
for (const group of fetch) {
if (!group) continue;

const picture = await this.profilePicture(group.id);

const result = {
Expand All @@ -4953,7 +4959,7 @@ export class BaileysStartupService extends ChannelStartupService {
subjectOwner: group.subjectOwner,
subjectTime: group.subjectTime,
pictureUrl: picture?.profilePictureUrl,
size: group.participants.length,
size: group.participants?.length ?? 0,
creation: group.creation,
owner: group.owner,
desc: group.desc,
Expand All @@ -4966,7 +4972,7 @@ export class BaileysStartupService extends ChannelStartupService {
};

if (getParticipants.getParticipants == 'true') {
result['participants'] = group.participants;
result['participants'] = group.participants ?? [];
}

groups = [...groups, result];
Expand Down