Skip to content

Commit 4228c7b

Browse files
committed
final fix
1 parent cfce05e commit 4228c7b

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/telegram_execution_context.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,18 @@ export default class TelegramExecutionContext {
170170
try {
171171
const response = await this.api.getBusinessConnection(this.bot.api.toString(), connectionId);
172172
if (response.status === 200) {
173-
const json = await response.json() as { ok: boolean, result: { user: { id: number } } };
174-
if (json.ok && json.result?.user?.id) {
175-
ownerId = json.result.user.id;
176-
TelegramExecutionContext.businessOwners.set(connectionId, ownerId);
173+
const json = await response.json() as { ok: boolean, result: { user: { id: number }, user_chat_id: number, can_reply: boolean } };
174+
if (json.ok && json.result) {
175+
ownerId = json.result.user?.id || json.result.user_chat_id;
176+
if (ownerId) {
177+
TelegramExecutionContext.businessOwners.set(connectionId, ownerId);
178+
}
179+
// If the bot cannot reply via this connection, treat it as invalid for our purposes
180+
if (json.result.can_reply === false) {
181+
console.warn('Bot cannot reply via this business connection, falling back');
182+
const { business_connection_id, ...retryParams } = params;
183+
return await apiMethod(this.bot.api.toString(), retryParams);
184+
}
177185
}
178186
}
179187
} catch (e) {

0 commit comments

Comments
 (0)