mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-17 12:42:54 -06:00
Merge pull request #1192 from tonimoreiraa/fix-dify-truncated-messages
fix(dify-service): Truncated messages (agent bot)
This commit is contained in:
commit
9109b140a9
@ -224,23 +224,13 @@ export class DifyService {
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${dify.apiKey}`,
|
Authorization: `Bearer ${dify.apiKey}`,
|
||||||
},
|
},
|
||||||
responseType: 'stream',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let conversationId;
|
let conversationId;
|
||||||
let answer = '';
|
let answer = '';
|
||||||
|
|
||||||
const stream = response.data;
|
const data = response.data.replaceAll('data: ', '');
|
||||||
const reader = new Readable().wrap(stream);
|
|
||||||
|
|
||||||
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() !== '');
|
const events = data.split('\n').filter((line) => line.trim() !== '');
|
||||||
|
|
||||||
for (const eventString of events) {
|
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)
|
if (instance.integration === Integration.WHATSAPP_BAILEYS)
|
||||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||||
|
|
||||||
@ -277,11 +262,6 @@ export class DifyService {
|
|||||||
sessionId: conversationId,
|
sessionId: conversationId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
reader.on('error', (error) => {
|
|
||||||
console.error('Error reading stream:', error);
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user