Spaces:
Paused
Paused
Download index.js from Erinaldordso/Bot: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/Erinaldordso/Bot/resolve/main/index.js
- Command line
-
hf download hf://spaces/Erinaldordso/Bot/index.js
-
curl -L -o index.js https://huggingface.co/spaces/Erinaldordso/Bot/resolve/main/index.js
1.47 kB
| 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}`); | |
| }); | |