Skip to content

Commit

Permalink
Merge pull request #947 from yswtrue/master
Browse files Browse the repository at this point in the history
add callback_query support
  • Loading branch information
codebam authored Nov 14, 2024
2 parents 5457b9c + 159aa33 commit ce2fd03
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/main/src/telegram_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions packages/main/src/telegram_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export default class TelegramBot {
command = ':document';
break;
}
case 'callback': {
command = ':callback';
break;
}
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/main/src/telegram_execution_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/main/src/types/TelegramCallbackQuery.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion packages/main/src/types/TelegramUpdate.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ce2fd03

Please sign in to comment.