Movatterモバイル変換


[0]ホーム

URL:


Title:R Wrapper Around the Telegram Bot API
Version:0.7.1
Author:Luca Braglia [aut, cre]
Maintainer:Luca Braglia <lbraglia@gmail.com>
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).
URL:https://github.com/lbraglia/telegram
BugReports:https://github.com/lbraglia/telegram/issues
Imports:R6, httr, jsonlite, curl, utils
Depends:R (≥ 3.2.3)
License:GPL-3
RoxygenNote:7.3.2
NeedsCompilation:no
Packaged:2025-03-25 07:43:09 UTC; l
Repository:CRAN
Date/Publication:2025-03-25 08:00:06 UTC

telegram.

Description

Simple R wrapper around the Telegram Bot API(http://core.telegram.org/bots/api) to access Telegram's messagingfacilities with ease (eg you send messages, images, files from R toyour smartphone)

Author(s)

Maintainer: Luca Braglialbraglia@gmail.com

See Also

Useful links:


TGBot

Description

Package main class (implementing the Telegram bot).

Format

AnR6Class generator object.

API Methods

forwardMessage

forward messages of anykind

getFile

get info about a file anddownload it

getMe

test your bot's authtoken

getUpdates

receive incomingupdates

getUserProfilePhotos

get a listof profile pictures for a user

sendAudio

sendmp3 files

sendDocument

send general files

sendLocation

send point on the map

sendMessage

send text messages

sendPhoto

send image files

sendSticker

send.webp stickers

sendVideo

sendmp4 videos

sendVoice

send ogg files encoded withOPUS

sendPoll

send a telegram poll

stopPoll

stop a telegram poll and obtain results

Methods

Public methods


Methodnew()

Usage
TGBot$new(token, proxy)

Methodset_token()

Usage
TGBot$set_token(token)

Methodset_proxy()

Usage
TGBot$set_proxy(proxy)

Methodset_default_chat_id()

Usage
TGBot$set_default_chat_id(chat_id)

Methodreq()

Usage
TGBot$req(method = NULL, body = NULL)

Methodlast_request()

Usage
TGBot$last_request()

Methodprint()

Usage
TGBot$print()

MethodforwardMessage()

Usage
TGBot$forwardMessage(  from_chat_id = NULL,  message_id = NULL,  disable_notification = NULL,  chat_id = NULL)

MethodgetFile()

Usage
TGBot$getFile(file_id, destfile = NULL)

MethodgetMe()

Usage
TGBot$getMe()

MethodgetUpdates()

Usage
TGBot$getUpdates(offset = NULL, limit = NULL)

MethodgetUserProfilePhotos()

Usage
TGBot$getUserProfilePhotos(user_id = NULL, offset = NULL, limit = NULL)

MethodsendAudio()

Usage
TGBot$sendAudio(  audio = NULL,  caption = NULL,  duration = NULL,  performer = NULL,  title = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendChatAction()

Usage
TGBot$sendChatAction(action = NULL, chat_id = NULL)

MethodsendDocument()

Usage
TGBot$sendDocument(  document = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendLocation()

Usage
TGBot$sendLocation(  latitude = NULL,  longitude = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendMessage()

Usage
TGBot$sendMessage(  text = NULL,  parse_mode = NULL,  disable_web_page_preview = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendPhoto()

Usage
TGBot$sendPhoto(  photo = NULL,  caption = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendSticker()

Usage
TGBot$sendSticker(  sticker = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendVideo()

Usage
TGBot$sendVideo(  video = NULL,  duration = NULL,  caption = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendVoice()

Usage
TGBot$sendVoice(  voice = NULL,  duration = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

MethodsendDice()

Usage
TGBot$sendDice(disable_notification = NULL, chat_id = NULL)

MethodsendPoll()

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

MethodstopPoll()

Usage
TGBot$stopPoll(message_id = NULL, chat_id = NULL)

Methodclone()

The objects of this class are cloneable with this method.

Usage
TGBot$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

References

Bots: Anintroduction for developers andTelegram Bot API

Examples

## Not run: ## Without proxybot <- 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)

bot_token

Description

Obtain token from system variables (inRenviron) setaccording to package naming conventions, that isR_TELEGRAM_BOT_ whereX is bot's name (first questionanswered to the botfather).

Usage

bot_token(x)

Arguments

x

character of length 1 with the name of the bot; ifNULL a menu to choose between bot is displayed and theproper value returned

Examples

## Not run:  bot_token('RBot')

forwardMessage

Description

Forward messages of any kind

Usage

forwardMessage(  from_chat_id = NULL,  message_id = NULL,  disable_notification = NULL,  chat_id = NULL)

Arguments

from_chat_id

Unique identifier for the chat where theoriginal message was sent (required)

message_id

Unique message identifier (required)

disable_notification

Sends the message silently. Users willreceive a notification with no sound

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


getFile

Description

Get info about a file and download it

Usage

getFile(file_id, destfile = NULL)

Arguments

file_id

File identifier (required)

destfile

Destination path; if specified the file will bedownloaded


getMe

Description

Test your bot's auth token

Usage

getMe()

getUpdates

Description

Receive incoming updates

Usage

getUpdates(offset = NULL, limit = NULL)

Arguments

offset

Identifier of the first update to be returned.

limit

Limits the number of updates to be retrieved. Valuesbetween 1-100 are accepted. Defaults to 100


getUserProfilePhotos

Description

Get a list of profile pictures for a user

Usage

getUserProfilePhotos(user_id = NULL, offset = NULL, limit = NULL)

Arguments

user_id

Unique identifier of the target user (required)

offset

Sequential number of the first photo to bereturned. By default, all photos are returned

limit

Limits the number of photos to be retrieved. Valuesbetween 1-100 are accepted. Defaults to 100


group_id

Description

Obtain telegram user id from system variables (inRenviron) setaccording to package naming conventions, that isR_TELEGRAM_USER_X where is the user's name .

Usage

group_id(x)

Arguments

x

character of length 1 with the name of the user; ifNULL a menu to choose between bot is displayed and theproper value returned

Examples

## Not run:  group_id('test_group')

proxy

Description

Obtain telegram proxy from system variables (inRenviron) setaccording to package naming conventions, that isR_TELEGRAM_PROXY_X_Y where X is the proxy's name and Y are theproxy parameters.

Usage

proxy(x)

Arguments

x

character of length 1 with the name of the proxy; ifNULL a menu to choose between proxy is displayed and theproper value returned

Examples

## Not run:  proxy('default')

sendAudio

Description

Sendmp3 files

Usage

sendAudio(  audio = NULL,  caption = NULL,  duration = NULL,  performer = NULL,  title = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

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 willreceive a notification with no sound

reply_to_message_id

If the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendChatAction

Description

Tell the user that something is happening on the bot's side

Usage

sendChatAction(action = NULL, chat_id = NULL)

Arguments

action

type of action to broadcast. Choose one, depending onwhat the user is about to receive: "typing" for text messages,"upload_photo" for photos, "record_video" or "upload_video" forvideos, "record_voice" or "upload_voice" for voice notes,"upload_document" for general files, "find_location" forlocation data, "record_video_note" or "upload_video_note" forvideo notes.

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendDice

Description

Use this method to send a dice, which will have a random value from1 to 6.

Usage

sendDice(disable_notification = NULL, chat_id = NULL)

Arguments

disable_notification

Sends the message silently. Users willreceive a notification with no sound

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendDocument

Description

Send general files

Usage

sendDocument(  document = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

document

path to the file to send (required)

disable_notification

Sends the message silently. Users willreceive a notification with no sound

reply_to_message_id

if the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendLocation

Description

Send point on the map

Usage

sendLocation(  latitude = NULL,  longitude = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

latitude

Latitude of location (required)

longitude

Longitude of location (required)

disable_notification

Sends the message silently. Users willreceive a notification with no sound

reply_to_message_id

If the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendMessage

Description

Send text messages

Usage

sendMessage(  text = NULL,  parse_mode = NULL,  disable_web_page_preview = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

text

Text of the message to be sent (required)

parse_mode

send 'Markdown' if you want Telegram apps to showbold, italic and inline URLs in your bot's message

disable_web_page_preview

Disables link previews for links inthis message

disable_notification

Sends the message silently. Users willreceive a notification with no sound

reply_to_message_id

If the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendPhoto

Description

Send image files

Usage

sendPhoto(  photo = NULL,  caption = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

photo

photo to send (required)

caption

photo caption

disable_notification

Sends the message silently. Users willreceive a notification with no sound

reply_to_message_id

If the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendPoll

Description

Use this method to send a native poll.

Usage

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)

Arguments

question

Poll question, 1-255 characters

options

vector of possible answers: 2-10 strings 1-100characters each

is_anonymous

if TRUE (default) the poll needs to beanonymous

type

poll type, 'quiz' or 'regular', defaults to 'regular'

allows_multiple_answers

if TRUE the poll allows multipleanswers (default to FALSE and ignored for polls in quiz mode)

correct_option_id

0-based identifier of the correct answeroption, required for polls in quiz mode (eg 0 set the firstanswer as correct)

is_closed

if TRUE the poll needs to be immediatelyclosed. This can be useful for poll preview. (default to FALSE)

disable_notification

Sends the message silently. Users willreceive a notification with no sound

reply_to_message_id

If the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendSticker

Description

Send.webp stickers

Usage

sendSticker(  sticker = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

sticker

sticker to send (required)

disable_notification

Sends the message silently. Users willreceive a notification with no sound

reply_to_message_id

If the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendVideo

Description

Sendmp4 videos

Usage

sendVideo(  video = NULL,  duration = NULL,  caption = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

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 theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


sendVoice

Description

Send.ogg files encoded with OPUS

Usage

sendVoice(  voice = NULL,  duration = NULL,  disable_notification = NULL,  reply_to_message_id = NULL,  chat_id = NULL)

Arguments

voice

Audio file to send (required)

duration

Duration of sent audio in seconds

disable_notification

Sends the message silently. Users willreceive a notification with no sound

reply_to_message_id

If the message is a reply, ID of theoriginal message

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


stopPoll

Description

Use this method to stop a poll which was sent by the bot.

Usage

stopPoll(message_id = NULL, chat_id = NULL)

Arguments

message_id

Identifier of the original message with the poll

chat_id

Unique identifier for the target chat or username ofthe target channel (required)


user_id

Description

Obtain telegram user id from system variables (inRenviron) setaccording to package naming conventions, that isR_TELEGRAM_USER_X where is the user's name .

Usage

user_id(x)

Arguments

x

character of length 1 with the name of the user; ifNULL a menu to choose between bot is displayed and theproper value returned

Examples

## Not run:  user_id('me')

[8]ページ先頭

©2009-2025 Movatter.jp