Creating a Bot
Receive messages and send a reply
Minimal Loop
- Listen for
message.received. - Ignore your own bot messages.
- Reply using
POST /api/bot/v1/messages/sendand the inboundconversation_id.
import { io } from "socket.io-client";
const token = process.env.VXIL_BOT_TOKEN!;
const socket = io("wss://api.vxil.io", { auth: { token }, transports: ["websocket"] });
socket.on("message.received", async (event) => {
if (event.message.author.id === event.bot_id) return;
await fetch("https://api.vxil.io/api/bot/v1/messages/send", {
method: "POST",
headers: {
"Authorization": `Bot ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
conversation_id: event.message.conversation_id,
content: "pong",
}),
});
});Next: Send Message