Langage :
Authentification
Chaque bot dispose d'un token unique à inclure dans chaque requête.
⚠️ Sécurité
- Ne commitez jamais le token dans un dépôt public
- Stockez-le dans une variable d'environnement (
.env) - En cas de compromission, régénérez-le depuis le dashboard
Header d'authentification
http
Authorization: Bot VOTRE_TOKEN_ICIExemple d'authentification
Vérifier le token / authentifier le bot
js
const BOT_TOKEN = process.env.BOT_TOKEN;
const res = await fetch('https://gateway.alfychat.app/api/bots/authenticate', {
method: 'POST',
headers: {
'Authorization': `Bot ${BOT_TOKEN}`,
'Content-Type': 'application/json',
},
});
const data = await res.json();
console.log('Connecté :', data.bot.name);Réponse — POST /api/bots/authenticate
json
// 200 OK
{
"success": true,
"bot": {
"id": "a1b2c3d4-...",
"name": "MonBot",
"status": "offline",
"isVerified": false,
"prefix": "!",
"serverCount": 0
}
}
// 401 Unauthorized
{ "error": "Token de bot invalide" }Envoyer un message
POST /api/messages
js
async function sendMessage(channelId, content, options = {}) {
const res = await fetch('https://gateway.alfychat.app/api/messages', {
method: 'POST',
headers: {
'Authorization': `Bot ${process.env.BOT_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ channelId, content, ...options }),
});
return res.json();
}
// Envoi simple
await sendMessage('channel-id', 'Bonjour !');
// En réponse à un message
await sendMessage('channel-id', 'Je te réponds !', { replyToId: 'msg-id' });