-
-
Notifications
You must be signed in to change notification settings - Fork 36
Inline Actions
In Telegram there are some bots capable of performing what are known as "inline actions". An example of some built-in inline bots are @gif and @pic, but sending gifs is just one of many potential ways to use an inline bot. For instance, @VorpalRobot rolls dice for DnD, Pathfinder, and other tabletop games.
Inline queries are like any other event and can be listened for using the EventHandler and it's On annotation, or using the InlineQueryHandler and the OnInlineQuery annotation. The benefit to the latter is that it's specifically tuned to inline queries.
@[OnInlineQuery]
def on_inline_query(ctx : InlineQueryContext)
results = Tourmaline::QueryResultBuilder.new do |builder|
builder.article(
id: "query",
title: "Inline title",
input_message_content: Tourmaline::Model::InputTextMessageContent.new("Click!"),
description: "Your query: #{query.query}"
)
end
ctx.answer(results)
endThe result set can contain any InlineQueryResults. The input_message_content is what gets sent upon one of the items being clicked.
The OnInlineQuery annotation, and subsequently the InlineQueryHandler, can also be tuned to filter inline queries out by their id or query field, just by providing a parameter with the same name. For instance:
# This will filter out all inline queries that don't have an id of "test"
@[OnInlineQuery(id: "test")]
# This will filter out all inline queries that don't have a query field with "test"
@[OnInlineQuery(query: "test")]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