I would create a telegram bot in ruby that send a message in a determinate hour i decide. For example. It's 8 am and the bot send a message "Good morning". Of course every morning at the same time. It could be a kind of reminder. I can get the time in this way:
time = Time.now.strftime("%H:%M")
And i know that to send a message i can use the Telegram API like:
bot.api.send_message(chat_id: message.chat.id, text: "Hi")
I use this code when i have an interaction between the bot and a user. For example:
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message.text
when "hi", 'hi@myBot'
bot.api.send_message(chat_id: message.chat.id, text: "Hi, #{message.from.first_name}")
end
....
....
but I don't know how do what i need because if i want to send a message i need the chat.id and in this case i get it only when i have an interaction with a user. So, is it possibile send a message for example when it's 8 am without any user interaction?
Use crono gem to perform asynchronous tasks.
Crono.perform(YourJob).every 1.day, at: {hour: 8, min: 00}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With