mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 02:18:38 -06:00
Initial (barely) working version
This commit is contained in:
parent
7788d740bd
commit
96e42f25af
@ -11,10 +11,7 @@ const logger = new Logger('KwikController');
|
|||||||
|
|
||||||
type SearchObject = {
|
type SearchObject = {
|
||||||
text_search: string;
|
text_search: string;
|
||||||
where: {
|
where: string[];
|
||||||
owner: string;
|
|
||||||
messageTimestamp: Record<string, any>; // Generic key-value pair
|
|
||||||
}[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class KwikController {
|
export class KwikController {
|
||||||
@ -208,37 +205,45 @@ export class KwikController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async textSearch({ instanceName }: InstanceDto, query: SearchObject) {
|
public async textSearch({ instanceName }: InstanceDto, query: SearchObject) {
|
||||||
logger.error('request received in textSearch');
|
logger.verbose('request received in textSearch');
|
||||||
logger.error(instanceName);
|
logger.verbose(instanceName);
|
||||||
logger.error(query);
|
logger.verbose(query);
|
||||||
|
|
||||||
const db = configService.get<Database>('DATABASE');
|
const db = configService.get<Database>('DATABASE');
|
||||||
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
|
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
|
||||||
query.where.forEach((w) => {
|
|
||||||
logger.error(w.messageTimestamp);
|
|
||||||
logger.error(w.owner);
|
|
||||||
});
|
|
||||||
const messages = await connection
|
const messages = await connection
|
||||||
.collection('messages')
|
.collection('messages')
|
||||||
.find({
|
.find({
|
||||||
// $and: [
|
owner: { $in: query.where },
|
||||||
// {
|
|
||||||
// $or: query.where,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
$text: { $search: query.text_search },
|
$text: { $search: query.text_search },
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
})
|
})
|
||||||
.limit(10)
|
.limit(100)
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
// const conversations = messages.map((m) => `${m.owner}#${m.key.remoteJid}#${m.messageTimestamp}`);
|
const data = [];
|
||||||
// logger.error('DELETEME: messages -> ');
|
for (let i = 0; i < messages.length; i++) {
|
||||||
// logger.error(conversations);
|
const message = messages[i];
|
||||||
|
const info = message.key.remoteJid.split('@');
|
||||||
|
let type;
|
||||||
|
let tinfo;
|
||||||
|
if (info[1] == 'g.us') {
|
||||||
|
tinfo = await this.waMonitor.waInstances[message.owner].findGroup({ groupJid: message.key.remoteJid }, 'inner');
|
||||||
|
|
||||||
// logger.error(messages.length);
|
type = 'GROUP';
|
||||||
|
} else {
|
||||||
|
tinfo = await connection.collection('contacts').findOne({ owner: message.owner, id: message.key.remoteJid });
|
||||||
|
type = 'CONTACT';
|
||||||
|
}
|
||||||
|
data.push({
|
||||||
|
message: message,
|
||||||
|
|
||||||
return { messages };
|
owner: message.owner,
|
||||||
|
conversation: `${message.owner}#${info}`,
|
||||||
|
type: type,
|
||||||
|
info: tinfo,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { data };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user