R
R
room_it2020-10-07 03:26:54
ruby
room_it, 2020-10-07 03:26:54

Telegram Bot - undefined method when sending a message?

Hello!
I'm learning Ruby, trying to write a simple bot.

Essence: The user enters the package name of the application in Google Play, which is added to the array. Once every n seconds, the bot goes through the array and checks if the application has exited or is still being moderated. If the application has changed its status (for example, left the moderation), the bot should send a message.

There were difficulties writing the flow and sending the message. What am I doing wrong?
Here is the part of the code responsible for the bot: https://pastebin.com/y5mC9vY0

Attached is a screenshot:
5f7d0ad3395b5461387121.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DoubleJarvis, 2020-10-07
@room_it

On line 14 in the code

bot.send_message(chat_id: saved_chat_id, text: app_text)
you pass hash {chat_id:, text:}, the gem code calls the .text method on it and fails because the hash has no such method. The signature of the send_message method wants to see reply as an argument, which can be seen in the README:
# reply
message.reply do |reply|
reply.text = "homer please clean the garage"
reply.send_with(bot)
end
# or
reply = message.reply
reply.text = "i'll do it after going to moe's"
bot.send_message(reply)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question