mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-19 09:53:36 -06:00
Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop
This commit is contained in:
commit
4cd30dabc4
@ -122,6 +122,8 @@ TYPEBOT_KEEP_OPEN=false
|
|||||||
#Chatwoot
|
#Chatwoot
|
||||||
# If you leave this option as false, when deleting the message for everyone on WhatsApp, it will not be deleted on Chatwoot.
|
# If you leave this option as false, when deleting the message for everyone on WhatsApp, it will not be deleted on Chatwoot.
|
||||||
CHATWOOT_MESSAGE_DELETE=false # false | true
|
CHATWOOT_MESSAGE_DELETE=false # false | true
|
||||||
|
# If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp.
|
||||||
|
CHATWOOT_MESSAGE_READ=false # false | true
|
||||||
# This db connection is used to import messages from whatsapp to chatwoot database
|
# This db connection is used to import messages from whatsapp to chatwoot database
|
||||||
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname
|
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname
|
||||||
CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE=true
|
CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE=true
|
||||||
@ -139,3 +141,5 @@ AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
|||||||
# seconds - 3600s ===1h | zero (0) - never expires
|
# seconds - 3600s ===1h | zero (0) - never expires
|
||||||
AUTHENTICATION_JWT_EXPIRIN_IN=0
|
AUTHENTICATION_JWT_EXPIRIN_IN=0
|
||||||
AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
|
AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
|
||||||
|
|
||||||
|
LANGUAGE=en # pt-BR, en
|
@ -164,6 +164,7 @@ export type QrCode = { LIMIT: number; COLOR: string };
|
|||||||
export type Typebot = { API_VERSION: string; KEEP_OPEN: boolean };
|
export type Typebot = { API_VERSION: string; KEEP_OPEN: boolean };
|
||||||
export type Chatwoot = {
|
export type Chatwoot = {
|
||||||
MESSAGE_DELETE: boolean;
|
MESSAGE_DELETE: boolean;
|
||||||
|
MESSAGE_READ: boolean;
|
||||||
IMPORT: {
|
IMPORT: {
|
||||||
DATABASE: {
|
DATABASE: {
|
||||||
CONNECTION: {
|
CONNECTION: {
|
||||||
@ -379,10 +380,11 @@ export class ConfigService {
|
|||||||
},
|
},
|
||||||
CHATWOOT: {
|
CHATWOOT: {
|
||||||
MESSAGE_DELETE: process.env.CHATWOOT_MESSAGE_DELETE === 'false',
|
MESSAGE_DELETE: process.env.CHATWOOT_MESSAGE_DELETE === 'false',
|
||||||
|
MESSAGE_READ: process.env.CHATWOOT_MESSAGE_READ === 'false',
|
||||||
IMPORT: {
|
IMPORT: {
|
||||||
DATABASE: {
|
DATABASE: {
|
||||||
CONNECTION: {
|
CONNECTION: {
|
||||||
URI: process.env.CHATWOOT_DATABASE_CONNECTION_URI || '',
|
URI: process.env.CHATWOOT_IMPORT_DATABASE_CONNECTION_URI || '',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PLACEHOLDER_MEDIA_MESSAGE: process.env?.CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE === 'true',
|
PLACEHOLDER_MEDIA_MESSAGE: process.env?.CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE === 'true',
|
||||||
|
@ -166,6 +166,8 @@ TYPEBOT:
|
|||||||
CHATWOOT:
|
CHATWOOT:
|
||||||
# If you leave this option as false, when deleting the message for everyone on WhatsApp, it will not be deleted on Chatwoot.
|
# If you leave this option as false, when deleting the message for everyone on WhatsApp, it will not be deleted on Chatwoot.
|
||||||
MESSAGE_DELETE: true # false | true
|
MESSAGE_DELETE: true # false | true
|
||||||
|
# If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp.
|
||||||
|
MESSAGE_READ: false # false | true
|
||||||
IMPORT:
|
IMPORT:
|
||||||
# This db connection is used to import messages from whatsapp to chatwoot database
|
# This db connection is used to import messages from whatsapp to chatwoot database
|
||||||
DATABASE:
|
DATABASE:
|
||||||
|
@ -21,5 +21,6 @@
|
|||||||
"cw.locationMessage.locationUrl": "URL",
|
"cw.locationMessage.locationUrl": "URL",
|
||||||
"cw.contactMessage.contact": "Contact",
|
"cw.contactMessage.contact": "Contact",
|
||||||
"cw.contactMessage.name": "Name",
|
"cw.contactMessage.name": "Name",
|
||||||
"cw.contactMessage.number": "Number"
|
"cw.contactMessage.number": "Number",
|
||||||
|
"cw.message.edited": "Edited Message"
|
||||||
}
|
}
|
@ -21,5 +21,6 @@
|
|||||||
"cw.locationMessage.locationUrl": "URL",
|
"cw.locationMessage.locationUrl": "URL",
|
||||||
"cw.contactMessage.contact": "Contato",
|
"cw.contactMessage.contact": "Contato",
|
||||||
"cw.contactMessage.name": "Nome",
|
"cw.contactMessage.name": "Nome",
|
||||||
"cw.contactMessage.number": "Número"
|
"cw.contactMessage.number": "Número",
|
||||||
|
"cw.message.edited": "Mensagem editada"
|
||||||
}
|
}
|
@ -15,6 +15,7 @@ class ChatwootMessage {
|
|||||||
inboxId?: number;
|
inboxId?: number;
|
||||||
conversationId?: number;
|
conversationId?: number;
|
||||||
contactInbox?: { sourceId: string };
|
contactInbox?: { sourceId: string };
|
||||||
|
isRead?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MessageRaw {
|
export class MessageRaw {
|
||||||
@ -36,8 +37,9 @@ export class MessageRaw {
|
|||||||
type MessageRawBoolean<T> = {
|
type MessageRawBoolean<T> = {
|
||||||
[P in keyof T]?: 0 | 1;
|
[P in keyof T]?: 0 | 1;
|
||||||
};
|
};
|
||||||
export type MessageRawSelect = Omit<MessageRawBoolean<MessageRaw>, 'key'> & {
|
export type MessageRawSelect = Omit<Omit<MessageRawBoolean<MessageRaw>, 'key'>, 'chatwoot'> & {
|
||||||
key?: MessageRawBoolean<Key>;
|
key?: MessageRawBoolean<Key>;
|
||||||
|
chatwoot?: MessageRawBoolean<ChatwootMessage>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageSchema = new Schema<MessageRaw>({
|
const messageSchema = new Schema<MessageRaw>({
|
||||||
@ -60,6 +62,7 @@ const messageSchema = new Schema<MessageRaw>({
|
|||||||
inboxId: { type: Number },
|
inboxId: { type: Number },
|
||||||
conversationId: { type: Number },
|
conversationId: { type: Number },
|
||||||
contactInbox: { type: Object },
|
contactInbox: { type: Object },
|
||||||
|
isRead: { type: Boolean },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ export class MessageRepository extends Repository {
|
|||||||
|
|
||||||
return await this.messageModel
|
return await this.messageModel
|
||||||
.find({ ...query.where })
|
.find({ ...query.where })
|
||||||
|
.select(query.select || {})
|
||||||
.sort({ messageTimestamp: -1 })
|
.sort({ messageTimestamp: -1 })
|
||||||
.limit(query?.limit ?? 0);
|
.limit(query?.limit ?? 0);
|
||||||
}
|
}
|
||||||
|
@ -1354,6 +1354,37 @@ export class ChatwootService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chatwootRead = this.configService.get<Chatwoot>('CHATWOOT').MESSAGE_READ;
|
||||||
|
if (chatwootRead) {
|
||||||
|
const lastMessage = await this.repository.message.find({
|
||||||
|
where: {
|
||||||
|
key: {
|
||||||
|
fromMe: false,
|
||||||
|
},
|
||||||
|
owner: instance.instanceName,
|
||||||
|
},
|
||||||
|
limit: 1,
|
||||||
|
});
|
||||||
|
if (lastMessage.length > 0 && !lastMessage[0].chatwoot?.isRead) {
|
||||||
|
waInstance?.markMessageAsRead({
|
||||||
|
read_messages: lastMessage.map((msg) => ({
|
||||||
|
id: msg.key?.id,
|
||||||
|
fromMe: msg.key?.fromMe,
|
||||||
|
remoteJid: msg.key?.remoteJid,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
const updateMessage = lastMessage.map((msg) => ({
|
||||||
|
key: msg.key,
|
||||||
|
owner: msg.owner,
|
||||||
|
chatwoot: {
|
||||||
|
...msg.chatwoot,
|
||||||
|
isRead: true,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
this.repository.message.update(updateMessage, instance.instanceName, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.message_type === 'template' && body.event === 'message_created') {
|
if (body.message_type === 'template' && body.event === 'message_created') {
|
||||||
@ -2047,6 +2078,34 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event === 'messages.edit') {
|
||||||
|
const editedText = `${
|
||||||
|
body?.editedMessage?.conversation || body?.editedMessage?.extendedTextMessage?.text
|
||||||
|
}\n\n_\`${i18next.t('cw.message.edited')}.\`_`;
|
||||||
|
const message = await this.getMessageByKeyId(instance, body?.key?.id);
|
||||||
|
const messageType = message.key?.fromMe ? 'outgoing' : 'incoming';
|
||||||
|
|
||||||
|
if (message && message.chatwoot?.conversationId) {
|
||||||
|
const send = await this.createMessage(
|
||||||
|
instance,
|
||||||
|
message.chatwoot.conversationId,
|
||||||
|
editedText,
|
||||||
|
messageType,
|
||||||
|
false,
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
message: { extendedTextMessage: { contextInfo: { stanzaId: message.key.id } } },
|
||||||
|
},
|
||||||
|
'WAID:' + body.key.id,
|
||||||
|
);
|
||||||
|
if (!send) {
|
||||||
|
this.logger.warn('edited message not sent');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event === 'messages.read') {
|
if (event === 'messages.read') {
|
||||||
this.logger.verbose('read message from instance: ' + instance.instanceName);
|
this.logger.verbose('read message from instance: ' + instance.instanceName);
|
||||||
|
|
||||||
|
@ -937,6 +937,17 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
try {
|
try {
|
||||||
this.logger.verbose('Event received: messages.upsert');
|
this.logger.verbose('Event received: messages.upsert');
|
||||||
for (const received of messages) {
|
for (const received of messages) {
|
||||||
|
if (
|
||||||
|
this.localChatwoot.enabled &&
|
||||||
|
(received.message?.protocolMessage?.editedMessage || received.message?.editedMessage?.message)
|
||||||
|
) {
|
||||||
|
const editedMessage =
|
||||||
|
received.message?.protocolMessage || received.message?.editedMessage?.message?.protocolMessage;
|
||||||
|
if (editedMessage) {
|
||||||
|
this.chatwootService.eventWhatsapp('messages.edit', { instanceName: this.instance.name }, editedMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(type !== 'notify' && type !== 'append') ||
|
(type !== 'notify' && type !== 'append') ||
|
||||||
received.message?.protocolMessage ||
|
received.message?.protocolMessage ||
|
||||||
|
Loading…
Reference in New Issue
Block a user