Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Ask cards: a line in the bot's own chat that its card could not take still goes out as usual

milind-soni403e89c8f25c
diff --git a/server/host/ask-cards.test.ts b/server/host/ask-cards.test.ts
index 716384ad31..e04bfb4577 100644
--- a/server/host/ask-cards.test.ts
+++ b/server/host/ask-cards.test.ts
@@ -469,6 +469,17 @@ describe("a typed line answers a question card", () => {
expect(await w.cards.typed(AUTH, "work", "Yes", undefined, {})).toEqual({ status: 403, error: "This question is Ben's to answer." });
expect(w.rows("work").filter((row) => row.role === "user")).toEqual([]);
});
+
+ it("leaves a line in the bot's own chat to the usual send when its card could not take it as the answer", async () => {
+ for (const refusal of [{ status: 403, error: "This question is Ben's to answer." }, { status: 409, error: "This card was already answered." }]) {
+ const w = world({ live: ["req-1"] });
+ const asked = question(w, "chat");
+ w.refuse(refusal);
+ expect(await w.cards.typed(AUTH, "chat", "What time is it?", undefined, { sendId: "send-9" })).toBeNull();
+ expect(w.deps.answerCard).toHaveBeenCalledWith(expect.objectContaining({ requestId: "req-1", behavior: "answer" }));
+ expect(w.rows("chat")).toEqual([asked]);
+ }
+ });
});
describe("a reminder of work parked on the person", () => {
diff --git a/server/host/ask-cards.ts b/server/host/ask-cards.ts
index e54355ee68..6c168ab4e4 100644
--- a/server/host/ask-cards.ts
+++ b/server/host/ask-cards.ts
@@ -405,7 +405,8 @@ export function createAskCards(deps: AskCardsDeps) {
const answered = await deps.answerCard({ auth, threadId, requestId, behavior: "answer", message: typedAnswer(asked.card, text) });
if (!answered.ok) {
spent.delete(key);
- return { status: answered.status, error: answered.error };
+ // In the bot's own chat the line was never meant only for the card: one that could not answer it is sent as usual.
+ return ownChat ? null : { status: answered.status, error: answered.error };
}
const posted = store.appendMessage(threadId, { role: "user", kind: "text", text, replyToId: asked.id,
...(line.sendId ? { sendId: line.sendId } : {}), ...(line.sender ? { sender: line.sender } : {}) });