Documentation
Un point d’entrée, deux langages — du REST pour lire et modifier, du Socket.IO pour agir en direct. Ce que fait l’application officielle, votre code peut le faire.
import { io } from 'socket.io-client';
const API = 'https://gateway.alfychat.app';
// 1. Connexion → jetons
const { tokens } = await fetch(`${API}/api/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: 'moi@exemple.fr', password: '…' }),
}).then((r) => r.json());
// 2. Une requête authentifiée : tout l'état initial
const state = await fetch(`${API}/api/bootstrap/me`, {
headers: { Authorization: `Bearer ${tokens.accessToken}` },
}).then((r) => r.json());
// 3. Le temps réel
const socket = io(API, { auth: { token: tokens.accessToken } });
socket.on('message:new', (msg) => console.log(msg.content));