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
8 changes: 8 additions & 0 deletions src/utils/proto-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { WAProto as proto } from 'baileys';

export function deserializeAppStateSyncKey(type: string, value: unknown): unknown {
if (type === 'app-state-sync-key' && value) {
return proto.Message.AppStateSyncKeyData.fromObject(value);
}
return value;
}
5 changes: 2 additions & 3 deletions src/utils/use-multi-file-auth-state-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CacheConf, configService } from '@config/env.config';
import { Logger } from '@config/logger.config';
import { INSTANCE_DIR } from '@config/path.config';
import { AuthenticationState, BufferJSON, initAuthCreds, WAProto as proto } from 'baileys';
import { deserializeAppStateSyncKey } from './proto-helpers';
import fs from 'fs/promises';
import path from 'path';

Expand Down Expand Up @@ -181,9 +182,7 @@ export default async function useMultiFileAuthStatePrisma(
await Promise.all(
ids.map(async (id) => {
let value = await readData(`${type}-${id}`);
if (type === 'app-state-sync-key' && value) {
value = proto.Message.AppStateSyncKeyData.create(value);
}
value = deserializeAppStateSyncKey(type, value);

data[id] = value;
}),
Expand Down
5 changes: 2 additions & 3 deletions src/utils/use-multi-file-auth-state-provider-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import { ProviderFiles } from '@api/provider/sessions';
import { Logger } from '@config/logger.config';
import { AuthenticationCreds, AuthenticationState, BufferJSON, initAuthCreds, proto, SignalDataTypeMap } from 'baileys';
import { deserializeAppStateSyncKey } from './proto-helpers';
import { isNotEmpty } from 'class-validator';

export type AuthState = {
Expand Down Expand Up @@ -115,9 +116,7 @@ export class AuthStateProvider {
await Promise.all(
ids.map(async (id) => {
let value = await readData(`${type}-${id}`);
if (type === 'app-state-sync-key' && value) {
value = proto.Message.AppStateSyncKeyData.create(value);
}
value = deserializeAppStateSyncKey(type, value);

data[id] = value;
}),
Expand Down
5 changes: 2 additions & 3 deletions src/utils/use-multi-file-auth-state-redis-db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CacheService } from '@api/services/cache.service';
import { Logger } from '@config/logger.config';
import { AuthenticationCreds, AuthenticationState, initAuthCreds, proto, SignalDataTypeMap } from 'baileys';
import { deserializeAppStateSyncKey } from './proto-helpers';

export async function useMultiFileAuthStateRedisDb(
instanceName: string,
Expand Down Expand Up @@ -60,9 +61,7 @@ export async function useMultiFileAuthStateRedisDb(
await Promise.all(
ids.map(async (id) => {
let value = await readData(`${type}-${id}`);
if (type === 'app-state-sync-key' && value) {
value = proto.Message.AppStateSyncKeyData.create(value);
}
value = deserializeAppStateSyncKey(type, value);

data[id] = value;
}),
Expand Down