Beispiel-Bot
Einfacher Gateway-Bot: antwortet auf „Hallo“ mit „Wie geht's?“
Repository-Pfad
Code
examples/voxery-simple-bot/Node.js (ESM), Abhängigkeiten: socket.io-client
Installation
Code
cd examples/voxery-simple-bot
npm install
cp .env.example .env
# fill in .env
npm startUmgebungsvariablen
.env
VOXERY_API_URL=https://api.voxery.xyz
VOXERY_BOT_TOKEN=voxery.bot.xxx
# Or legacy JWT login:
# VOXERY_BOT_EMAIL=bot@example.com
# VOXERY_BOT_PASSWORD=your-password
# Optional — otherwise first server / first text channel:
# VOXERY_SERVER_ID=clx...
# VOXERY_CHANNEL_ID=clx...Ablauf im Code
- Login → JWT oder Bot-Token
- Server & Text-Kanal auflösen
- Socket.IO verbinden
- join_server + join_channel
- Event-Handler für Nachrichten
Kern-Logik
index.mjs (excerpt)
socket.on("message_create", (msg) => {
if (!msg?.author?.id || msg.author.id === botUserId) return;
if (msg.channelId !== channelId) return;
const text = (msg.content ?? "").trim().toLowerCase();
if (text === "hallo" || text === "hello" || text === "hi") {
socket.emit("send_message", {
channelId,
content: "How are you?",
});
}
});Testen
- Bot starten (npm start)
- In der App den Kanal öffnen, in dem der Bot lauscht
- „Hallo“ schreiben → Bot antwortet „Wie geht's?“
Webhook-Alternative
Webhooks können nur senden, nicht auf „Hallo“ reagieren. Für Keyword-Antworten brauchst du einen Gateway-Bot wie diesen.