mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
fix: dify truncated messages
This commit is contained in:
parent
db9cdbfc38
commit
fc84e0f327
@ -224,23 +224,13 @@ export class DifyService {
|
||||
headers: {
|
||||
Authorization: `Bearer ${dify.apiKey}`,
|
||||
},
|
||||
responseType: 'stream',
|
||||
});
|
||||
|
||||
let conversationId;
|
||||
let answer = '';
|
||||
|
||||
const stream = response.data;
|
||||
const reader = new Readable().wrap(stream);
|
||||
const data = response.data.replaceAll('data: ', '');
|
||||
|
||||
reader.on('data', (chunk) => {
|
||||
const data = chunk.toString().replace(/data:\s*/g, '');
|
||||
|
||||
if (data.trim() === '' || !data.startsWith('{')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const events = data.split('\n').filter((line) => line.trim() !== '');
|
||||
|
||||
for (const eventString of events) {
|
||||
@ -254,12 +244,7 @@ export class DifyService {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing stream data:', error);
|
||||
}
|
||||
});
|
||||
|
||||
reader.on('end', async () => {
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS)
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
|
||||
@ -277,11 +262,6 @@ export class DifyService {
|
||||
sessionId: conversationId,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
reader.on('error', (error) => {
|
||||
console.error('Error reading stream:', error);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user