Async Requests¶
Put await in front of an Api call when the next line needs what Telegram sent back.
Execution pauses at the await, the request completes, and me holds the response. Then the command continues.
What you get back¶
Responses follow Telegram's shape: typically ok (boolean) and result (the useful payload). Failed calls set ok to false — check it when the failure would change your logic.
let sent = await Api.sendMessage({ text: "Hello again." })
if (!sent.ok) {
// user blocked the bot, chat gone, etc.
}
Without that check, the failure only appears in your platform error logs. The command keeps running as if nothing went wrong.
Message sends return something useful¶
When you await Api.sendMessage, the return value is also a chainable object — edit, delete, pin the message you just created. See Method Chaining.
Don't await everything¶
If you fire a message and don't care about the response, skip await:
Extra awaits add wait time without benefit.
Works with dynamic calls too¶
Same rules — check ok, read result.
See also¶
- Callbacks — defer handling to another command with
on_run - Tips and Limitations — TBL errors vs Telegram errors