Skip to content

Commit 373a531

Browse files
committed
fix: update logging and message handling in EvoaiService
This commit modifies the logging messages in the `EvoaiService` to use the correct service name "EvoAI" instead of "Dify" for better clarity. Additionally, it refines the message handling logic by changing the way message IDs are generated and updating the payload structure sent to the API. The extraction of the message from the response artifacts has also been improved to ensure that the correct message is retrieved from the response data. Changes include: - Updated logging statements to reflect the correct service name. - Changed the message ID generation to use a shorter UUID substring. - Adjusted the payload structure to include `contextId` and `messageId`. - Enhanced message extraction logic from the response artifacts. These changes enhance the clarity of logs and improve the robustness of message handling in the service.
1 parent e081533 commit 373a531

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
5050
// Check if this is an audio message that we should try to transcribe
5151
if (this.isAudioMessage(content) && msg) {
5252
try {
53-
this.logger.debug(`[Dify] Downloading audio for Whisper transcription`);
53+
this.logger.debug(`[EvoAI] Downloading audio for Whisper transcription`);
5454
const transcription = await this.openaiService.speechToText(msg);
5555
if (transcription) {
5656
contentProcessed = transcription;
5757
} else {
5858
contentProcessed = '[Audio message could not be transcribed]';
5959
}
6060
} catch (err) {
61-
this.logger.error(`[Dify] Failed to transcribe audio: ${err}`);
61+
this.logger.error(`[EvoAI] Failed to transcribe audio: ${err}`);
6262
contentProcessed = '[Audio message could not be transcribed]';
6363
}
6464
}
@@ -85,8 +85,8 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
8585
this.logger.debug(`[EvoAI] Sending message to bot with content: ${content}`);
8686

8787
const endpoint: string = evoai.agentUrl;
88-
const callId = `call-${uuidv4()}`;
89-
const taskId = `task-${uuidv4()}`;
88+
const callId = `req-${uuidv4().substring(0, 8)}`;
89+
const messageId = uuidv4();
9090

9191
// Prepare message parts
9292
const parts = [
@@ -111,8 +111,8 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
111111
type: 'file',
112112
file: {
113113
name: fileName,
114-
bytes: fileContent,
115114
mimeType: 'image/jpeg',
115+
bytes: fileContent,
116116
},
117117
} as any);
118118
} catch (fileErr) {
@@ -122,16 +122,16 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
122122

123123
const payload = {
124124
jsonrpc: '2.0',
125-
method: 'tasks/send',
125+
id: callId,
126+
method: 'message/send',
126127
params: {
128+
contextId: session.sessionId,
127129
message: {
128130
role: 'user',
129131
parts,
132+
messageId: messageId,
130133
},
131-
sessionId: session.sessionId,
132-
id: taskId,
133134
},
134-
id: callId,
135135
};
136136

137137
this.logger.debug(`[EvoAI] Sending request to: ${endpoint}`);
@@ -159,17 +159,23 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
159159
},
160160
});
161161

162-
this.logger.debug(`[EvoAI] Response: ${JSON.stringify(response.data.status)}`);
162+
this.logger.debug(`[EvoAI] Response: ${JSON.stringify(response.data)}`);
163163

164164
if (instance.integration === Integration.WHATSAPP_BAILEYS)
165165
await instance.client.sendPresenceUpdate('paused', remoteJid);
166166

167167
let message = undefined;
168168
const result = response?.data?.result;
169-
if (result?.status?.message?.parts && Array.isArray(result.status.message.parts)) {
170-
const textPart = result.status.message.parts.find((p) => p.type === 'text' && p.text);
171-
if (textPart) message = textPart.text;
169+
170+
// Extract message from artifacts array
171+
if (result?.artifacts && Array.isArray(result.artifacts) && result.artifacts.length > 0) {
172+
const artifact = result.artifacts[0];
173+
if (artifact?.parts && Array.isArray(artifact.parts)) {
174+
const textPart = artifact.parts.find((p) => p.type === 'text' && p.text);
175+
if (textPart) message = textPart.text;
176+
}
172177
}
178+
173179
this.logger.debug(`[EvoAI] Extracted message to send: ${message}`);
174180
const conversationId = session.sessionId;
175181

0 commit comments

Comments
 (0)