diff --git a/chatbot.Rproj b/chatbot.Rproj new file mode 100644 index 0000000..e83436a --- /dev/null +++ b/chatbot.Rproj @@ -0,0 +1,16 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes diff --git a/intro_al_botfatheR.Rmd b/intro_al_botfatheR.Rmd new file mode 100644 index 0000000..47202a4 --- /dev/null +++ b/intro_al_botfatheR.Rmd @@ -0,0 +1,69 @@ +--- +title: "Como usar el chatbot de Telegram con R" +author: "ixpantia" +date: "10/10/2020" +output: html_document +editor_options: + chunk_output_type: console +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +library(telegram.bot) +``` + +## Introduccion + +Quereomos usar Telegram + +## Un simple ejemplo + +```{r} +TOKEN <- Sys.getenv("TOKEN") + +start <- function(bot, update) { + bot$sendMessage( + chat_id = update$message$chat$id, + text = sprintf("Hola %s! \n + este es un mensaje de varias \n + si varias \n + lineas", update$message$from$first_name) + ) +} + +updater <- Updater(TOKEN) + CommandHandler("start", start) + +updater$start_polling() # Send "/start" to the bot + +``` + + +## Ahora con dos comandos + +```{r} +TOKEN <- Sys.getenv("TOKEN") + +start <- function(bot, update) { + bot$sendMessage( + chat_id = update$message$chat$id, + text = sprintf("Hola %s! acabas de comuncarte con el Chatbot de ConectaR2021. Usted tiene el control sobre este chatbot, haciendo sus consultas con los siguientes comandos. ..... ", update$message$from$first_name) + ) +} + + +hola <- function(bot, update) { + bot$sendMessage( + chat_id = update$message$chat$id, + text = sprintf("Hola este es el chatbot de la conferencia ConectaR2021. Puedes usar esto para obtener informacion sobre lo que estamos haciendo. Para ver las diferentes opciones usa el /en este momento tenemos /info /programa. ", + update$message$from$first_name) + ) +} + +updater <- Updater(TOKEN) + CommandHandler("start", start) +updater <- Updater(TOKEN) + CommandHandler("hola", hola) + +updater$start_polling() # Send "/start" to the bot + +``` + +