-
-
Notifications
You must be signed in to change notification settings - Fork 38
Listening for Events
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 in an EventContext
every time that update is seen.
As an example, let's listen for text messages and print them to the console:
@[On(:text)]
def text_listener(ctx : EventHandler)
if message = ctx.message
logger.debug("Text: #{message.text}")
end
end
As with the Command
annotation, the On
annotation also has a handler counterpart in the EventHandler
, which works in much the same way.
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