| Updater {telegram.bot} | R Documentation |
Building a Telegram Bot with Update Polling
Description
This class, which employs the class Dispatcher, provides a
front-end to class Bot to the programmer, so you can focus on
coding the bot. Its purpose is to receive the updates from Telegram and to
deliver them to said dispatcher. The dispatcher supports
Handler classes for different kinds of data: Updates from
Telegram, basic text commands and even arbitrary types. See
add (+) to learn more about building your
Updater.
Usage
Updater(
token = NULL,
base_url = NULL,
base_file_url = NULL,
request_config = NULL,
bot = NULL
)
is.Updater(x)
Arguments
token |
(Optional). The bot's token given by the BotFather. |
base_url |
(Optional). Telegram Bot API service URL. |
base_file_url |
(Optional). Telegram Bot API file URL. |
request_config |
(Optional). Additional configuration settings
to be passed to the bot's POST requests. See the The |
bot |
(Optional). A pre-initialized |
x |
Object to be tested. |
Format
An R6Class object.
Details
Note: You must supply either a bot or a
token argument.
Methods
start_pollingStarts polling updates from Telegram.
stop_pollingStops the polling.
References
Bots: An introduction for developers and Telegram Bot API
Examples
## Not run:
updater <- Updater(token = "TOKEN")
# In case you want to set a proxy (see ?httr:use_proxy)
updater <- Updater(
token = "TOKEN",
request_config = httr::use_proxy(...)
)
# Add a handler
start <- function(bot, update) {
bot$sendMessage(
chat_id = update$message$chat_id,
text = sprintf(
"Hello %s!",
update$message$from$first_name
)
)
}
updater <- updater + CommandHandler("start", start)
# Start polling
updater$start_polling(verbose = TRUE) # Send '/start' to the bot
## End(Not run)