diff --git a/prisma/migrations/20240723200254_add_webhookurl_on_message/migration.sql b/prisma/migrations/20240723200254_add_webhookurl_on_message/migration.sql new file mode 100644 index 00000000..20567778 --- /dev/null +++ b/prisma/migrations/20240723200254_add_webhookurl_on_message/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Message" ADD COLUMN "webhookUrl" VARCHAR(500); diff --git a/prisma/postgresql-schema.prisma b/prisma/postgresql-schema.prisma index 358e1ccf..86c5cb03 100644 --- a/prisma/postgresql-schema.prisma +++ b/prisma/postgresql-schema.prisma @@ -135,6 +135,7 @@ model Message { Media Media? OpenaiSession OpenaiSession? @relation(fields: [openaiSessionId], references: [id]) openaiSessionId String? + webhookUrl String? @db.VarChar(500) } model MessageUpdate { diff --git a/src/api/dto/sendMessage.dto.ts b/src/api/dto/sendMessage.dto.ts index 07ef804e..8d3ba1a0 100644 --- a/src/api/dto/sendMessage.dto.ts +++ b/src/api/dto/sendMessage.dto.ts @@ -13,6 +13,7 @@ export class Options { encoding?: boolean; mentionsEveryOne?: boolean; mentioned?: string[]; + webhookUrl?: string; } export class MediaMessage { @@ -137,6 +138,7 @@ export class SendTemplateDto extends Metadata { name: string; language: string; components: any; + webhookUrl?: string; } export class SendContactDto extends Metadata { contact: ContactMessage[]; diff --git a/src/api/services/channels/whatsapp.business.service.ts b/src/api/services/channels/whatsapp.business.service.ts index d835361b..341ca76d 100644 --- a/src/api/services/channels/whatsapp.business.service.ts +++ b/src/api/services/channels/whatsapp.business.service.ts @@ -548,6 +548,10 @@ export class BusinessStartupService extends ChannelStartupService { await this.prismaRepository.messageUpdate.create({ data: message, }); + + if (findMessage.webhookUrl) { + await axios.post(findMessage.webhookUrl, message); + } } } } @@ -636,6 +640,7 @@ export class BusinessStartupService extends ChannelStartupService { protected async sendMessageWithTyping(number: string, message: any, options?: Options, isIntegration = false) { try { let quoted: any; + let webhookUrl: any; const linkPreview = options?.linkPreview != false ? undefined : false; if (options?.quoted) { const m = options?.quoted; @@ -648,6 +653,9 @@ export class BusinessStartupService extends ChannelStartupService { quoted = msg; } + if (options?.webhookUrl) { + webhookUrl = options.webhookUrl; + } let content: any; const messageSent = await (async () => { @@ -826,6 +834,7 @@ export class BusinessStartupService extends ChannelStartupService { messageType: this.renderMessageType(content.type), messageTimestamp: (messageSent?.messages[0]?.timestamp as number) || Math.round(new Date().getTime() / 1000), instanceId: this.instanceId, + webhookUrl, source: 'unknown', }; @@ -1134,6 +1143,7 @@ export class BusinessStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + webhookUrl: data?.webhookUrl, }, isIntegration, ); diff --git a/src/validate/message.schema.ts b/src/validate/message.schema.ts index fee7bcfe..6705be5e 100644 --- a/src/validate/message.schema.ts +++ b/src/validate/message.schema.ts @@ -33,6 +33,7 @@ export const templateMessageSchema: JSONSchema7 = { name: { type: 'string' }, language: { type: 'string' }, components: { type: 'array' }, + webhookUrl: { type: 'string' }, }, required: ['name', 'language'], };