telega/inline_mode
Builder for answering inline queries, in the spirit of keyboard.
Covers the most common InlineQueryResult variants (article, photo,
video, document, location); anything else can be added with result
using the raw types from telega/model/types.
fn handle_inline_query(ctx, query: types.InlineQuery) {
let #(page, next_offset) = inline_mode.paginate(items, offset: query.offset, page_size: 10)
let assert Ok(_) =
list.index_fold(page, inline_mode.new(), fn(builder, item, index) {
inline_mode.article(builder, id: int.to_string(index), title: item, text: item)
})
|> inline_mode.with_cache_time(300)
|> inline_mode.maybe_next_offset(next_offset)
|> inline_mode.answer(ctx, query.id)
Ok(ctx)
}
Types
Accumulates inline query results and answer options.
pub opaque type InlineQueryAnswer
Values
pub fn answer(
builder builder: InlineQueryAnswer,
ctx ctx: bot.Context(session, error, dependencies),
query_id query_id: String,
) -> Result(Bool, error.TelegaError)
Send the accumulated results as the answer to an inline query. No more than 50 results per query are allowed.
pub fn article(
builder builder: InlineQueryAnswer,
id id: String,
title title: String,
text text: String,
) -> InlineQueryAnswer
Add an article result: shows title in the result list, sends text when chosen.
pub fn article_described(
builder builder: InlineQueryAnswer,
id id: String,
title title: String,
text text: String,
description description: option.Option(String),
) -> InlineQueryAnswer
Same as article with a short description shown under the title.
pub fn document(
builder builder: InlineQueryAnswer,
id id: String,
title title: String,
url url: String,
mime_type mime_type: String,
) -> InlineQueryAnswer
Add a document result. mime_type must be "application/pdf" or "application/zip".
pub fn location(
builder builder: InlineQueryAnswer,
id id: String,
latitude latitude: Float,
longitude longitude: Float,
title title: String,
) -> InlineQueryAnswer
Add a location result.
pub fn maybe_next_offset(
builder builder: InlineQueryAnswer,
offset offset: option.Option(String),
) -> InlineQueryAnswer
Set the next offset when there are more pages — pairs with paginate.
pub fn paginate(
items items: List(a),
offset offset: String,
page_size page_size: Int,
) -> #(List(a), option.Option(String))
Slice items for the page requested by offset (the raw
InlineQuery.offset string, empty on the first query) and compute the
offset of the next page, None when this page is the last one.
pub fn personal(
builder builder: InlineQueryAnswer,
) -> InlineQueryAnswer
Cache results only for the user that sent the query.
pub fn photo(
builder builder: InlineQueryAnswer,
id id: String,
url url: String,
thumb thumbnail_url: String,
) -> InlineQueryAnswer
Add a photo result. url must point to a JPEG up to 5MB.
pub fn photo_captioned(
builder builder: InlineQueryAnswer,
id id: String,
url url: String,
thumb thumbnail_url: String,
caption caption: option.Option(String),
) -> InlineQueryAnswer
Same as photo with a caption sent along with the photo.
pub fn result(
builder builder: InlineQueryAnswer,
result result: types.InlineQueryResult,
) -> InlineQueryAnswer
Escape hatch: add any InlineQueryResult built from telega/model/types.
pub fn results(
builder builder: InlineQueryAnswer,
) -> List(types.InlineQueryResult)
Added results in the order they were added.
pub fn video(
builder builder: InlineQueryAnswer,
id id: String,
url url: String,
thumb thumbnail_url: String,
title title: String,
) -> InlineQueryAnswer
Add an MP4 video result. For embedded players (text/html) build
InlineQueryResultVideo manually and add it with result — Telegram
requires input_message_content for those.
pub fn with_button(
builder builder: InlineQueryAnswer,
button button: types.InlineQueryResultsButton,
) -> InlineQueryAnswer
Button shown above the inline results.
pub fn with_cache_time(
builder builder: InlineQueryAnswer,
seconds seconds: Int,
) -> InlineQueryAnswer
Maximum time in seconds the result may be cached on Telegram servers (default 300).
pub fn with_next_offset(
builder builder: InlineQueryAnswer,
offset offset: String,
) -> InlineQueryAnswer
Offset the client sends in the next query to fetch more results.