mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-20 12:22:21 -06:00
feat(env): enhance webhook configuration and SSL support
- Added new environment variables for SSL configuration, including `SSL_CONF_PRIVKEY` and `SSL_CONF_FULLCHAIN`, to support secure connections. - Introduced additional webhook configuration options in the `.env.example` file, such as `WEBHOOK_REQUEST_TIMEOUT_MS`, `WEBHOOK_RETRY_MAX_ATTEMPTS`, and related retry settings to improve webhook resilience and error handling. - Updated the `bootstrap` function in `main.ts` to handle SSL certificate loading failures gracefully, falling back to HTTP if necessary. - Enhanced error handling and logging in the `BusinessStartupService` to ensure better traceability and robustness when processing messages. This commit focuses on improving the security and reliability of webhook interactions while ensuring that the application can handle SSL configurations effectively.
This commit is contained in:
@@ -223,7 +223,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
||||
): Promise<void> {
|
||||
if (!message) return;
|
||||
|
||||
const linkRegex = /(!?)\[(.*?)\]\((.*?)\)/g;
|
||||
const linkRegex = /!?\[(.*?)\]\((.*?)\)/g;
|
||||
let textBuffer = '';
|
||||
let lastIndex = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
@@ -231,7 +231,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
||||
const splitMessages = (settings as any)?.splitMessages ?? false;
|
||||
|
||||
while ((match = linkRegex.exec(message)) !== null) {
|
||||
const [, , altText, url] = match;
|
||||
const [fullMatch, altText, url] = match;
|
||||
const mediaType = this.getMediaType(url);
|
||||
const beforeText = message.slice(lastIndex, match.index);
|
||||
|
||||
@@ -276,7 +276,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
||||
}
|
||||
} else {
|
||||
// It's a regular link, keep it in the text
|
||||
textBuffer += `[${altText}](${url})`;
|
||||
textBuffer += fullMatch;
|
||||
}
|
||||
|
||||
lastIndex = linkRegex.lastIndex;
|
||||
|
||||
@@ -180,10 +180,10 @@ class ChatwootImport {
|
||||
const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`); // Make sure the sourceId is always formatted as WAID:1234567890
|
||||
let query: string;
|
||||
if (conversationId) {
|
||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
|
||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
|
||||
}
|
||||
|
||||
if(!conversationId) {
|
||||
if (!conversationId) {
|
||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2';
|
||||
}
|
||||
|
||||
@@ -508,9 +508,7 @@ class ChatwootImport {
|
||||
templateMessage: msg.message.templateMessage?.hydratedTemplate?.hydratedContentText,
|
||||
};
|
||||
|
||||
const typeKey = Object.keys(types).find(
|
||||
(key) => types[key] !== undefined && types[key] !== null
|
||||
);
|
||||
const typeKey = Object.keys(types).find((key) => types[key] !== undefined && types[key] !== null);
|
||||
switch (typeKey) {
|
||||
case 'documentMessage': {
|
||||
const doc = msg.message.documentMessage;
|
||||
@@ -526,10 +524,13 @@ class ChatwootImport {
|
||||
return `_<File: ${fileName}${caption}>_`;
|
||||
}
|
||||
|
||||
case 'templateMessage':
|
||||
case 'templateMessage': {
|
||||
const template = msg.message.templateMessage?.hydratedTemplate;
|
||||
return (template?.hydratedTitleText ? `*${template.hydratedTitleText}*\n` : '') +
|
||||
(template?.hydratedContentText || '');
|
||||
return (
|
||||
(template?.hydratedTitleText ? `*${template.hydratedTitleText}*\n` : '') +
|
||||
(template?.hydratedContentText || '')
|
||||
);
|
||||
}
|
||||
|
||||
case 'imageMessage':
|
||||
return '_<Image Message>_';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { $Enums, TriggerOperator, TriggerType } from '@prisma/client';
|
||||
import { $Enums } from '@prisma/client';
|
||||
|
||||
import { BaseChatbotDto, BaseChatbotSettingDto } from '../../base-chatbot.dto';
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { TriggerOperator, TriggerType } from '@prisma/client';
|
||||
|
||||
import { BaseChatbotDto, BaseChatbotSettingDto } from '../../base-chatbot.dto';
|
||||
|
||||
export class EvoaiDto extends BaseChatbotDto {
|
||||
|
||||
@@ -86,7 +86,14 @@ export class EvolutionBotService extends BaseChatbotService<EvolutionBot, Evolut
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
}
|
||||
|
||||
const message = response?.data?.message;
|
||||
let message = response?.data?.message;
|
||||
|
||||
if (message && typeof message === 'string' && message.startsWith("'") && message.endsWith("'")) {
|
||||
const innerContent = message.slice(1, -1);
|
||||
if (!innerContent.includes("'")) {
|
||||
message = innerContent;
|
||||
}
|
||||
}
|
||||
|
||||
if (message) {
|
||||
// Use the base class method to send the message to WhatsApp
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { TriggerOperator, TriggerType } from '@prisma/client';
|
||||
|
||||
import { BaseChatbotDto, BaseChatbotSettingDto } from '../../base-chatbot.dto';
|
||||
|
||||
export class OpenaiCredsDto {
|
||||
|
||||
Reference in New Issue
Block a user