TelegramObject-add: Constructing an Updater

Description Usage Arguments Details Examples

Description

With + you can add any kind of Handler to an Updater's Dispatcher (or directly to a Dispatcher).

Usage

1
2
## S3 method for class 'TelegramObject'
e1 + e2

Arguments

e1

An object of class Updater or Dispatcher.

e2

An object of class Handler.

Details

See add_handler for further information.

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
25
26
27
28
29
30
31
## Not run: 
# You can chain multiple handlers
start <- function(bot, update){
  bot$sendMessage(chat_id = update$message$chat_id,
                  text = sprintf("Hello %s!",
                                 update$message$from$first_name))
}
echo <- function(bot, update){
  bot$sendMessage(chat_id = update$message$chat_id,
                  text = update$message$text)
}

updater <- Updater("TOKEN") + CommandHandler("start", start) +
  MessageHandler(echo, MessageFilters$text)
  
# And keep adding...
caps <- function(bot, update, args){
  if (length(args > 0L)){
    text_caps <- toupper(paste(args, collapse = " "))
    bot$sendMessage(chat_id = update$message$chat_id,
                    text = text_caps) 
  }
}

updater <- updater + CommandHandler("caps", caps, pass_args = TRUE)

# Give it a try!
updater$start_polling()
# Send '/start' to the bot, '/caps foo' or just a simple text

## End(Not run)

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