-
-
Notifications
You must be signed in to change notification settings - Fork 38
Listening for Events
Chris Watson edited this page Sep 9, 2019
·
5 revisions
Tourmaline provides event listeners which are fired every time one of several UpdateAction
's is fired.
Like commands, it's possible to annotate a method with an On
annotation to designate that method as an event listener.On
accepts any of the UpdateAction
's as an argument (although you can use symbols as well) and passes the full Update
to the method every time that action is fired.
As an example, let's listen for text messages and print them to the console:
@[On(:text)]
def text_listener(update)
if message = update.message
logger.debug("Text: #{message.text}")
end
end
As with commands you can also add event listeners without using an annotation.
bot.on(:text) do |update|
if message = update.message
bot.logger.debug("Text: #{message.text}")
end
end
Tourmaline (and many other projects) was written by watzon. It is free software, but if you feel so inclined you could sponsor its development on Patreon. Thank you for using my projects!
- Webhooks
- Inline Actions
- Reply Keyboards
- Games (coming soon)
- Stickers (coming soon)
- Payments