This is a very simple package with only one function tgme. The aim of
this package is to send you a message when a job on Rstudio server is
done (or on your local machine). It is a free alternative to the Rich
Pauloo’s {textme} package.
Many thanks to Luca Braglia for the {telegram}, which this package relies entirely upon.
You can install the released version of tgme from CRAN with:
install.packages("tgme")And the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("atsyplenkov/tgme")This is a basic example which shows you how to solve a common problem:
library(tgme)
## basic example code
tgme("This is your text")- Install Telegram
- Find and start
BotFather - Type
/newbotand follow the instructions. - You need to remember and keep your:
bot_name(it’s the first question you’ve answered to the botfather) and TOKEN to access the HTTP API. The TOKEN will look smth like123123:asdasdasd. - Then you need to get your
chat_id, i.e. your personal user ID.
- Write something to your bot. For example “Test”.
- Then, go to your browser and go to
https://api.telegram.org/bot**TOKEN**/getUpdates. Replace word TOKEN with your actual token number. For example if your’s token is1234FF, then you should go tohttps://api.telegram.org/bot1234FF/getUpdates - In your browser you will see following lines (depending on how many
messages did you send). Sometimes you should write twice to your
bot.
{"ok":true,"result":[{"update_id":1234, "message":{"message_id":3,"from":{**"id":1234**,"is_bot":false,"first_name":"Name","last_name":"Surname","username":"username","language_code":"en"},"chat":{"id":1234,"first_name":"Name","last_name":"Surname","username":"username","type":"private"},"date":124,"text":"Test"}} - The
"id"variable is what we are looking for. Therefore 1234 is yourchat_id.
- Install {telegram} package.
- Run
usethis::edit_r_environ()to update your.Renviron. - Add line with your telegram bot_name and TOKEN:
R_TELEGRAM_BOT_bot_name=123123:asdasdasdFor example if your Bot’s name isExampleBotand your token is1234FF, then you need to addR_TELEGRAM_BOT_ExampleBot=1234FFto your.Renviron. - Add line with your telegram
user_nameand chat_id:R_TELEGRAM_USER_user_name=chat_idFor example if youruser_nameismeand your chat_id is1234, then you need to addR_TELEGRAM_USER_me=1234to your.Renviron. - Restart
Rsession for changes to take effect
Now you can send yourself a message for free, when the R job is done. Try:
library(tgme)
library(tictoc)
tic()
Sys.sleep(5)
fin <- toc()
#> 5.11 sec elapsed
tgme(text = paste0("Job is done for ",
round(fin$toc-fin$tic),
" sec"),
bot_name = "rstudio_server",
user_name = "me")If something is not clear, then read the {telegram} readme for details.

