[−][src]Struct telexide::client::Client
The Client is the main object to manage your interaction with telegram.
It handles the incoming update objects from telegram and dispatches them to your event handlers and commands, providing those with access to shared data and easy access to the telegram API itself.
Event Handlers
Event handlers can be configured to be called upon every update that is received. (Later on support will be added for subscribing to more specific update events)
Note that you do not need to manually handle retrieving updates, as they are handled internally and then dispatched to your event handlers.
Examples
use telexide::prelude::*; #[prepare_listener] async fn event_listener(ctx: Context, update: Update) { println!("received an update!") } #[tokio::main] async fn main() -> telexide::Result<()> { let mut client = Client::new(token); client.subscribe_handler_func(event_listener); client.start().await }
Fields
api_client: Arc<Box<dyn API + Send>>
The API client, it contains all the methods to talk to the telegram api,
more documentation can be found over at the API
docs
data: Arc<RwLock<ShareMap>>
Your custom data that you want to be shared amongst event handlers and commands.
The purpose of the data field is to be accessible and persistent across contexts; that is, data can be modified by one context, and will persist through the future and be accessible through other contexts. This is useful for anything that should "live" through the program: counters, database connections, custom user caches, etc. Therefore this ShareMap requires all types it will contain to be Send + Sync.
When using a Context
, this data will be available as
Context::data
.
Refer to the repeat_image_bot example for an example on using the
data
field
allowed_updates: Vec<UpdateType>
The update types that you want to receive, see the documentation of
UpdateType
for more information
Methods
impl Client
[src]
pub fn new(token: String) -> Self
[src]
Creates a Client object with default values and no framework
pub fn with_framework(fr: Arc<Framework>, token: String) -> Self
[src]
Creates a Client object with default values, but with a Framework
pub async fn start<'_>(&'_ self) -> Result<()>
[src]
Starts the client and blocks until an error happens in the updates
stream or the program exits (for example due to a panic).
If using the framework, it will update your commands in telegram
This uses a default UpdatesStream
object
pub async fn start_with_stream<'_, '_>(
&'_ self,
stream: &'_ mut UpdatesStream
) -> Result<()>
[src]
&'_ self,
stream: &'_ mut UpdatesStream
) -> Result<()>
Starts the client and blocks until an error happens in the updates
stream or the program exits (for example due to a panic).
If using the framework, it will update your commands in telegram
You have to provide your own UpdatesStream
object
pub fn subscribe_handler_func(
&mut self,
handler: fn(_: Context, _: Update) -> Pin<Box<dyn Future<Output = ()> + Send>>
)
[src]
&mut self,
handler: fn(_: Context, _: Update) -> Pin<Box<dyn Future<Output = ()> + Send>>
)
Subscribes an update event handler function ([EventHandlerFunc
]) to
the client and will be ran whenever a new update is received
pub fn subscribe_raw_handler(
&mut self,
handler: fn(_: Context, _: RawUpdate) -> Pin<Box<dyn Future<Output = ()> + Send>>
)
[src]
&mut self,
handler: fn(_: Context, _: RawUpdate) -> Pin<Box<dyn Future<Output = ()> + Send>>
)
Subscribes a raw update event handler function ([RawEventHandlerFunc
]) to the client and will be ran
whenever a new update is received
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CloneAny for T where
T: Clone + Any,
[src]
T: Clone + Any,
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
[src]
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
[src]
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
[src]
T: Sync,
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Send + Sync> where
T: Send + Sync,
[src]
T: Send + Sync,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> UnsafeAny for T where
T: Any,
T: Any,