From c523cd225fa285bd5fff01a1e2478776f6216228 Mon Sep 17 00:00:00 2001 From: FvD Date: Sat, 10 Oct 2020 08:43:27 -0600 Subject: [PATCH 1/2] primer ejemplo --- chatbot.Rproj | 16 ++++++++++++++++ intro_al_botfatheR.Rmd | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 chatbot.Rproj create mode 100644 intro_al_botfatheR.Rmd 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..b3b4bee --- /dev/null +++ b/intro_al_botfatheR.Rmd @@ -0,0 +1,38 @@ +--- +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 + +``` From 66fceec0beef9728c8bb8614f4b523927f815901 Mon Sep 17 00:00:00 2001 From: FvD Date: Sat, 10 Oct 2020 15:53:43 -0600 Subject: [PATCH 2/2] dos funciones --- intro_al_botfatheR.Rmd | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/intro_al_botfatheR.Rmd b/intro_al_botfatheR.Rmd index b3b4bee..47202a4 100644 --- a/intro_al_botfatheR.Rmd +++ b/intro_al_botfatheR.Rmd @@ -36,3 +36,34 @@ 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 + +``` + +