Struct telegram_bot::Api[][src]

pub struct Api { /* fields omitted */ }

Main type for sending requests to the Telegram bot API.

You can create an API object via from_token or from_env. A Listener object is obtained via listener. All remaining methods correspond directly to a telegram API call and are named like the API method, but in camel_case.

Methods

impl Api
[src]

Creates a new bot with the given token. If the token is completely invalid (resulting in an invalid API-URL), the function will return an Err value. However, the function will not check if the given token is a valid Telegram token. You can call get_me to execute a test request.

Will receive the bot token from the environment variable var and call from_token with it. Will return an Err value, if the environment var could not be read or the token has an invalid format.

Corresponds to the "getMe" method of the API.

Corresponds to the "sendMessage" method of the API.

Corresponds to the "forwardMessage" method of the API.

Corresponds to the "sendLocation" method of the API.

Corresponds to the "sendChatAction" method of the API.

Corresponds to the "getUserProfilePhotos" method of the API.

Corresponds to the "getUpdates" method of the API.

Note: The method will not set the offset parameter on its own. To receive updates in a more high level way, see listener.

Corresponds to the sendPhoto method of the API.

Corresponds to the sendAudio method of the API.

Corresponds to the sendVoice method of the API.

Corresponds to the sendDocument method of the API.

Corresponds to the sendSticker method of the API.

Corresponds to the sendVideo method of the API.

Corresponds to the setWebhook method of the API.

Note: This library does not yet offer the feature to listen via webhook. This is just the raw telegram API request and will do nothing more. Use only if you know what you're doing.

Receive and handle updates via "getUpdates".

This method will repeatedly call get_updates to receive new updates. It will then call the given handler for every update and increase the update offset accordingly, so the handler will never be called with the same update twice. The timeout parameter influences how long (in seconds) each poll may last. Defaults to 30. The handler gets a mutable reference to the bot since borrowing it from the outer scope won't work. When the handler returns an Err value the bot will stop listening for updates and long_poll will return the Error. If you want to stop listening you can just return Error::UserInterrupt.

Note: If the bot is restarted, but the last received updates are not yet confirmed (the last poll was not empty), there will be some duplicate updates.

Trait Implementations

impl Clone for Api
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Api

impl Sync for Api