mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-25 01:48:39 -06:00
Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop
This commit is contained in:
commit
9945d8debb
@ -25,7 +25,14 @@ export async function useMultiFileAuthStateDb(
|
|||||||
const writeData = async (data: any, key: string): Promise<any> => {
|
const writeData = async (data: any, key: string): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
return await collection.replaceOne({ _id: key }, JSON.parse(JSON.stringify(data, BufferJSON.replacer)), {
|
let msgParsed = JSON.parse(JSON.stringify(data, BufferJSON.replacer));
|
||||||
|
if (Array.isArray(msgParsed)) {
|
||||||
|
msgParsed = {
|
||||||
|
_id: key,
|
||||||
|
content_array: msgParsed,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return await collection.replaceOne({ _id: key }, msgParsed, {
|
||||||
upsert: true,
|
upsert: true,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -36,7 +43,10 @@ export async function useMultiFileAuthStateDb(
|
|||||||
const readData = async (key: string): Promise<any> => {
|
const readData = async (key: string): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
const data = await collection.findOne({ _id: key });
|
let data = (await collection.findOne({ _id: key })) as any;
|
||||||
|
if (data?.content_array) {
|
||||||
|
data = data.content_array;
|
||||||
|
}
|
||||||
const creds = JSON.stringify(data);
|
const creds = JSON.stringify(data);
|
||||||
return JSON.parse(creds, BufferJSON.reviver);
|
return JSON.parse(creds, BufferJSON.reviver);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -338,14 +338,18 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('update contact in chatwoot');
|
this.logger.verbose('update contact in chatwoot');
|
||||||
const contact = await client.contacts.update({
|
try {
|
||||||
accountId: this.provider.account_id,
|
const contact = await client.contacts.update({
|
||||||
id,
|
accountId: this.provider.account_id,
|
||||||
data,
|
id,
|
||||||
});
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
this.logger.verbose('contact updated');
|
this.logger.verbose('contact updated');
|
||||||
return contact;
|
return contact;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findContact(instance: InstanceDto, phoneNumber: string) {
|
public async findContact(instance: InstanceDto, phoneNumber: string) {
|
||||||
@ -488,6 +492,9 @@ export class ChatwootService {
|
|||||||
avatar_url: picture_url.profilePictureUrl || null,
|
avatar_url: picture_url.profilePictureUrl || null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!contact) {
|
||||||
|
contact = await this.findContact(instance, chatId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const jid = isGroup ? null : body.key.remoteJid;
|
const jid = isGroup ? null : body.key.remoteJid;
|
||||||
contact = await this.createContact(
|
contact = await this.createContact(
|
||||||
|
@ -369,7 +369,7 @@ export class TypebotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.underline) {
|
if (element.underline) {
|
||||||
text = `~${text}~`;
|
text = `*${text}*`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.url) {
|
if (element.url) {
|
||||||
|
@ -2283,6 +2283,21 @@ export class WAStartupService {
|
|||||||
!message['conversation'] &&
|
!message['conversation'] &&
|
||||||
sender !== 'status@broadcast'
|
sender !== 'status@broadcast'
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
if (message['reactionMessage']) {
|
||||||
|
this.logger.verbose('Sending reaction');
|
||||||
|
return await this.client.sendMessage(
|
||||||
|
sender,
|
||||||
|
{
|
||||||
|
react: {
|
||||||
|
text: message['reactionMessage']['text'],
|
||||||
|
key: message['reactionMessage']['key']
|
||||||
|
}
|
||||||
|
} as unknown as AnyMessageContent,
|
||||||
|
option as unknown as MiscMessageGenerationOptions,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!message['audio']) {
|
if (!message['audio']) {
|
||||||
this.logger.verbose('Sending message');
|
this.logger.verbose('Sending message');
|
||||||
return await this.client.sendMessage(
|
return await this.client.sendMessage(
|
||||||
@ -2298,7 +2313,6 @@ export class WAStartupService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message['conversation']) {
|
if (message['conversation']) {
|
||||||
this.logger.verbose('Sending message');
|
this.logger.verbose('Sending message');
|
||||||
return await this.client.sendMessage(
|
return await this.client.sendMessage(
|
||||||
@ -2346,7 +2360,7 @@ export class WAStartupService {
|
|||||||
this.logger.log(messageRaw);
|
this.logger.log(messageRaw);
|
||||||
|
|
||||||
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
|
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
|
||||||
await this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
|
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
|
||||||
|
|
||||||
if (this.localChatwoot.enabled && !isChatwoot) {
|
if (this.localChatwoot.enabled && !isChatwoot) {
|
||||||
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
|
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
|
||||||
|
Loading…
Reference in New Issue
Block a user