diff --git a/packages/main/src/telegram_api.ts b/packages/main/src/telegram_api.ts index 3fffb351c..d11288322 100644 --- a/packages/main/src/telegram_api.ts +++ b/packages/main/src/telegram_api.ts @@ -110,4 +110,24 @@ export default class TelegramApi { }); return await fetch(url); } + + + /** + * Send an callback response to a given botApi + * @param botApi - full URL to the telegram API without slug + * @param data - data to append to the request + */ + async answerCallback( + botApi: string, + data: { + callback_query_id: number | string; + text?: string; + show_alert?: boolean; + url?: string; + cache_time?: number; + }, + ) { + const url = this.getApiUrl(botApi, 'answerCallbackQuery', data); + return await fetch(url); + } } diff --git a/packages/main/src/telegram_bot.ts b/packages/main/src/telegram_bot.ts index 1cbf86233..02487ff54 100644 --- a/packages/main/src/telegram_bot.ts +++ b/packages/main/src/telegram_bot.ts @@ -71,6 +71,10 @@ export default class TelegramBot { command = ':document'; break; } + case 'callback': { + command = ':callback'; + break; + } default: break; } diff --git a/packages/main/src/telegram_execution_context.ts b/packages/main/src/telegram_execution_context.ts index 1d66345c4..36716cebe 100644 --- a/packages/main/src/telegram_execution_context.ts +++ b/packages/main/src/telegram_execution_context.ts @@ -33,6 +33,8 @@ export default class TelegramExecutionContext { this.update_type = 'inline'; } else if (this.update.message?.document) { this.update_type = 'document'; + } else if (this.update.callback_query?.id) { + this.update_type = 'callback'; } } diff --git a/packages/main/src/types/TelegramCallbackQuery.ts b/packages/main/src/types/TelegramCallbackQuery.ts new file mode 100644 index 000000000..087e36344 --- /dev/null +++ b/packages/main/src/types/TelegramCallbackQuery.ts @@ -0,0 +1,16 @@ +import TelegramFrom from './TelegramFrom.js'; +import TelegramMessage from './TelegramMessage.js'; + +interface TelegramCallbackQuery { + chat_type: 'sender' | 'private' | 'group' | 'supergroup' | 'channel'; + from: TelegramFrom; + id: number; + offset: string; + query: string; + message: TelegramMessage, + inline_message_id: string; + chat_instance: string; + data: string; + game_short_name: string; +} +export default TelegramCallbackQuery; diff --git a/packages/main/src/types/TelegramUpdate.ts b/packages/main/src/types/TelegramUpdate.ts index 9226dba9f..9d125904f 100644 --- a/packages/main/src/types/TelegramUpdate.ts +++ b/packages/main/src/types/TelegramUpdate.ts @@ -1,6 +1,7 @@ import TelegramInlineQuery from './TelegramInlineQuery.js'; import TelegramMessage from './TelegramMessage.js'; import PartialTelegramUpdate from './PartialTelegramUpdate.js'; +import TelegramCallbackQuery from './TelegramCallbackQuery.js'; export default class TelegramUpdate { update_id: number; @@ -10,7 +11,7 @@ export default class TelegramUpdate { edited_channel_post?: TelegramMessage; inline_query?: TelegramInlineQuery; // chosen_inline_result?: TelegramChosenInlineResult; - // callback_query?: TelegramCallbackQuery; + callback_query?: TelegramCallbackQuery; // shipping_query?: TelegramShippingQuery; // pre_checkout_query?: TelegramPreCheckoutQuery; // poll?: TelegramPoll;