Skip to content

Commit 119ceba

Browse files
committed
Adding a new webhook that triggers when a message is updated by the user
1 parent 427c994 commit 119ceba

File tree

8 files changed

+33
-3
lines changed

8 files changed

+33
-3
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ RABBITMQ_EVENTS_MESSAGES_EDITED=false
6262
RABBITMQ_EVENTS_MESSAGES_UPDATE=false
6363
RABBITMQ_EVENTS_MESSAGES_DELETE=false
6464
RABBITMQ_EVENTS_SEND_MESSAGE=false
65+
RABBITMQ_EVENTS_SEND_MESSAGE_UPDATE=false
6566
RABBITMQ_EVENTS_CONTACTS_SET=false
6667
RABBITMQ_EVENTS_CONTACTS_UPSERT=false
6768
RABBITMQ_EVENTS_CONTACTS_UPDATE=false
@@ -108,6 +109,7 @@ PUSHER_EVENTS_MESSAGES_EDITED=true
108109
PUSHER_EVENTS_MESSAGES_UPDATE=true
109110
PUSHER_EVENTS_MESSAGES_DELETE=true
110111
PUSHER_EVENTS_SEND_MESSAGE=true
112+
PUSHER_EVENTS_SEND_MESSAGE_UPDATE=true
111113
PUSHER_EVENTS_CONTACTS_SET=true
112114
PUSHER_EVENTS_CONTACTS_UPSERT=true
113115
PUSHER_EVENTS_CONTACTS_UPDATE=true
@@ -149,6 +151,7 @@ WEBHOOK_EVENTS_MESSAGES_EDITED=true
149151
WEBHOOK_EVENTS_MESSAGES_UPDATE=true
150152
WEBHOOK_EVENTS_MESSAGES_DELETE=true
151153
WEBHOOK_EVENTS_SEND_MESSAGE=true
154+
WEBHOOK_EVENTS_SEND_MESSAGE_UPDATE=true
152155
WEBHOOK_EVENTS_CONTACTS_SET=true
153156
WEBHOOK_EVENTS_CONTACTS_UPSERT=true
154157
WEBHOOK_EVENTS_CONTACTS_UPDATE=true

Docker/swarm/evolution_api_v2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ services:
3434
- RABBITMQ_EVENTS_MESSAGES_UPDATE=false
3535
- RABBITMQ_EVENTS_MESSAGES_DELETE=false
3636
- RABBITMQ_EVENTS_SEND_MESSAGE=false
37+
- RABBITMQ_EVENTS_SEND_MESSAGE_UPDATE=false
3738
- RABBITMQ_EVENTS_CONTACTS_SET=false
3839
- RABBITMQ_EVENTS_CONTACTS_UPSERT=false
3940
- RABBITMQ_EVENTS_CONTACTS_UPDATE=false
@@ -71,6 +72,7 @@ services:
7172
- WEBHOOK_EVENTS_MESSAGES_UPDATE=true
7273
- WEBHOOK_EVENTS_MESSAGES_DELETE=true
7374
- WEBHOOK_EVENTS_SEND_MESSAGE=true
75+
- WEBHOOK_EVENTS_SEND_MESSAGE_UPDATE=true
7476
- WEBHOOK_EVENTS_CONTACTS_SET=true
7577
- WEBHOOK_EVENTS_CONTACTS_UPSERT=true
7678
- WEBHOOK_EVENTS_CONTACTS_UPDATE=true

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,6 @@ export class BaileysStartupService extends ChannelStartupService {
11381138
{ instanceName: this.instance.name, instanceId: this.instance.id },
11391139
editedMessage,
11401140
);
1141-
11421141
await this.sendDataWebhook(Events.MESSAGES_EDITED, editedMessage);
11431142
}
11441143
}
@@ -3899,10 +3898,25 @@ export class BaileysStartupService extends ChannelStartupService {
38993898
}
39003899

39013900
try {
3902-
return await this.client.sendMessage(jid, {
3901+
const messageSent = await this.client.sendMessage(jid, {
39033902
...(options as any),
39043903
edit: data.key,
39053904
});
3905+
3906+
const updatedMessage =
3907+
messageSent.message?.protocolMessage || messageSent.message?.editedMessage?.message?.protocolMessage;
3908+
3909+
if (updatedMessage) {
3910+
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled)
3911+
this.chatwootService.eventWhatsapp(
3912+
'send.message.update',
3913+
{ instanceName: this.instance.name, instanceId: this.instance.id },
3914+
updatedMessage,
3915+
);
3916+
await this.sendDataWebhook(Events.SEND_MESSAGE_UPDATE, updatedMessage);
3917+
}
3918+
3919+
return messageSent;
39063920
} catch (error) {
39073921
this.logger.error(error);
39083922
throw new BadRequestException(error.toString());

src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ export class ChatwootService {
21992199
}
22002200
}
22012201

2202-
if (event === 'messages.edit') {
2202+
if (event === 'messages.edit' || event === 'send.message.update') {
22032203
const editedText = `${
22042204
body?.editedMessage?.conversation || body?.editedMessage?.extendedTextMessage?.text
22052205
}\n\n_\`${i18next.t('cw.message.edited')}.\`_`;

src/api/integrations/event/event.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class EventController {
132132
'MESSAGES_UPDATE',
133133
'MESSAGES_DELETE',
134134
'SEND_MESSAGE',
135+
'SEND_MESSAGE_UPDATE',
135136
'CONTACTS_SET',
136137
'CONTACTS_UPSERT',
137138
'CONTACTS_UPDATE',

src/api/types/wa.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export enum Events {
1515
MESSAGES_UPDATE = 'messages.update',
1616
MESSAGES_DELETE = 'messages.delete',
1717
SEND_MESSAGE = 'send.message',
18+
SEND_MESSAGE_UPDATE = 'send.message.update',
1819
CONTACTS_SET = 'contacts.set',
1920
CONTACTS_UPSERT = 'contacts.upsert',
2021
CONTACTS_UPDATE = 'contacts.update',

src/config/env.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export type EventsRabbitmq = {
7272
MESSAGES_UPDATE: boolean;
7373
MESSAGES_DELETE: boolean;
7474
SEND_MESSAGE: boolean;
75+
SEND_MESSAGE_UPDATE: boolean;
7576
CONTACTS_SET: boolean;
7677
CONTACTS_UPDATE: boolean;
7778
CONTACTS_UPSERT: boolean;
@@ -131,6 +132,7 @@ export type EventsWebhook = {
131132
MESSAGES_UPDATE: boolean;
132133
MESSAGES_DELETE: boolean;
133134
SEND_MESSAGE: boolean;
135+
SEND_MESSAGE_UPDATE: boolean;
134136
CONTACTS_SET: boolean;
135137
CONTACTS_UPDATE: boolean;
136138
CONTACTS_UPSERT: boolean;
@@ -163,6 +165,7 @@ export type EventsPusher = {
163165
MESSAGES_UPDATE: boolean;
164166
MESSAGES_DELETE: boolean;
165167
SEND_MESSAGE: boolean;
168+
SEND_MESSAGE_UPDATE: boolean;
166169
CONTACTS_SET: boolean;
167170
CONTACTS_UPDATE: boolean;
168171
CONTACTS_UPSERT: boolean;
@@ -370,6 +373,7 @@ export class ConfigService {
370373
MESSAGES_UPDATE: process.env?.RABBITMQ_EVENTS_MESSAGES_UPDATE === 'true',
371374
MESSAGES_DELETE: process.env?.RABBITMQ_EVENTS_MESSAGES_DELETE === 'true',
372375
SEND_MESSAGE: process.env?.RABBITMQ_EVENTS_SEND_MESSAGE === 'true',
376+
SEND_MESSAGE_UPDATE: process.env?.RABBITMQ_EVENTS_SEND_MESSAGE_UPDATE === 'true',
373377
CONTACTS_SET: process.env?.RABBITMQ_EVENTS_CONTACTS_SET === 'true',
374378
CONTACTS_UPDATE: process.env?.RABBITMQ_EVENTS_CONTACTS_UPDATE === 'true',
375379
CONTACTS_UPSERT: process.env?.RABBITMQ_EVENTS_CONTACTS_UPSERT === 'true',
@@ -421,6 +425,7 @@ export class ConfigService {
421425
MESSAGES_UPDATE: process.env?.PUSHER_EVENTS_MESSAGES_UPDATE === 'true',
422426
MESSAGES_DELETE: process.env?.PUSHER_EVENTS_MESSAGES_DELETE === 'true',
423427
SEND_MESSAGE: process.env?.PUSHER_EVENTS_SEND_MESSAGE === 'true',
428+
SEND_MESSAGE_UPDATE: process.env?.PUSHER_EVENTS_SEND_MESSAGE_UPDATE === 'true',
424429
CONTACTS_SET: process.env?.PUSHER_EVENTS_CONTACTS_SET === 'true',
425430
CONTACTS_UPDATE: process.env?.PUSHER_EVENTS_CONTACTS_UPDATE === 'true',
426431
CONTACTS_UPSERT: process.env?.PUSHER_EVENTS_CONTACTS_UPSERT === 'true',
@@ -477,6 +482,7 @@ export class ConfigService {
477482
MESSAGES_UPDATE: process.env?.WEBHOOK_EVENTS_MESSAGES_UPDATE === 'true',
478483
MESSAGES_DELETE: process.env?.WEBHOOK_EVENTS_MESSAGES_DELETE === 'true',
479484
SEND_MESSAGE: process.env?.WEBHOOK_EVENTS_SEND_MESSAGE === 'true',
485+
SEND_MESSAGE_UPDATE: process.env?.WEBHOOK_EVENTS_SEND_MESSAGE_UPDATE === 'true',
480486
CONTACTS_SET: process.env?.WEBHOOK_EVENTS_CONTACTS_SET === 'true',
481487
CONTACTS_UPDATE: process.env?.WEBHOOK_EVENTS_CONTACTS_UPDATE === 'true',
482488
CONTACTS_UPSERT: process.env?.WEBHOOK_EVENTS_CONTACTS_UPSERT === 'true',

src/validate/instance.schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const instanceSchema: JSONSchema7 = {
6868
'MESSAGES_UPDATE',
6969
'MESSAGES_DELETE',
7070
'SEND_MESSAGE',
71+
'SEND_MESSAGE_UPDATE',
7172
'CONTACTS_SET',
7273
'CONTACTS_UPSERT',
7374
'CONTACTS_UPDATE',
@@ -104,6 +105,7 @@ export const instanceSchema: JSONSchema7 = {
104105
'MESSAGES_UPDATE',
105106
'MESSAGES_DELETE',
106107
'SEND_MESSAGE',
108+
'SEND_MESSAGE_UPDATE',
107109
'CONTACTS_SET',
108110
'CONTACTS_UPSERT',
109111
'CONTACTS_UPDATE',
@@ -140,6 +142,7 @@ export const instanceSchema: JSONSchema7 = {
140142
'MESSAGES_UPDATE',
141143
'MESSAGES_DELETE',
142144
'SEND_MESSAGE',
145+
'SEND_MESSAGE_UPDATE',
143146
'CONTACTS_SET',
144147
'CONTACTS_UPSERT',
145148
'CONTACTS_UPDATE',

0 commit comments

Comments
 (0)