fix: Update audio download method for WhatsApp messages
This commit modifies the audio download process in `whatsapp-router/src/webhook.ts` to align with the updated nucleo-whatsapp API. Previously, audio files were downloaded using a direct GET request to the file URL. This has been changed to a POST request to the `/downloadFileWithCredentials` endpoint provided by nucleo-whatsapp. Key changes: - Audio files are now downloaded by POSTing to `[OPEN_WA_URL]/downloadFileWithCredentials` with the audio file's URL in the request body. - The `/downloadFileWithCredentials` endpoint returns a base64 encoded string directly, so the explicit base64 conversion step after downloading has been removed. This change ensures compatibility with the correct API for fetching message media.
This commit is contained in:
@@ -45,7 +45,7 @@ console.log(`Using Gemini API key: ${API_KEY}`);
|
|||||||
|
|
||||||
const genAI = API_KEY ? new GoogleGenAI({ apiKey: API_KEY }) : null;
|
const genAI = API_KEY ? new GoogleGenAI({ apiKey: API_KEY }) : null;
|
||||||
|
|
||||||
const MCP_URL = process.env.MCP_URL || 'http://localhost:5000/mcp';
|
const MCP_URL = process.env.MCP_URL || 'http://planilla.interno.com/mcp';
|
||||||
let mcpClient: Client | undefined;
|
let mcpClient: Client | undefined;
|
||||||
let mcpTransport: StreamableHTTPClientTransport | undefined;
|
let mcpTransport: StreamableHTTPClientTransport | undefined;
|
||||||
|
|
||||||
|
|||||||
3643
whatsapp-router/package-lock.json
generated
3643
whatsapp-router/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ dotenv.config();
|
|||||||
export type Handler = string | ((conv: Conversation) => Promise<string>);
|
export type Handler = string | ((conv: Conversation) => Promise<string>);
|
||||||
|
|
||||||
export const chatHandlers: Record<string, Handler> = {
|
export const chatHandlers: Record<string, Handler> = {
|
||||||
'50498554225@c.us': process.env.CONVERSATION_AGENT_URL || 'http://localhost:8001',
|
'50498554225@c.us': process.env.CONVERSATION_AGENT_URL || 'http://conversation-layer-agent:8001',
|
||||||
// Add other mappings like:
|
// Add other mappings like:
|
||||||
// '50496210031@c.us': 'http://llm-agent:8000'
|
// '50496210031@c.us': 'http://llm-agent:8000'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ export function registerWebhookRoutes(
|
|||||||
}
|
}
|
||||||
console.log('🎤 Mensaje de audio detectado', audioUrl);
|
console.log('🎤 Mensaje de audio detectado', audioUrl);
|
||||||
try {
|
try {
|
||||||
const audioResponse = await axios.get(audioUrl, {
|
// Download audio using the /downloadFileWithCredentials endpoint
|
||||||
responseType: 'arraybuffer',
|
const audioResponse = await axios.post(`${openWaUrl}/downloadFileWithCredentials`, {
|
||||||
|
args: { url: audioUrl },
|
||||||
});
|
});
|
||||||
const audioBase64 = Buffer.from(audioResponse.data).toString('base64');
|
const audioBase64 = audioResponse.data; // This is already a base64 string
|
||||||
|
|
||||||
const apiKey = process.env.GOOGLE_API_KEY;
|
const apiKey = process.env.GOOGLE_API_KEY;
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
@@ -66,7 +67,7 @@ export function registerWebhookRoutes(
|
|||||||
|
|
||||||
// Corrected Gemini API call structure
|
// Corrected Gemini API call structure
|
||||||
const result = await genAI.models.generateContent({
|
const result = await genAI.models.generateContent({
|
||||||
model: 'gemini-2.0-flash', // Ensure this model supports inline audio or use appropriate one
|
model: 'gemini-pro', // Ensure this model supports inline audio or use appropriate one
|
||||||
contents: [
|
contents: [
|
||||||
{ inlineData: { mimeType: 'audio/ogg', data: audioBase64 } },
|
{ inlineData: { mimeType: 'audio/ogg', data: audioBase64 } },
|
||||||
{ text: 'Generate a transcript of the speech.' },
|
{ text: 'Generate a transcript of the speech.' },
|
||||||
|
|||||||
Reference in New Issue
Block a user