[−][src]Module tbot::methods
Structs for calling API methods.
The methods from this module are low-level: you have to pass everything
a method needs to their new
methods. More likely, you'd like to use
Bot
to infer your bot's token when calling methods. Moreover, when
handling updates, their contexts provide methods that infer even more
information from the update.
All the methods have a common pattern:
- Methods are constructed using their
new
method. This methods accepts required parameters for this method; - Methods provide the builder pattern for optional parameters;
- Methods implement the
IntoFuture
trait, so you need to turn a method into a future before actually calling the method.
For example, here's how to call SendMessage
:
use tbot::{ prelude::*, types::{chat, parameters::Text}, Token, }; const CHAT: chat::Id = chat::Id(0); const MESSAGE: &str = "`tbot` is a super-cool crate!"; let bot = tbot::bot!("BOT_TOKEN"); let request = bot.send_message(CHAT, Text::markdown(MESSAGE)) .into_future() .map_err(|err| { dbg!(err); }); tbot::run(request);
You may see that we use tbot::run
. It is a thin wrapper around
tokio::run
which doesn't require a Future::Item
to be ()
.
In addition, we also have tbot::spawn
with the same mitigations.
Inline/message methods
Several API methods accept either (chat_id
and message_id
) or
inline_message_id
, and their return type depends on the chosen
parameters. For such methods, tbot
provides two structs, e.g. for
editMessageText
there are EditMessageText
which resolves to
()
and EditInlineText
which resolves to types::Message
. This
brings a more straightforward API wrapper, unlike if we only had one method
which would resolve to (() | types::Message)
.