Webhook | R Documentation |
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 updates via webhook 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 Webhook
.
Webhook( webhook_url, token = NULL, base_url = NULL, base_file_url = NULL, request_config = NULL, certificate = NULL, max_connections = NULL, allowed_updates = NULL, ip_address = NULL, drop_pending_updates = FALSE, verbose = FALSE, bot = NULL ) is.Webhook(x)
webhook_url |
Webhook HTTPS url to send updates to. The url is conventionally
suffixed with the Note: The url must be publicly accessible, since Telegram will need to make
HTTP For example, if you are deploying to Heroku, you can use the app's hostname,
such as |
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 |
certificate |
(Optional). Upload your public key certificate so that the root certificate in use can be checked. See Telegram's self-signed guide for details. |
max_connections |
(Optional). Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput. |
allowed_updates |
(Optional). String or vector of strings with the
types of updates you want your bot to receive. For example, specify
Please note that this parameter doesn't affect updates created before the call to the get_updates, so unwanted updates may be received for a short period of time. |
ip_address |
(Optional). The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS. |
drop_pending_updates |
(Optional). Pass True to drop all pending updates. |
verbose |
(Optional). If |
bot |
(Optional). A pre-initialized |
x |
Object to be tested. |
An R6Class
object.
You must supply the webhook_url
and either a bot
or a token
argument.
The webhook_url
must be publicly accessible, since Telegram will
need to make HTTP POST
requests to the end-point for each update.
Security Note: Webhook
encapsulates generating a secret_token
which
is used to validate that the request comes from a webhook set by you.
start_server
Starts listening for updates from Telegram.
stop_server
Stops listening for updates.
running
Returns TRUE
when listening for updates.
Bots: An introduction for developers, Telegram Bot API and Marvin's Marvellous Guide to All Things Webhook
## Not run: webhook <- Webhook("https://example.com/webhook", "TOKEN") # In case you want to set a proxy webhook <- Webhook( webhook_url = "https://example.com/webhook", token = "TOKEN", request_config = httr::use_proxy(...), verbose = TRUE ) # Add a handler start <- function(bot, update) { bot$sendMessage( chat_id = update$message$chat_id, text = sprintf( "Hello %s!", update$message$from$first_name ) ) } webhook <- webhook + CommandHandler("start", start) # Start polling webhook$start_server() # Send '/start' to the bot ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.