Spaces:
Paused
Paused
File size: 1,468 Bytes
58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 55a239d 58301c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | const { Groq } = require("groq-sdk");
const { Telegraf } = require("telegraf");
const express = require("express");
const app = express();
// O sistema lê as chaves que você salvou nas 'Secrets' do Hugging Face
const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });
const bot = new Telegraf(process.env.TELEGRAM_TOKEN);
// Rota para o Cron-job.org não deixar o bot dormir
app.get("/", (req, res) => {
res.send("🚀 ERINALDO.DEV Telegram Bot está Online e Imortal!");
});
// Mensagem de boas-vindas no Telegram
bot.start((ctx) => ctx.reply("Salve Erinaldo! O sistema ERINALDO.DEV está ativo no Telegram. Pode mandar sua dúvida!"));
// O robô ouvindo você no Telegram
bot.on("text", async (ctx) => {
try {
// Mostra que o robô está 'digitando'
await ctx.sendChatAction('typing');
const chatCompletion = await groq.chat.completions.create({
messages: [{ role: "user", content: ctx.message.text }],
model: "llama-3.3-70b-versatile",
});
const resposta = chatCompletion.choices[0].message.content;
await ctx.reply(resposta);
} catch (error) {
console.error("Erro no Bot:", error);
await ctx.reply("⚠️ Erro ao processar a inteligência. Verifique a chave GROQ_API_KEY nas Settings.");
}
});
// Inicia o Bot e o Servidor na porta do Hugging Face
bot.launch();
const PORT = process.env.PORT || 7860;
app.listen(PORT, () => {
console.log(`✅ Bot rodando com sucesso na porta ${PORT}`);
});
|