mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-25 18:08:40 -06:00
Ajustes
This commit is contained in:
parent
ec2b7f94f8
commit
0156c8d0c1
10
BuildImage.ps1
Normal file
10
BuildImage.ps1
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
(Get-ECRLoginCommand).Password | docker login --username AWS --password-stdin 130811782740.dkr.ecr.us-east-2.amazonaws.com
|
||||||
|
#
|
||||||
|
# Build da imagem com a tag correta
|
||||||
|
docker build -t evolution:2.1.2.debug -f ./Dockerfile .
|
||||||
|
|
||||||
|
# Tag para o ECR
|
||||||
|
docker tag evolution:2.1.2.debug 130811782740.dkr.ecr.us-east-2.amazonaws.com/evolution
|
||||||
|
|
||||||
|
# Push para o ECR (após login)
|
||||||
|
docker push 130811782740.dkr.ecr.us-east-2.amazonaws.com/evolution
|
@ -426,16 +426,20 @@ export class ChatwootService {
|
|||||||
let contact: any;
|
let contact: any;
|
||||||
|
|
||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
|
this.logger.verbose(`Searching for group contact with query: ${query}`);
|
||||||
contact = await client.contacts.search({
|
contact = await client.contacts.search({
|
||||||
accountId: this.provider.accountId,
|
accountId: this.provider.accountId,
|
||||||
q: query,
|
q: query,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
const payload = this.getFilterPayload(query);
|
||||||
|
this.logger.verbose(`Payload for contact filter: ${JSON.stringify(payload, null, 2)}`);
|
||||||
|
|
||||||
contact = await chatwootRequest(this.getClientCwConfig(), {
|
contact = await chatwootRequest(this.getClientCwConfig(), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: `/api/v1/accounts/${this.provider.accountId}/contacts/filter`,
|
url: `/api/v1/accounts/${this.provider.accountId}/contacts/filter`,
|
||||||
body: {
|
body: {
|
||||||
payload: this.getFilterPayload(query),
|
payload: payload,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -445,6 +449,8 @@ export class ChatwootService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose(`Response from contact search: ${JSON.stringify(contact, null, 2)}`);
|
||||||
|
|
||||||
if (!isGroup) {
|
if (!isGroup) {
|
||||||
return contact.payload.length > 1 ? this.findContactInContactList(contact.payload, query) : contact.payload[0];
|
return contact.payload.length > 1 ? this.findContactInContactList(contact.payload, query) : contact.payload[0];
|
||||||
} else {
|
} else {
|
||||||
@ -452,6 +458,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async mergeBrazilianContacts(contacts: any[]) {
|
private async mergeBrazilianContacts(contacts: any[]) {
|
||||||
try {
|
try {
|
||||||
const contact = await chatwootRequest(this.getClientCwConfig(), {
|
const contact = await chatwootRequest(this.getClientCwConfig(), {
|
||||||
@ -547,6 +554,7 @@ export class ChatwootService {
|
|||||||
try {
|
try {
|
||||||
this.logger.verbose('--- Start createConversation ---');
|
this.logger.verbose('--- Start createConversation ---');
|
||||||
this.logger.verbose(`Instance: ${JSON.stringify(instance)}`);
|
this.logger.verbose(`Instance: ${JSON.stringify(instance)}`);
|
||||||
|
this.logger.verbose(`Body: ${JSON.stringify(body)}`);
|
||||||
|
|
||||||
const client = await this.clientCw(instance);
|
const client = await this.clientCw(instance);
|
||||||
|
|
||||||
@ -554,6 +562,7 @@ export class ChatwootService {
|
|||||||
this.logger.warn(`Client not found for instance: ${JSON.stringify(instance)}`);
|
this.logger.warn(`Client not found for instance: ${JSON.stringify(instance)}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
this.logger.verbose(`Client obtained: ${JSON.stringify(client)}`);
|
||||||
|
|
||||||
const cacheKey = `${instance.instanceName}:createConversation-${body.key.remoteJid}`;
|
const cacheKey = `${instance.instanceName}:createConversation-${body.key.remoteJid}`;
|
||||||
this.logger.verbose(`Cache key: ${cacheKey}`);
|
this.logger.verbose(`Cache key: ${cacheKey}`);
|
||||||
@ -570,7 +579,7 @@ export class ChatwootService {
|
|||||||
});
|
});
|
||||||
this.logger.verbose(`Conversation exists: ${JSON.stringify(conversationExists)}`);
|
this.logger.verbose(`Conversation exists: ${JSON.stringify(conversationExists)}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error getting conversation: ${error}`);
|
this.logger.error(`Error getting conversation: ${JSON.stringify(error)}`);
|
||||||
conversationExists = false;
|
conversationExists = false;
|
||||||
}
|
}
|
||||||
if (!conversationExists) {
|
if (!conversationExists) {
|
||||||
@ -594,6 +603,7 @@ export class ChatwootService {
|
|||||||
this.logger.verbose(`Name contact: ${nameContact}`);
|
this.logger.verbose(`Name contact: ${nameContact}`);
|
||||||
|
|
||||||
const filterInbox = await this.getInbox(instance);
|
const filterInbox = await this.getInbox(instance);
|
||||||
|
this.logger.verbose(`Filter inbox: ${JSON.stringify(filterInbox)}`);
|
||||||
|
|
||||||
if (!filterInbox) {
|
if (!filterInbox) {
|
||||||
this.logger.warn(`Inbox not found for instance: ${JSON.stringify(instance)}`);
|
this.logger.warn(`Inbox not found for instance: ${JSON.stringify(instance)}`);
|
||||||
@ -607,25 +617,26 @@ export class ChatwootService {
|
|||||||
|
|
||||||
nameContact = `${group.subject} (GROUP)`;
|
nameContact = `${group.subject} (GROUP)`;
|
||||||
|
|
||||||
const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(
|
const participantId = body.key.participant.split('@')[0];
|
||||||
body.key.participant.split('@')[0],
|
const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(participantId);
|
||||||
);
|
|
||||||
this.logger.verbose(`Participant profile picture URL: ${JSON.stringify(picture_url)}`);
|
this.logger.verbose(`Participant profile picture URL: ${JSON.stringify(picture_url)}`);
|
||||||
|
|
||||||
const findParticipant = await this.findContact(instance, body.key.participant.split('@')[0]);
|
const findParticipant = await this.findContact(instance, participantId);
|
||||||
this.logger.verbose(`Found participant: ${JSON.stringify(findParticipant)}`);
|
this.logger.verbose(`Found participant: ${JSON.stringify(findParticipant)}`);
|
||||||
|
|
||||||
if (findParticipant) {
|
if (findParticipant) {
|
||||||
if (!findParticipant.name || findParticipant.name === chatId) {
|
if (!findParticipant.name || findParticipant.name === chatId) {
|
||||||
|
this.logger.verbose(`Updating participant contact with ID: ${findParticipant.id}`);
|
||||||
await this.updateContact(instance, findParticipant.id, {
|
await this.updateContact(instance, findParticipant.id, {
|
||||||
name: body.pushName,
|
name: body.pushName,
|
||||||
avatar_url: picture_url.profilePictureUrl || null,
|
avatar_url: picture_url.profilePictureUrl || null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.verbose('Creating participant contact');
|
||||||
await this.createContact(
|
await this.createContact(
|
||||||
instance,
|
instance,
|
||||||
body.key.participant.split('@')[0],
|
participantId,
|
||||||
filterInbox.id,
|
filterInbox.id,
|
||||||
false,
|
false,
|
||||||
body.pushName,
|
body.pushName,
|
||||||
@ -660,15 +671,18 @@ export class ChatwootService {
|
|||||||
this.logger.verbose(`Name needs update: ${nameNeedsUpdate}`);
|
this.logger.verbose(`Name needs update: ${nameNeedsUpdate}`);
|
||||||
|
|
||||||
if (pictureNeedsUpdate || nameNeedsUpdate) {
|
if (pictureNeedsUpdate || nameNeedsUpdate) {
|
||||||
|
this.logger.verbose(`Updating contact with ID: ${contact.id}`);
|
||||||
contact = await this.updateContact(instance, contact.id, {
|
contact = await this.updateContact(instance, contact.id, {
|
||||||
...(nameNeedsUpdate && { name: nameContact }),
|
...(nameNeedsUpdate && { name: nameContact }),
|
||||||
...(waProfilePictureFile === '' && { avatar: null }),
|
...(waProfilePictureFile === '' && { avatar: null }),
|
||||||
...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
|
...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
|
||||||
});
|
});
|
||||||
|
this.logger.verbose(`Contact after update: ${JSON.stringify(contact)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const jid = body.key.remoteJid;
|
const jid = body.key.remoteJid;
|
||||||
|
this.logger.verbose('Creating new contact');
|
||||||
contact = await this.createContact(
|
contact = await this.createContact(
|
||||||
instance,
|
instance,
|
||||||
chatId,
|
chatId,
|
||||||
@ -678,6 +692,7 @@ export class ChatwootService {
|
|||||||
picture_url.profilePictureUrl || null,
|
picture_url.profilePictureUrl || null,
|
||||||
jid,
|
jid,
|
||||||
);
|
);
|
||||||
|
this.logger.verbose(`Contact created: ${JSON.stringify(contact)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contact) {
|
if (!contact) {
|
||||||
@ -707,6 +722,7 @@ export class ChatwootService {
|
|||||||
|
|
||||||
if (this.provider.conversationPending) {
|
if (this.provider.conversationPending) {
|
||||||
if (conversation) {
|
if (conversation) {
|
||||||
|
this.logger.verbose(`Setting conversation status to pending for conversation ID: ${conversation.id}`);
|
||||||
await client.conversations.toggleStatus({
|
await client.conversations.toggleStatus({
|
||||||
accountId: this.provider.accountId,
|
accountId: this.provider.accountId,
|
||||||
conversationId: conversation.id,
|
conversationId: conversation.id,
|
||||||
@ -739,11 +755,15 @@ export class ChatwootService {
|
|||||||
data['status'] = 'pending';
|
data['status'] = 'pending';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.verbose(`Creating conversation with data: ${JSON.stringify(data)}`);
|
||||||
|
|
||||||
const conversation = await client.conversations.create({
|
const conversation = await client.conversations.create({
|
||||||
accountId: this.provider.accountId,
|
accountId: this.provider.accountId,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logger.verbose(`Conversation created: ${JSON.stringify(conversation)}`);
|
||||||
|
|
||||||
if (!conversation) {
|
if (!conversation) {
|
||||||
this.logger.warn('Conversation not created or found');
|
this.logger.warn('Conversation not created or found');
|
||||||
return null;
|
return null;
|
||||||
@ -753,10 +773,11 @@ export class ChatwootService {
|
|||||||
this.cache.set(cacheKey, conversation.id);
|
this.cache.set(cacheKey, conversation.id);
|
||||||
return conversation.id;
|
return conversation.id;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error in createConversation: ${error}`);
|
this.logger.error(`Error in createConversation: ${JSON.stringify(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async getInbox(instance: InstanceDto): Promise<inbox | null> {
|
public async getInbox(instance: InstanceDto): Promise<inbox | null> {
|
||||||
const cacheKey = `${instance.instanceName}:getInbox`;
|
const cacheKey = `${instance.instanceName}:getInbox`;
|
||||||
if (await this.cache.has(cacheKey)) {
|
if (await this.cache.has(cacheKey)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user