-
Notifications
You must be signed in to change notification settings - Fork 4
Callback Query Manager
Abdi Urgessa edited this page Apr 21, 2024
·
7 revisions
The CallbackQueryManager
is a specialized component aimed at managing callback queries that a Telegram bot might receive. Callback queries are typically sent by Telegram servers when a user interacts with an inline keyboard attached to a message.
Here's how you might use the CallbackQueryManager
in conjunction with the bot event listener for callback queries:
telesun.on('callback_query', (ctx) => {
const data = ctx.callbackQuery.data;
// Process the callback query here
ctx.answerCallbackQuery(ctx.callbackQuery.id, {
text:'Received your request!',
show_alert: true,
});
});
The CallbackQueryManager
class provides methods specifically for dealing with callback queries. Below is an overview of its method:
-
answerCallbackQuery(objParam)
: Answers a callback query, typically to stop the loading spinner on the user's client. This method can also be used to send alerts or messages back to the user.
The answerCallbackQuery
method is central to the CallbackQueryManager
, allowing the bot to respond to the user's interaction. Here's a closer look at its usage:
Parameters:
-
objParam
: An object containing parameters for answering the callback query. This can include fields such astext
for a notification message to the user,showAlert
to indicate if an alert should be shown to the user instead of a toast notification, andurl
to send a URL that will be opened by the user's client.
Example Usage:
// Example of answering a callback query with a simple notification
ctx.answerCallbackQuery(ctx.callbackQuery.id, {
text: 'Thank you for your response!',
showAlert: false // This will not show an alert, but a toast notification
});
// Example of answering a callback query with an alert
ctx.answerCallbackQuery(ctx.callbackQuery.id, {
text: 'Please note this important information.',
showAlert: true // This will show an alert dialog
});
Advanced Usage:
// Example of answering a callback query and directing the user to a URL
ctx.answerCallbackQuery(ctx.callbackQuery.id, {
text: 'Check out this link for more information.',
url: 'https://example.com',
showAlert: true // Optional, based on whether you want to show the text as an alert
});
- Manager Classes:
- Mail:
- Google Spreadsheet:
- Best Practice:
- Getting Updates:
- Example Types:
- Example Bots: