Skip to content

Commit 2ce9352

Browse files
committed
update
1 parent 53bc684 commit 2ce9352

1 file changed

Lines changed: 9 additions & 36 deletions

File tree

src/telegram_execution_context.ts

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import TelegramApi, {
77
SendVoiceParams,
88
SendChatActionParams,
99
SendInvoiceParams,
10-
EditMessageTextParams
10+
EditMessageTextParams,
11+
SendMessageDraftParams
1112
} from './telegram_api.js';
1213
import TelegramBot from './telegram_bot.js';
1314

@@ -493,58 +494,30 @@ export default class TelegramExecutionContext {
493494
draft_id: number,
494495
parse_mode = '',
495496
options: Record<string, number | string | boolean | object> = {},
497+
finish = false
496498
) {
497-
const message_id = this.drafts.get(draft_id);
498-
499-
if (message_id) {
500-
const params: EditMessageTextParams = {
501-
chat_id: this.getChatId(),
502-
message_id,
503-
text: message,
504-
parse_mode,
505-
...options,
506-
};
507-
if (this.update_type === 'business_message') {
508-
params.business_connection_id = this.update.business_message?.business_connection_id;
509-
}
510-
return await this.withBusinessFallback(params, (api, data) => this.api.editMessageText(api, data));
499+
if (finish) {
500+
return await this.reply(message, parse_mode, true, options as any);
511501
}
512502

513503
if (this.update_type === 'guest_message') {
514-
if (this.drafts.has(draft_id)) {
515-
return new Response('Query already answered', { status: 200 });
516-
}
517-
this.drafts.set(draft_id, -1);
518504
return await this.answerGuestQueryText(message, parse_mode);
519505
}
520506

521-
const params: SendMessageParams = {
522-
...options as unknown as SendMessageParams, // Cast options to any here because options is a broad record
507+
const params: SendMessageDraftParams = {
508+
...options as unknown as SendMessageDraftParams,
523509
chat_id: this.getChatId(),
524510
message_thread_id: this.getThreadId(),
525511
text: message,
526512
parse_mode,
513+
draft_id,
527514
};
528515

529516
if (this.update_type === 'business_message') {
530517
params.business_connection_id = this.update.business_message?.business_connection_id;
531518
}
532519

533-
const response = await this.withBusinessFallback(params, (api, data) => this.api.sendMessage(api, data));
534-
535-
if (response && response.status === 200) {
536-
const cloned = response.clone();
537-
try {
538-
const json = (await cloned.json()) as { ok: boolean; result: { message_id: number } };
539-
if (json.ok && json.result?.message_id) {
540-
this.drafts.set(draft_id, json.result.message_id);
541-
}
542-
} catch {
543-
// ignore
544-
}
545-
}
546-
547-
return response;
520+
return await this.withBusinessFallback(params, (api, data) => this.api.sendMessageDraft(api, data));
548521
}
549522

550523
async reply(message: string, parse_mode = '', reply = true, options: Record<string, number | string | boolean> = {}) {

0 commit comments

Comments
 (0)