Skip to content

Commit 08199a2

Browse files
committed
update
1 parent 1294724 commit 08199a2

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/telegram_api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ export default class TelegramApi {
163163
throw new Error('BUSINESS_CONNECTION_INVALID');
164164
}
165165

166+
if (errorDescription.includes('PEER_ID_INVALID')) {
167+
throw new Error('PEER_ID_INVALID');
168+
}
169+
166170
throw new Error(`Telegram API error: ${String(response.status)} ${response.statusText}${errorDescription ? ': ' + errorDescription : ''}`);
167171
}
168172
const cloned = response.clone();

src/telegram_execution_context.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export default class TelegramExecutionContext {
128128
private getMessageId(): string {
129129
if (this.update.message?.message_id) {
130130
return this.update.message.message_id.toString();
131+
} else if (this.update.business_message?.message_id) {
132+
return this.update.business_message.message_id.toString();
131133
} else if (this.update.guest_message?.message_id) {
132134
return this.update.guest_message.message_id.toString();
133135
}
@@ -139,7 +141,7 @@ export default class TelegramExecutionContext {
139141
* @returns The message thread ID as a number or undefined
140142
*/
141143
private getThreadId(): number | undefined {
142-
return this.update.message?.message_thread_id;
144+
return this.update.message?.message_thread_id ?? this.update.business_message?.message_thread_id;
143145
}
144146

145147
/**
@@ -179,7 +181,7 @@ export default class TelegramExecutionContext {
179181
video,
180182
});
181183
}
182-
throw e;
184+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message even without business connection'); return null; } throw e;
183185
}
184186
case 'guest_message':
185187
return await this.answerGuestQueryVideo(video);
@@ -246,7 +248,7 @@ export default class TelegramExecutionContext {
246248
caption,
247249
});
248250
}
249-
throw e;
251+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message even without business connection'); return null; } throw e;
250252
}
251253
case 'guest_message':
252254
return await this.answerGuestQueryPhoto(photo, caption);
@@ -302,7 +304,7 @@ export default class TelegramExecutionContext {
302304
caption,
303305
});
304306
}
305-
throw e;
307+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message even without business connection'); return null; } throw e;
306308
}
307309
case 'guest_message':
308310
return await this.answerGuestQueryVoice(voice, caption);
@@ -344,7 +346,7 @@ export default class TelegramExecutionContext {
344346
action: 'typing',
345347
});
346348
}
347-
throw e;
349+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message even without business connection'); return null; } throw e;
348350
}
349351
default:
350352
return null;
@@ -465,7 +467,7 @@ export default class TelegramExecutionContext {
465467
...options,
466468
});
467469
}
468-
throw e;
470+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message even without business connection'); return null; } throw e;
469471
}
470472
}
471473

@@ -498,7 +500,7 @@ export default class TelegramExecutionContext {
498500
parse_mode,
499501
});
500502
} else {
501-
throw e;
503+
if (e instanceof Error && e.message === 'PEER_ID_INVALID') { console.error('Peer invalid, cannot deliver message even without business connection'); return null; } throw e;
502504
}
503505
}
504506

0 commit comments

Comments
 (0)