atipugin / telegram-bot-ruby

Ruby wrapper for Telegram's Bot API
https://core.telegram.org/bots/api
Do What The F*ck You Want To Public License
1.35k stars 218 forks source link

how to save users response? #236

Closed lemondsun closed 1 year ago

lemondsun commented 3 years ago

I'm trying to save the user's response to my database. Right now I am able to save the chatId as it comes from the message but I haven't found a way to save the user's response.

` when '/set_price'

question = "Hello #{message.from.first_name}, tell me your price and I will alert you when the Gas price is at or below your target price."

@replyMessage = bot.api.send_message(chat_id: message.chat.id, text: question,  )['result']
@userResponse = bot.api.copy_message(chat_id: message.chat.id, from_chat_id: message.chat.id, message_id: 
@replyMessage["message_id"] )

get all chats saved in db

chats = Telebot.all

chats.each {
  |chat| if message.chat.id === chat.chatId
  @price = @userResponse
  i = chat
  i.update_attribute(:price, @price)
  i.save

end }

end`

Any help will be greatly appreciated.

anko20094 commented 2 years ago

what kind of message is it?