Skip to content

Commit 63e406f

Browse files
committed
update
1 parent 08199a2 commit 63e406f

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/telegram_execution_context.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ export default class TelegramExecutionContext {
171171
video,
172172
});
173173
} catch (e) {
174-
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
174+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message'); return null; }
175+
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
175176
console.warn('Business connection invalid, retrying without business_connection_id');
176177
return await this.api.sendVideo(this.bot.api.toString(), {
177178
...options,
@@ -237,7 +238,8 @@ export default class TelegramExecutionContext {
237238
caption,
238239
});
239240
} catch (e) {
240-
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
241+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message'); return null; }
242+
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
241243
console.warn('Business connection invalid, retrying without business_connection_id');
242244
return await this.api.sendPhoto(this.bot.api.toString(), {
243245
...options,
@@ -293,7 +295,8 @@ export default class TelegramExecutionContext {
293295
caption,
294296
});
295297
} catch (e) {
296-
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
298+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message'); return null; }
299+
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
297300
console.warn('Business connection invalid, retrying without business_connection_id');
298301
return await this.api.sendVoice(this.bot.api.toString(), {
299302
...options,
@@ -337,7 +340,8 @@ export default class TelegramExecutionContext {
337340
action: 'typing',
338341
});
339342
} catch (e) {
340-
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
343+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message'); return null; }
344+
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
341345
console.warn('Business connection invalid, retrying without business_connection_id');
342346
return await this.api.sendChatAction(this.bot.api.toString(), {
343347

@@ -457,7 +461,8 @@ export default class TelegramExecutionContext {
457461
...options,
458462
});
459463
} catch (e) {
460-
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
464+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message'); return null; }
465+
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
461466
console.warn('Business connection invalid, retrying without business_connection_id');
462467
return await this.api.editMessageText(this.bot.api.toString(), {
463468
chat_id: this.getChatId(),
@@ -490,6 +495,7 @@ export default class TelegramExecutionContext {
490495
business_connection_id,
491496
});
492497
} catch (e) {
498+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message'); return null; }
493499
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
494500
console.warn('Business connection invalid, retrying without business_connection_id');
495501
response = await this.api.sendMessage(this.bot.api.toString(), {
@@ -561,7 +567,8 @@ export default class TelegramExecutionContext {
561567
parse_mode,
562568
});
563569
} catch (e) {
564-
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
570+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message'); return null; }
571+
if (e instanceof Error && e.message === 'BUSINESS_CONNECTION_INVALID') {
565572
console.warn('Business connection invalid, retrying without business_connection_id');
566573
return await this.api.sendMessage(this.bot.api.toString(), {
567574
chat_id: this.getChatId(),

src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ export async function markdownToHtml(s: string): Promise<string> {
4141
renderer.em = ({ tokens }) => `<i>${renderer.parser.parseInline(tokens)}</i>`;
4242
renderer.codespan = ({ text }) => `<code>${text}</code>`;
4343
renderer.code = ({ text, lang }) => {
44+
const escapedText = text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
4445
if (lang) {
45-
return `<pre><code class="language-${lang}">${text}</code></pre>\n`;
46+
return `<pre><code class="language-${lang}">${escapedText}</code></pre>\n`;
4647
}
47-
return `<pre><code>${text}</code></pre>\n`;
48+
return `<pre><code>${escapedText}</code></pre>\n`;
4849
};
4950
renderer.del = ({ tokens }) => `<s>${renderer.parser.parseInline(tokens)}</s>`;
5051

0 commit comments

Comments
 (0)