bodegAI/commands/recipes_command.js

41 lines
1.4 KiB
JavaScript

const recipesService = require('../services/recipes_service');
const recipeUtils = require('../utils/recipe_utils');
/**
* Maneja el comando de recetas.
* @param {Object} client - Instancia del cliente de WhatsApp.
* @param {Object} message - Mensaje recibido.
*/
const handleRecipeCommand = async (client, message) => {
const parts = message.body.trim().split(' ');
const subCommand = parts[0].toLowerCase();
const query = parts.slice(1).join(' ');
try {
let recipe;
if (subCommand === '!receta') {
if (query) {
// Buscar receta por nombre
recipe = await recipesService.searchMealByName(query);
} else {
// Obtener receta aleatoria
recipe = await recipesService.getRandomMeal();
}
const recipeInfo = recipeUtils.formatRecipeInfo(recipe);
await client.sendMessage(message.from, recipeInfo);
console.log(`📤 Información de la receta enviada a ${message.from}`);
} else {
// Manejar otros subcomandos si es necesario
await client.sendMessage(message.from, '❌ Comando no reconocido.');
}
} catch (error) {
console.error('❌ Error al manejar el comando de recetas:', error);
await client.sendMessage(message.from, `❌ Error al obtener la receta: ${error.message}`);
}
};
module.exports = {
handleRecipeCommand
};