mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 04:02:54 -06:00
chore: Add webhookUrl to Message model, DTOs, and services
Adds webhookUrl field to Message model, SendMessageDto, SendTemplateDto, SendContactDto, and related services to enable sending messages to a specified webhook URL. This change allows for more flexible message handling and delivery options. Modified files: - prisma/postgresql-schema.prisma - src/api/dto/sendMessage.dto.ts - src/api/services/channels/whatsapp.business.service.ts - src/validate/message.schema.ts Untracked files: - prisma/migrations/20240723200254_add_webhookurl_on_message/
This commit is contained in:
parent
50591e9ed6
commit
4746d3991e
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Message" ADD COLUMN "webhookUrl" VARCHAR(500);
|
@ -135,6 +135,7 @@ model Message {
|
|||||||
Media Media?
|
Media Media?
|
||||||
OpenaiSession OpenaiSession? @relation(fields: [openaiSessionId], references: [id])
|
OpenaiSession OpenaiSession? @relation(fields: [openaiSessionId], references: [id])
|
||||||
openaiSessionId String?
|
openaiSessionId String?
|
||||||
|
webhookUrl String? @db.VarChar(500)
|
||||||
}
|
}
|
||||||
|
|
||||||
model MessageUpdate {
|
model MessageUpdate {
|
||||||
|
@ -13,6 +13,7 @@ export class Options {
|
|||||||
encoding?: boolean;
|
encoding?: boolean;
|
||||||
mentionsEveryOne?: boolean;
|
mentionsEveryOne?: boolean;
|
||||||
mentioned?: string[];
|
mentioned?: string[];
|
||||||
|
webhookUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MediaMessage {
|
export class MediaMessage {
|
||||||
@ -137,6 +138,7 @@ export class SendTemplateDto extends Metadata {
|
|||||||
name: string;
|
name: string;
|
||||||
language: string;
|
language: string;
|
||||||
components: any;
|
components: any;
|
||||||
|
webhookUrl?: string;
|
||||||
}
|
}
|
||||||
export class SendContactDto extends Metadata {
|
export class SendContactDto extends Metadata {
|
||||||
contact: ContactMessage[];
|
contact: ContactMessage[];
|
||||||
|
@ -548,6 +548,10 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
await this.prismaRepository.messageUpdate.create({
|
await this.prismaRepository.messageUpdate.create({
|
||||||
data: message,
|
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) {
|
protected async sendMessageWithTyping(number: string, message: any, options?: Options, isIntegration = false) {
|
||||||
try {
|
try {
|
||||||
let quoted: any;
|
let quoted: any;
|
||||||
|
let webhookUrl: any;
|
||||||
const linkPreview = options?.linkPreview != false ? undefined : false;
|
const linkPreview = options?.linkPreview != false ? undefined : false;
|
||||||
if (options?.quoted) {
|
if (options?.quoted) {
|
||||||
const m = options?.quoted;
|
const m = options?.quoted;
|
||||||
@ -648,6 +653,9 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
quoted = msg;
|
quoted = msg;
|
||||||
}
|
}
|
||||||
|
if (options?.webhookUrl) {
|
||||||
|
webhookUrl = options.webhookUrl;
|
||||||
|
}
|
||||||
|
|
||||||
let content: any;
|
let content: any;
|
||||||
const messageSent = await (async () => {
|
const messageSent = await (async () => {
|
||||||
@ -826,6 +834,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
messageType: this.renderMessageType(content.type),
|
messageType: this.renderMessageType(content.type),
|
||||||
messageTimestamp: (messageSent?.messages[0]?.timestamp as number) || Math.round(new Date().getTime() / 1000),
|
messageTimestamp: (messageSent?.messages[0]?.timestamp as number) || Math.round(new Date().getTime() / 1000),
|
||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
|
webhookUrl,
|
||||||
source: 'unknown',
|
source: 'unknown',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1134,6 +1143,7 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
linkPreview: data?.linkPreview,
|
linkPreview: data?.linkPreview,
|
||||||
mentionsEveryOne: data?.mentionsEveryOne,
|
mentionsEveryOne: data?.mentionsEveryOne,
|
||||||
mentioned: data?.mentioned,
|
mentioned: data?.mentioned,
|
||||||
|
webhookUrl: data?.webhookUrl,
|
||||||
},
|
},
|
||||||
isIntegration,
|
isIntegration,
|
||||||
);
|
);
|
||||||
|
@ -33,6 +33,7 @@ export const templateMessageSchema: JSONSchema7 = {
|
|||||||
name: { type: 'string' },
|
name: { type: 'string' },
|
||||||
language: { type: 'string' },
|
language: { type: 'string' },
|
||||||
components: { type: 'array' },
|
components: { type: 'array' },
|
||||||
|
webhookUrl: { type: 'string' },
|
||||||
},
|
},
|
||||||
required: ['name', 'language'],
|
required: ['name', 'language'],
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user