Skip to content

Commit a53328e

Browse files
committed
parse html in inline mode
1 parent 369d10c commit a53328e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

packages/main/src/telegram_execution_context.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ export default class TelegramExecutionContext {
127127
}
128128
}
129129

130+
async replyInline(title: string, message: string, parse_mode = '') {
131+
switch (this.update_type) {
132+
case 'inline':
133+
return await this.api.answerInline(this.bot.api.toString(), {
134+
inline_query_id: this.update.inline_query?.id.toString() ?? '',
135+
results: [new TelegramInlineQueryResultArticle({ content: message, title, parse_mode })],
136+
});
137+
default:
138+
break;
139+
}
140+
}
141+
130142
/**
131143
* Reply to the last message with text
132144
* @param message - text to reply with
@@ -161,7 +173,7 @@ export default class TelegramExecutionContext {
161173
case 'inline':
162174
return await this.api.answerInline(this.bot.api.toString(), {
163175
inline_query_id: this.update.inline_query?.id.toString() ?? '',
164-
results: [new TelegramInlineQueryResultArticle(message)],
176+
results: [new TelegramInlineQueryResultArticle({ content: message, parse_mode })],
165177
});
166178
case 'document':
167179
return await this.api.sendMessage(this.bot.api.toString(), {

packages/main/src/types/TelegramInlineQueryResultArticle.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ export default class TelegramInlineQueryResultArticle extends TelegramInlineQuer
55
title: string;
66
input_message_content: TelegramInputMessageContent;
77
thumb_url: string;
8-
constructor(content: string, title = content, parse_mode = '', thumb_url = '') {
8+
constructor(data: { content: string; title?: string; parse_mode?: string; thumb_url?: string }) {
99
super('article');
10-
this.title = title;
10+
this.title = data.title ?? '';
1111
this.input_message_content = {
12-
message_text: content.toString(),
13-
parse_mode,
12+
message_text: data.content.toString(),
13+
parse_mode: data.parse_mode ?? '',
1414
};
15-
this.thumb_url = thumb_url;
15+
this.thumb_url = data.thumb_url ?? '';
1616
}
1717
}

packages/worker/src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export default {
277277
return new Response('ok');
278278
}
279279
if ('response' in response) {
280-
await bot.reply(response.response ?? '');
280+
await bot.replyInline(response.response ?? '', await markdown_to_html(response.response ?? ''), 'HTML');
281281
}
282282
break;
283283
}

0 commit comments

Comments
 (0)