// bot.js
import { Bot, defineBot, isMainModule } from '@botmesh/core'
import { BaileysProvider } from '@botmesh/baileys'
const createBot = defineBot((provider) => {
const bot = new Bot({ provider, lang: 'es' })
// Una palabra clave, o cualquiera de una lista (mensaje completo, sin importar mayúsculas ni tildes)
bot.when('hola', (ctx) => ctx.reply('👋 ¡Hola!'))
bot.when(['adios', 'chao', 'hasta luego'], (ctx) => ctx.reply('👋 ¡Hasta luego!'))
// La palabra en cualquier parte del mensaje
bot.when({ pattern: 'factura', match: 'contains' }, (ctx) => ctx.reply('🧾 Veo que mencionaste una factura'))
// Expresiones regulares
bot.when(/[\w.]+@[\w.]+\.\w+/, (ctx) => ctx.reply('📧 Eso parece un email'))
bot.when(/\d{4,}/, (ctx) => ctx.reply(`🔢 Detecté un número largo en "${ctx.body}"`))
// Citar el mensaje del usuario, o reaccionar a él
bot.when('citar', (ctx) => ctx.quote('Respondo a tu mensaje exacto'))
bot.when('buen bot', (ctx) => ctx.react('👍'))
// Quién escribió y dónde
bot.when('quien soy', (ctx) =>
ctx.reply(`Eres ${ctx.senderInfo.displayName ?? 'alguien'} (${ctx.sender}) en un ${ctx.isGroup ? 'grupo' : 'chat privado'}.`),
)
// Texto de varias líneas con formato estilo WhatsApp
bot.when('info', (ctx) => ctx.reply(['ℹ️ *Info del bot*', '', '• Motor: botmesh', '• Funciona en: WhatsApp, Telegram'].join('\n')))
bot.onMessage((ctx) => ctx.reply('🤔 No reconocí eso. Prueba: hola, citar, quien soy, info.'))
return bot
})
export default createBot
// `node bot.js` conecta con WhatsApp; `npx botmesh dev bot.js` se salta este bloque
if (isMainModule(import.meta)) {
const bot = await createBot(new BaileysProvider({ session: 'messages-bot' }))
bot.on('ready', () => console.log('✅ Conectado. Escribe "hola" desde otro teléfono.'))
await bot.start()
}