Handler: The base of all handlers

Description Usage Arguments Format Methods Sub-classes Examples

View source: R/handler.R

Description

The base class for all update handlers. Create custom handlers by inheriting from it.

Usage

1
2
3
4
Handler(callback, check_update = NULL, handle_update = NULL,
  handlername = NULL)

is.Handler(x)

Arguments

callback

The callback function for this handler. Its inputs will be (bot, update), where bot is a Bot instance and update an Update class.

check_update

Function that will override the default check_update method. Use it if you want to create your own Handler.

handle_update

Function that will override the default handle_update method. Use it if you want to create your own Handler.

handlername

Name of the customized class, which will inherit from Handler. If NULL (default) it will create a Handler class.

x

Object to be tested.

Format

An R6Class object.

Methods

check_update

Called to determine if an update should be handled by this handler instance.

handle_update

Called if it was determined that an update should indeed be handled by this instance.

Sub-classes

MessageHandler

To handle Telegram messages.

CommandHandler

To handle Telegram commands.

CallbackQueryHandler

To handle Telegram callback queries.

ErrorHandler

To handle errors while polling for updates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Not run: 
# Example of a Handler
callback_method <- function(bot, update){
  chat_id <- update$effective_chat()$id
  bot$sendMessage(chat_id = chat_id, text = "Hello")
}

hello_handler <- Handler(callback_method)

# Customizing Handler
check_update <- function(update){
  TRUE
}

handle_update <- function(update, dispatcher){
  self$callback(dispatcher$bot, update)
}

foo_handler <- Handler(callback_method,
                       check_update = check_update,
                       handle_update = handle_update,
                       handlername = 'FooHandler')

## End(Not run)

ebeneditos/telegram.bot documentation built on Dec. 2, 2018, 1:18 p.m.