Open leroyanders opened 1 month ago
Started getting this error too (JSON is formatted for readability):
{
"level": 50,
"time": "2024-08-18T22:19:26.098Z",
"pid": 1753026,
"hostname": "XXXXX",
"err": {
"type": "Error",
"message": "bad-request",
"stack": "Error: bad-request\n at assertNodeErrorFree (/home/ubuntu/projects/Baileys2/src/WABinary/generic-utils.ts:55:9)\n at query (/home/ubuntu/projects/Baileys2/src/Socket/socket.ts:180:23)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async fetchProps (/home/ubuntu/projects/Baileys2/src/Socket/chats.ts:742:22)\n at async Promise.all (index 1)\n at async executeInitQueries (/home/ubuntu/projects/Baileys2/src/Socket/chats.ts:827:3)",
"data": 400,
"isBoom": true,
"isServer": true,
"output": {
"statusCode": 500,
"payload": {
"statusCode": 500,
"error": "Internal Server Error",
"message": "An internal server error occurred"
},
"headers": {}
}
},
"msg": "unexpected error in 'init queries'"
}
here's my code: `import { Injectable } from '@nestjs/common'; import { WsException } from '@nestjs/websockets'; import { User } from '@prisma/client'; import makeWASocket, { AuthenticationState, useMultiFileAuthState, DisconnectReason, ConnectionState, } from 'baileys'; import MAIN_LOGGER from 'baileys/lib/Utils/logger'; import { CustomLogger } from '../../../common/loggers'; import { handleException } from '../../../handlers'; import { MessageBuilder } from '../../../patterns/builders'; import { CloudStorageService } from '../../cloud-storage/services'; import { CreateAttachmentDto } from '../../websocket/dtos/attachment'; import { MessageDto, ReturnMessageDto } from '../../websocket/dtos'; import { ChatService, WebSocketService } from '../../websocket/services'; import { ServerWithEvents, SocketWithEvents } from '../../websocket/types'; import { AttachmentType, MessageWith, ReactionsType, ReplyType, } from '../../websocket/types/dtos'; import { Boom } from '@hapi/boom'; import { readyHandler } from '../handlers';
MAIN_LOGGER.child({}).level = 'silent';
@Injectable() export class BaileysService { private readonly logger = new CustomLogger(this.constructor.name); private clients: Map<string, any> = new Map(); private authStates: Map<string, AuthenticationState> = new Map(); static phoneNumberExtension = '@c.us';
private getClientId(userId: number): string { return
user-id-${userId}
; }constructor( private readonly chatService: ChatService, private readonly cloudStorage: CloudStorageService, ) {}
private async reauthorizeClient( user: User, socket: SocketWithEvents, server: ServerWithEvents, ): Promise {
const clientId = this.getClientId(user.id);
const { state, saveCreds } = await useMultiFileAuthState(
./auth_info/${clientId}
, );}
getClientByUserId(userId: number): any { const clientId = this.getClientId(userId); const client = this.clients.get(clientId);
}
async createWhatsAppSession( socket: SocketWithEvents, user: User, server: ServerWithEvents, ): Promise {
await this.reauthorizeClient(user, socket, server);
}
async closeWhatsAppSession( user: User, socket: SocketWithEvents, ): Promise {
const clientId = this.getClientId(user.id);
const clientToClose = this.clients.get(clientId);
}
async isRegisteredWAUser( userId: number, phoneNumber: string, ): Promise {
const client = this.getClientByUserId(userId);
const [result] = await client.onWhatsApp(phoneNumber);
}
async getWAContactByPhoneNumber( userId: number, phoneNumber: string, ): Promise<string | null> { const client = this.getClientByUserId(userId); const [result] = await client.onWhatsApp(phoneNumber);
}
async sendMessage( userId: number, whatsappChatId: string, messageBody: string, createAttachmentDto?: CreateAttachmentDto, ): Promise {
const client = this.getClientByUserId(userId);
await this.isChatIdValid(whatsappChatId, userId);
}
async replyToMessage( userId: number, repliedMessageId: string, whatsappChatId: string, messageBody: string, createAttachmentDto?: CreateAttachmentDto, ): Promise {
await this.isChatIdValid(whatsappChatId, userId);
}
async getContactsByUserId(userId: number): Promise {
const client = this.getClientByUserId(userId);
return await client.getContacts();
}
async getChatsByUserId(userId: number, contactId: string): Promise<any[]> { const client = this.getClientByUserId(userId); const chats = await client.getChats();
}
async getChatById(userId: number, whatsappChatId: string): Promise {
const client = this.getClientByUserId(userId);
return await client.getChat(whatsappChatId);
}
async getMessagesFromChat(chat: any): Promise<any[]> { return await chat.messages; }
async ensureClientConnected(userId: number): Promise {
const client = this.getClientByUserId(userId);
}
async getMessageById(userId: number, id: string): Promise {
await this.ensureClientConnected(userId);
const client = this.getClientByUserId(userId);
}
async getContactByUserId(userId: number): Promise {
const client = this.getClientByUserId(userId);
return await client.getContact(client.user.jid);
}
async sendChatSeen(userId: number, whatsappChatId: string) { const client = this.getClientByUserId(userId); await client.sendReadReceipt(whatsappChatId); }
async editMessage( messageId: string, newBody: string, userId: number, ): Promise {
const message = await this.getMessageById(userId, messageId);
await message.edit(newBody);
}
async setAttachmentReactionAndReply( message: any, ): Promise<MessageWith<AttachmentType & ReactionsType & ReplyType>> { const messageBuilder = new MessageBuilder(message);
}
async reactToMessage( messageId: string, userId: number, reaction: string, ): Promise {
const client = this.getClientByUserId(userId);
await client.sendMessage(messageId, {
react: { text: reaction },
});
}
async deleteMessage(messageId: string, userId: number): Promise {
const client = this.getClientByUserId(userId);
await client.sendMessage(messageId, { delete: true });
}
async isChatIdValid(chatId: string, userId: number): Promise {
const client = this.getClientByUserId(userId);
const [result] = await client.onWhatsApp(chatId);
} } `