ebeneditos / telegram.bot

Develop a Telegram Bot with R
https://ebeneditos.github.io/telegram.bot/
GNU General Public License v3.0
107 stars 24 forks source link

MessageHadler - Help!!! #13

Closed lucasfreitas1988 closed 4 years ago

lucasfreitas1988 commented 4 years ago

Hello,

I want to include in my Telegram chatbot answers to specific questions, made by messages and not by commands. I believe I should use a MessageHandler, but I can't run these blocks of commands ... For example, I use this code and nothing works:

start_2 <- function (bot, update) {    bot$sendMessage (chat_id = "Are you ok?",                    text = sprintf ("Yeah, can I help you?")) }

start_handler_2 <- MessageHandler (start_2, MessageFilters$text) dispatcher $ add_handler (start_handler_2)

There is something wrong? I just want to make my bot respond to a specific message ... I don't want to use commands (with a / or _ for blanks within the sentence)

ebeneditos commented 4 years ago

Hi, in chat_id you should introduce a valid chat id. Something like this should work:

are_you_okay <- function(bot, update) {
  if (update$message$text == "Are you ok?") {
    bot$sendMessage(
      chat_id = update$message$chat$id,
      text = "Yeah, can I help you?"
    )
  }
}

Hope this helped!