Title: | R Wrapper Around the Telegram Bot API |
---|---|
Description: | A simple wrapper around the Telegram Bot API (https://core.telegram.org/bots/api) to access Telegram's messaging facilities with ease (e.g. you send messages, images, files from R to your smartphone). |
Authors: | Luca Braglia [aut, cre] |
Maintainer: | Luca Braglia <[email protected]> |
License: | GPL-3 |
Version: | 0.7.0 |
Built: | 2024-11-06 04:41:36 UTC |
Source: | https://github.com/lbraglia/telegram |
Obtain token from system variables (in Renviron
) set
according to package naming conventions, that is
R_TELEGRAM_BOT_
where X
is bot's name (first question
answered to the botfather).
bot_token(x)
bot_token(x)
x |
character of length 1 with the name of the bot; if
|
## Not run: bot_token('RBot')
## Not run: bot_token('RBot')
Forward messages of any kind
forwardMessage( from_chat_id = NULL, message_id = NULL, disable_notification = NULL, chat_id = NULL )
forwardMessage( from_chat_id = NULL, message_id = NULL, disable_notification = NULL, chat_id = NULL )
from_chat_id |
Unique identifier for the chat where the original message was sent (required) |
message_id |
Unique message identifier (required) |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Get info about a file and download it
getFile(file_id, destfile = NULL)
getFile(file_id, destfile = NULL)
file_id |
File identifier (required) |
destfile |
Destination path; if specified the file will be downloaded |
Receive incoming updates
getUpdates(offset = NULL, limit = NULL)
getUpdates(offset = NULL, limit = NULL)
offset |
Identifier of the first update to be returned. |
limit |
Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100 |
Get a list of profile pictures for a user
getUserProfilePhotos(user_id = NULL, offset = NULL, limit = NULL)
getUserProfilePhotos(user_id = NULL, offset = NULL, limit = NULL)
user_id |
Unique identifier of the target user (required) |
offset |
Sequential number of the first photo to be returned. By default, all photos are returned |
limit |
Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100 |
Obtain telegram user id from system variables (in Renviron
) set
according to package naming conventions, that is
R_TELEGRAM_USER_X
where is the user's name .
group_id(x)
group_id(x)
x |
character of length 1 with the name of the user; if
|
## Not run: group_id('test_group')
## Not run: group_id('test_group')
Obtain telegram proxy from system variables (in Renviron
) set
according to package naming conventions, that is
R_TELEGRAM_PROXY_X_Y
where X is the proxy's name and Y are the
proxy parameters.
proxy(x)
proxy(x)
x |
character of length 1 with the name of the proxy; if
|
## Not run: proxy('default')
## Not run: proxy('default')
Send mp3
files
sendAudio( audio = NULL, caption = NULL, duration = NULL, performer = NULL, title = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendAudio( audio = NULL, caption = NULL, duration = NULL, performer = NULL, title = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
audio |
path to audio file to send (required) |
caption |
audio caption |
duration |
duration of the audio in seconds |
performer |
performer |
title |
track name |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Tell the user that something is happening on the bot's side
sendChatAction(action = NULL, chat_id = NULL)
sendChatAction(action = NULL, chat_id = NULL)
action |
type of action to broadcast. Choose one, depending on what the user is about to receive: "typing" for text messages, "upload_photo" for photos, "record_video" or "upload_video" for videos, "record_voice" or "upload_voice" for voice notes, "upload_document" for general files, "find_location" for location data, "record_video_note" or "upload_video_note" for video notes. |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Use this method to send a dice, which will have a random value from 1 to 6.
sendDice(disable_notification = NULL, chat_id = NULL)
sendDice(disable_notification = NULL, chat_id = NULL)
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Send general files
sendDocument( document = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendDocument( document = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
document |
path to the file to send (required) |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
if the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Send point on the map
sendLocation( latitude = NULL, longitude = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendLocation( latitude = NULL, longitude = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
latitude |
Latitude of location (required) |
longitude |
Longitude of location (required) |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Send text messages
sendMessage( text = NULL, parse_mode = NULL, disable_web_page_preview = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendMessage( text = NULL, parse_mode = NULL, disable_web_page_preview = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
text |
Text of the message to be sent (required) |
parse_mode |
send 'Markdown' if you want Telegram apps to show bold, italic and inline URLs in your bot's message |
disable_web_page_preview |
Disables link previews for links in this message |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Send image files
sendPhoto( photo = NULL, caption = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendPhoto( photo = NULL, caption = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
photo |
photo to send (required) |
caption |
photo caption |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Use this method to send a native poll.
sendPoll( question = NULL, options = NULL, is_anonymous = TRUE, type = c("regular", "quiz"), allows_multiple_answers = FALSE, correct_option_id = NULL, is_closed = FALSE, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendPoll( question = NULL, options = NULL, is_anonymous = TRUE, type = c("regular", "quiz"), allows_multiple_answers = FALSE, correct_option_id = NULL, is_closed = FALSE, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
question |
Poll question, 1-255 characters |
options |
vector of possible answers: 2-10 strings 1-100 characters each |
is_anonymous |
if TRUE (default) the poll needs to be anonymous |
type |
poll type, 'quiz' or 'regular', defaults to 'regular' |
allows_multiple_answers |
if TRUE the poll allows multiple answers (default to FALSE and ignored for polls in quiz mode) |
correct_option_id |
0-based identifier of the correct answer option, required for polls in quiz mode (eg 0 set the first answer as correct) |
is_closed |
if TRUE the poll needs to be immediately closed. This can be useful for poll preview. (default to FALSE) |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Send .webp
stickers
sendSticker( sticker = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendSticker( sticker = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sticker |
sticker to send (required) |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Send mp4
videos
sendVideo( video = NULL, duration = NULL, caption = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendVideo( video = NULL, duration = NULL, caption = NULL, reply_to_message_id = NULL, chat_id = NULL )
video |
Video to send (required) |
duration |
Duration of sent video in seconds |
caption |
Video caption |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Send .ogg
files encoded with OPUS
sendVoice( voice = NULL, duration = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendVoice( voice = NULL, duration = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
voice |
Audio file to send (required) |
duration |
Duration of sent audio in seconds |
disable_notification |
Sends the message silently. Users will receive a notification with no sound |
reply_to_message_id |
If the message is a reply, ID of the original message |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Use this method to stop a poll which was sent by the bot.
stopPoll(message_id = NULL, chat_id = NULL)
stopPoll(message_id = NULL, chat_id = NULL)
message_id |
Identifier of the original message with the poll |
chat_id |
Unique identifier for the target chat or username of the target channel (required) |
Simple R wrapper around the Telegram Bot API (http://core.telegram.org/bots/api) to access Telegram's messaging facilities with ease (eg you send messages, images, files from R to your smartphone)
Maintainer: Luca Braglia [email protected]
Useful links:
Package main class (implementing the Telegram bot).
An R6Class
generator object.
forwardMessage
forward messages of any kind
getFile
get info about a file and download it
getMe
test your bot's auth token
getUpdates
receive incoming updates
getUserProfilePhotos
get a list of profile pictures for a user
sendAudio
send mp3
files
sendDocument
send general files
sendLocation
send point on the map
sendMessage
send text messages
sendPhoto
send image files
sendSticker
send .webp
stickers
sendVideo
send mp4
videos
sendVoice
send ogg files encoded with OPUS
sendPoll
send a telegram poll
stopPoll
stop a telegram poll and obtain results
new()
TGBot$new(token, proxy)
set_token()
TGBot$set_token(token)
set_proxy()
TGBot$set_proxy(proxy)
set_default_chat_id()
TGBot$set_default_chat_id(chat_id)
req()
TGBot$req(method = NULL, body = NULL)
last_request()
TGBot$last_request()
print()
TGBot$print()
forwardMessage()
TGBot$forwardMessage( from_chat_id = NULL, message_id = NULL, disable_notification = NULL, chat_id = NULL )
getFile()
TGBot$getFile(file_id, destfile = NULL)
getMe()
TGBot$getMe()
getUpdates()
TGBot$getUpdates(offset = NULL, limit = NULL)
getUserProfilePhotos()
TGBot$getUserProfilePhotos(user_id = NULL, offset = NULL, limit = NULL)
sendAudio()
TGBot$sendAudio( audio = NULL, caption = NULL, duration = NULL, performer = NULL, title = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendChatAction()
TGBot$sendChatAction(action = NULL, chat_id = NULL)
sendDocument()
TGBot$sendDocument( document = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendLocation()
TGBot$sendLocation( latitude = NULL, longitude = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendMessage()
TGBot$sendMessage( text = NULL, parse_mode = NULL, disable_web_page_preview = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendPhoto()
TGBot$sendPhoto( photo = NULL, caption = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendSticker()
TGBot$sendSticker( sticker = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendVideo()
TGBot$sendVideo( video = NULL, duration = NULL, caption = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendVoice()
TGBot$sendVoice( voice = NULL, duration = NULL, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
sendDice()
TGBot$sendDice(disable_notification = NULL, chat_id = NULL)
sendPoll()
TGBot$sendPoll( question = NULL, options = NULL, is_anonymous = TRUE, type = c("regular", "quiz"), allows_multiple_answers = FALSE, correct_option_id = NULL, is_closed = FALSE, disable_notification = NULL, reply_to_message_id = NULL, chat_id = NULL )
stopPoll()
TGBot$stopPoll(message_id = NULL, chat_id = NULL)
clone()
The objects of this class are cloneable with this method.
TGBot$clone(deep = FALSE)
deep
Whether to make a deep clone.
Bots: An introduction for developers and Telegram Bot API
## Not run: ## Without proxy bot <- TGBot$new(token = bot_token('RBot')) ## With a proxy ... prx <- list('url' = '123.45.6.78', 'port' = 8080, 'username' = 'user', 'password' = 'password') bot <- TGBot$new(token = bot_token('RBot'), proxy = prx) ## .. or bot <- TGBot$new(token = bot_token('RBot')) bot$set_proxy(proxy = prx) ## End(Not run)
## Not run: ## Without proxy bot <- TGBot$new(token = bot_token('RBot')) ## With a proxy ... prx <- list('url' = '123.45.6.78', 'port' = 8080, 'username' = 'user', 'password' = 'password') bot <- TGBot$new(token = bot_token('RBot'), proxy = prx) ## .. or bot <- TGBot$new(token = bot_token('RBot')) bot$set_proxy(proxy = prx) ## End(Not run)
Obtain telegram user id from system variables (in Renviron
) set
according to package naming conventions, that is
R_TELEGRAM_USER_X
where is the user's name .
user_id(x)
user_id(x)
x |
character of length 1 with the name of the user; if
|
## Not run: user_id('me')
## Not run: user_id('me')