ask_user puts up to six questions on one card (radios for one pick, checkboxes for several, an optional typed Other) as a [question:ID] chip. The user's answers are checked against the questions, stored in bot_questions and sent to the bot as their chat message; Skip says so. Offered in chat replies and user-started tasks, never in routines, hook calls or chatroom sessions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
27 lines
860 B
TypeScript
27 lines
860 B
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import AppError from "@/src/utils/app-error";
|
|
import grabBotQuestion from "./grab-bot-question";
|
|
|
|
type Params = {
|
|
question_id: number | string;
|
|
user_id: number | string;
|
|
};
|
|
|
|
/**
|
|
* The user skipped questions a bot asked: nothing is answered.
|
|
*/
|
|
export default async function skipBotQuestion({ question_id, user_id }: Params) {
|
|
const row = await grabBotQuestion({ question_id, user_id });
|
|
const now = Date.now();
|
|
|
|
const claimed = await BunSQLite.sql<{ id: number }>({
|
|
sql: `UPDATE bot_questions SET status = 'skipped', decided_at = ?, updated_at = ?
|
|
WHERE id = ? AND status = 'pending' RETURNING id`,
|
|
values: [now, now, Number(row.id)],
|
|
});
|
|
|
|
if (!claimed.payload?.[0]) throw new AppError(`These questions were already ${row.status}.`);
|
|
|
|
return row;
|
|
}
|