INNER CODE UNIT · TypeScript
askBackend
Beever-AI/beever-atlas · bot/src/index.ts:558
async function askBackend(
channelId: string,
question: string,
sessionId: string,
userId: string,
attachments?: ImageAttachment[],
): Promise<AskResult> {
// Encode the channel id so a value with slashes/`..` can't escape the route
// path and reach an unintended backend endpoint.
const url = `${BACKEND_URL}/api/channels/${encodeURIComponent(channelId)}/ask`;
const headers: Record<string, string> = { "Content-Type": "application/json" };
const apiKey = backendApiKey();
if (apiKey) {
headers["Authorization"] = `Bearer ${apiKey}`;
}
// Include `attachments` ONLY when non-empty so the text-only body stays
// byte-identical to before — existing SSE tests assert on the exact body.
const payload: Record<string, unknown> = { question, session_id: sessionId, user_id: userId };