From 999f59c3f0df8dc2b0cffac2b530f8a2ce5ba687 Mon Sep 17 00:00:00 2001 From: Steve Dempsey Date: Sun, 15 Nov 2026 08:16:52 -0500 Subject: [PATCH] Ask for a Telegram reply box only in a group chat Tapping the typed-answer button sent a force_reply prompt in every chat, so in a direct chat each typed answer arrived threaded under 'Reply to message'. A direct chat never needs it: the armed map alone matches the next text. A group still does, because an unaddressed message is dropped before the armed check and a reply to the bot counts as addressed. --- ds-bot/src/host/im/index.js | 5 ++++- ds-bot/test/im.test.js | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ds-bot/src/host/im/index.js b/ds-bot/src/host/im/index.js index 09a4422167..44555d7d0f 100644 --- a/ds-bot/src/host/im/index.js +++ b/ds-bot/src/host/im/index.js @@ -521,7 +521,10 @@ export function install(rt) { return } armed.set(armKey(conn, chat.key), cardKey) - enqueue(conn, chat.key, { chat: { key: chat.key, kind: chat.kind, title: chat.title }, text: text('typePrompt'), forceReply: true }) + // Only a group needs the reply box: there an unaddressed message is dropped + // before the armed check, and a reply to the bot counts as addressed. In a + // direct chat the armed map alone matches the answer, so the box is noise. + enqueue(conn, chat.key, { chat: { key: chat.key, kind: chat.kind, title: chat.title }, text: text('typePrompt'), forceReply: chat.kind === 'group' }) } // The typed answer for the card this chat armed. False when that card is no // longer open, so the text goes on as an ordinary message. diff --git a/ds-bot/test/im.test.js b/ds-bot/test/im.test.js index feb91763c8..032c0b9551 100644 --- a/ds-bot/test/im.test.js +++ b/ds-bot/test/im.test.js @@ -708,7 +708,8 @@ test('the typed-answer button arms a reply prompt and the next text answers that await press(s, 't:q:q1') await s.flush() const prompt = s.fake.sent.at(-1) - assert.equal(prompt.forceReply, true, 'the prompt asks Telegram for a reply box') + assert.equal(prompt.text, 'Type your answer and send it.') + assert.equal(prompt.forceReply, false, 'a direct chat gets no reply box: the arm alone matches the answer') assert.equal(prompt.buttons, undefined, 'a reply prompt carries no inline keyboard') assert.ok(s.rt.state.questions.a !== undefined, 'arming answers nothing yet') s.prompts.length = 0 @@ -724,6 +725,25 @@ test('the typed-answer button arms a reply prompt and the next text answers that assert.equal(s.prompts.length, 1, 'the arm is spent: the next text is an ordinary message') }) +test('in a group the typed-answer prompt keeps the reply box, and the reply answers the card', async (t) => { + const s = await start() + t.after(s.stop) + const conn = await pairedChat(s) + await gm(s, 'u1', '@fakebot hello') + await s.rt.imEndpoint('im-chat', { id: conn.id, chatKey: 'g1', target: { botId: 'a' } }) + s.fake.sent.length = 0 + await askQuestion(s) + assert.ok(s.fake.sent.some(entry => entry.chat?.key === 'g1' && entry.buttons !== undefined), 'the card reaches the group') + const got = followups(s) + await s.fake.handlers.onAction({ chat: { key: 'g1', kind: 'group', title: 'Group One' }, sender: { id: 'u1', name: 'U1' }, data: 't:q:q1', messageId: 1 }) + await s.flush() + const prompt = s.fake.sent.at(-1) + assert.equal(prompt.chat.key, 'g1') + assert.equal(prompt.forceReply, true, 'a group needs the reply box, or the unaddressed answer is dropped') + await gm(s, 'u1', 'Ship to Acme only') + assert.deepEqual(answerOf(got[0]), { id: 'q1', selected: [], custom: 'Ship to Acme only' }) +}) + test('ordinary chat text with no armed card is untouched', async (t) => { const s = await start() t.after(s.stop) @@ -773,7 +793,7 @@ test('a second arm replaces the first, and a typed view answer reaches the Bot', await press(s, 't:v:v1') await press(s, 't:v:v1') await s.flush() - assert.equal(s.fake.sent.filter(entry => entry.forceReply === true).length, 2) + assert.equal(s.fake.sent.filter(entry => entry.text === 'Type your answer and send it.').length, 2) s.prompts.length = 0 await dm(s, 'u1', 'neither, ask me tomorrow') assert.equal(s.prompts.length, 1, 'the typed text goes to the Bot once')