A hook's calls used to run in whatever session was active at the time. Now `bot_hooks.session_id` pins them to one session, open or closed (null still follows the active one). The hook form picks where it runs (the bot's own chat or one of its workspaces) and a session there, or a new one of its own started beside the active one so the chat on screen stays. A bot's proposed hook gets the session it was proposed in, and a missing session is replaced on the next call. Changing place or session is refused while a run is open; the computer stays only if reachable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
30 lines
884 B
TypeScript
30 lines
884 B
TypeScript
import { AppData } from "@/src/data/app-data";
|
|
import createBotSession from "../bot-sessions/create-bot-session";
|
|
|
|
type Params = {
|
|
user_id: number | string;
|
|
bot_id: number | string;
|
|
workspace_id?: number | string | null;
|
|
/**
|
|
* The hook's title, which names the session.
|
|
*/
|
|
title: string;
|
|
};
|
|
|
|
/**
|
|
* Starts a hook's own session in the conversation, beside the active one
|
|
* (closed, so the chat on screen stays as it is). It shows in the
|
|
* conversation's sessions once something lands in it. Returns its id.
|
|
*/
|
|
export default async function startHookSession({ user_id, bot_id, workspace_id, title }: Params) {
|
|
const session = await createBotSession({
|
|
user_id,
|
|
bot_id,
|
|
workspace_id,
|
|
status: "closed",
|
|
title: `Hook: ${title}`.slice(0, AppData.BotSessionTitleMaxChars),
|
|
});
|
|
|
|
return Number(session.id);
|
|
}
|