telbot_types/
lib.rs

1use std::collections::HashMap;
2
3use file::InputFile;
4use serde::de::DeserializeOwned;
5use serde::{Deserialize, Serialize};
6
7pub mod bot;
8pub mod chat;
9pub mod file;
10pub mod markup;
11pub mod message;
12pub mod payment;
13pub mod query;
14pub mod sticker;
15pub mod update;
16pub mod user;
17pub mod webhook;
18
19pub trait TelegramMethod {
20    type Response: DeserializeOwned;
21    fn name() -> &'static str;
22}
23
24/// Methods that should be sent in JSON format
25pub trait JsonMethod: TelegramMethod + Serialize {}
26
27/// Methods that should be sent in multipart or JSON format
28pub trait FileMethod: TelegramMethod + Serialize {
29    fn files(&self) -> Option<HashMap<&str, &InputFile>>;
30}
31
32/// Api response
33#[derive(Debug, Deserialize)]
34#[serde(untagged)]
35pub enum ApiResponse<T: DeserializeOwned> {
36    Ok {
37        #[serde(bound(deserialize = "T: DeserializeOwned"))]
38        result: T,
39    },
40    Err(TelegramError),
41}
42
43#[derive(Debug, Deserialize)]
44pub struct TelegramError {
45    pub description: String,
46}