0

Hello i have some issues with my telegram bot, developed in ruby with 'telegrammer' client.

1)

  when '/lottery'
    question = 'choose a number:'
    answers =
      Telegram::Bot::Types::ReplyKeyboardMarkup.new(
      keyboard: [
        ["1", "2", "3"],
        ["4", "5", "6"],
        ["7", "8", "9"],
        [" ", "0", " "]
      ],

      one_time_keyboard: true
      )

    bot.api.sendMessage(chat_id: message.chat.id, text: question, reply_markup: answers)

How can i interact with the answer of the user? Like

if answers == "1"
    bot.api.sendMessage(chat_id: message.chat.id, text: "You have selected 1", reply_markup: answers)
end

2) How can i read a command like

/*** @user1

and then the bot will says

@user1 the @user tell you ***

Thank you so much in advance...

3
  • Did you find a solution for this?
    – Emjey
    Feb 22, 2017 at 17:22
  • I don't remember, but I think not, I stopped working on telegrams bot, sorry Feb 22, 2017 at 17:54
  • 1
    Alright! No problemo! For the time being I could do a work around by predefining the commands in the inline keyboard, that lets user automatically select it.
    – Emjey
    Feb 22, 2017 at 17:58

1 Answer 1

1

1.
When a user clicks something on the keyboard, there is no special command sent. It doesn't matter if if a user clicks "1" on the keyboard are just sends a message with "1" to your bot (assuming the bot receives that message). So you will just receive the standard data like

"message" : {
    "text" : "1"
    #...
}

So you will probably have a code that looks about this

#If message text equals '1'
when '1'
    #Do something

2.
I don't know how the 'telegrammer' client works, but it's probably the best if your first check if the message text matches a certain regex. If the text does match, then you only need to split the message text to get the parts you want so you can build your reply.

1
  • However, When '1' acts like a command and not like user input for a particular command! I am thinking should I use def () and call this def when the user types that specific command?
    – Emjey
    Feb 22, 2017 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.