CommandHandler: Handling commands

Description Usage Arguments Format Examples

View source: R/commandhandler.R

Description

Handler class to handle Telegram commands.

Usage

1
2
CommandHandler(command, callback, filters = NULL, pass_args = FALSE,
  username = NULL)

Arguments

command

The command or vector of commands this handler should listen for.

callback

The callback function for this handler. See Handler for information about this function.

filters

(Optional). Only allow updates with these filters. See MessageFilters for a full list of all available filters.

pass_args

(Optional). Determines whether the handler should be passed args, received as a vector, split on spaces.

username

(Optional). Bot's username, you can retrieve it from bot$getMe()$username. If this parameter is passed, then the CommandHandler will also listen to the command /[email protected], as bot commands are often called this way.

Format

An R6Class object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 

# Initialize bot
bot <- Bot("TOKEN")
username <- bot$getMe()$username
updater <- Updater(bot = bot)

# Add a command
start <- function(bot, update){
  bot$sendMessage(chat_id = update$message$chat_id,
                  text = "Hi, I am a bot!")
}

updater <- updater + CommandHandler("start", start, username = username)

## End(Not run)

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