Skip to content

Commit 4b48aab

Browse files
committed
feat: Show "View another" only after attachment delivery for better UX
1 parent f60f3ba commit 4b48aab

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

src/bot/composers/lookups/academic-calendar/composer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,14 @@ async function handleCalendarAttachment(
124124
],
125125
statusMessageId: statusMessage.message_id,
126126
context: "calendar",
127+
sendViewAnotherMessage: true,
127128
};
128129

129130
if (ctx.msgId !== undefined) {
130131
jobData.replyToMessageId = ctx.msgId;
131132
}
132133

133134
await addAttachmentDeliveryJob(jobData);
134-
135-
await ctx.reply(`${emoji("eyes")} View another calendar?`, {
136-
reply_markup: keyboard,
137-
});
138135
}
139136

140137
async function fetchAndDisplayCalendars(ctx: BotContext): Promise<void> {

src/bot/composers/lookups/announcements/composer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,14 @@ async function handleAnnouncementAttachments(
122122
attachments,
123123
statusMessageId: statusMessage.message_id,
124124
context: "announcement",
125+
sendViewAnotherMessage: true,
125126
};
126127

127128
if (ctx.msgId !== undefined) {
128129
jobData.replyToMessageId = ctx.msgId;
129130
}
130131

131132
await addAttachmentDeliveryJob(jobData);
132-
133-
await ctx.reply(`${emoji("eyes")} View another announcement?`, {
134-
reply_markup: keyboard,
135-
});
136133
}
137134

138135
async function fetchAndDisplayAnnouncements(ctx: BotContext): Promise<void> {

src/bot/composers/lookups/constants.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { emoji } from "@grammyjs/emoji";
2+
13
/**
24
* Constants for lookup composers to avoid magic numbers
35
*/
@@ -11,3 +13,20 @@ export const LOOKUP_CONFIG = {
1113
/** Initial page number for pagination */
1214
INITIAL_PAGE: 0,
1315
} as const;
16+
17+
/**
18+
* Map context types to their corresponding emojis
19+
*/
20+
export const CONTEXT_EMOJI_MAP: Record<string, string> = {
21+
"calendar": emoji("calendar"),
22+
"timetable": emoji("books"),
23+
"announcement": emoji("paperclip"),
24+
"inline query result": emoji("paperclip"),
25+
} as const;
26+
27+
/**
28+
* Get emoji for a given context
29+
*/
30+
export function getContextEmoji(context: string): string {
31+
return CONTEXT_EMOJI_MAP[context] || emoji("paperclip");
32+
}

src/bot/composers/lookups/exam-timetable/composer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,14 @@ async function handleTimetableAttachment(
133133
],
134134
statusMessageId: statusMessage.message_id,
135135
context: "timetable",
136+
sendViewAnotherMessage: true,
136137
};
137138

138139
if (ctx.msgId !== undefined) {
139140
jobData.replyToMessageId = ctx.msgId;
140141
}
141142

142143
await addAttachmentDeliveryJob(jobData);
143-
144-
await ctx.reply(`${emoji("eyes")} View another timetable?`, {
145-
reply_markup: keyboard,
146-
});
147144
}
148145

149146
async function fetchAndDisplayTimetables(ctx: BotContext): Promise<void> {

src/workers/attachment-delivery/queue.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface AttachmentDeliveryJob {
1111
statusMessageId?: number;
1212
replyToMessageId?: number;
1313
context: string;
14+
sendViewAnotherMessage?: boolean;
1415
}
1516

1617
export const attachmentDeliveryQueue = new Queue<AttachmentDeliveryJob>(

src/workers/attachment-delivery/worker.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import logger from "../../utils/logger.js";
99
import { emoji } from "@grammyjs/emoji";
1010
import { ATTACHMENT_DELIVERY_QUEUE } from "./queue.js";
1111
import { TelegramErrorUtils } from "../shared/utils/telegramErrorHandler.js";
12+
import { createViewAnotherKeyboard } from "../../bot/composers/lookups/utils.js";
13+
import { getContextEmoji } from "../../bot/composers/lookups/constants.js";
1214

1315
export class AttachmentDeliveryWorker extends BaseWorker<AttachmentDeliveryJob> {
1416
constructor() {
@@ -123,6 +125,10 @@ export class AttachmentDeliveryWorker extends BaseWorker<AttachmentDeliveryJob>
123125
if (statusMessageId !== undefined) {
124126
await this.deleteStatusMessage(chatId, statusMessageId);
125127
}
128+
129+
if (job.data.sendViewAnotherMessage) {
130+
await this.sendViewAnotherMessage(job.data.chatId, job.data.context);
131+
}
126132
} catch (error) {
127133
if (statusMessageId !== undefined) {
128134
await this.updateErrorMessage(chatId, statusMessageId);
@@ -134,7 +140,7 @@ export class AttachmentDeliveryWorker extends BaseWorker<AttachmentDeliveryJob>
134140
private buildCaption(attachments: Attachment[], context: string): string {
135141
if (attachments.length === 0) return "";
136142

137-
const contextEmoji = this.getContextEmoji(context);
143+
const contextEmoji = getContextEmoji(context);
138144
const lines = [
139145
`${contextEmoji} Attachments:`,
140146
...attachments.map(a => a.name),
@@ -143,14 +149,19 @@ export class AttachmentDeliveryWorker extends BaseWorker<AttachmentDeliveryJob>
143149
return lines.join("\n");
144150
}
145151

146-
private getContextEmoji(context: string): string {
147-
const emojiMap: Record<string, string> = {
148-
"calendar": emoji("calendar"),
149-
"timetable": emoji("books"),
150-
"announcement": emoji("paperclip"),
151-
"inline query result": emoji("paperclip"),
152-
};
153-
return emojiMap[context] || emoji("paperclip");
152+
private async sendViewAnotherMessage(
153+
chatId: number,
154+
context: string
155+
): Promise<void> {
156+
const keyboard = createViewAnotherKeyboard(context);
157+
const contextEmoji = getContextEmoji(context);
158+
159+
await this.bot!.api.sendMessage(
160+
chatId,
161+
`${contextEmoji} View another ${context}?`,
162+
{ reply_markup: keyboard }
163+
);
164+
logger.debug({ chatId, context }, "Sent view another message");
154165
}
155166

156167
private async deleteStatusMessage(

0 commit comments

Comments
 (0)