CommandHandler: Handling commands

View source: R/commandhandler.R

CommandHandlerR Documentation

Handling commands

Description

Handler class to handle Telegram commands.

Usage

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 /command@username, as bot commands are often called this way.

Format

An R6Class object.

Examples

## 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)

telegram.bot documentation built on Sept. 7, 2022, 5:07 p.m.