-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Desiders/add-support-bot-api-7.2
Add support Bot API 7.2
- Loading branch information
Showing
61 changed files
with
1,560 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "business_connection" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
telers = { path = "../../telers", features = ["default"] } | ||
tokio = { version = "1.36", features = ["macros"] } | ||
tracing = "0.1" | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//! This example shows how to receive updates from business connections. | ||
//! | ||
//! You can run this example by setting `BOT_TOKEN` and optional `RUST_LOG` environment variable and running: | ||
//! ```bash | ||
//! RUST_LOG={log_level} BOT_TOKEN={your_bot_token} cargo run --package business_connection | ||
//! ``` | ||
use telers::{ | ||
event::{telegram::HandlerResult, EventReturn, ToServiceProvider as _}, | ||
methods::SendMessage, | ||
types::{BusinessConnection, BusinessMessagesDeleted, Message}, | ||
Bot, Dispatcher, Router, | ||
}; | ||
use tracing::{event, Level}; | ||
use tracing_subscriber::{fmt, layer::SubscriberExt as _, util::SubscriberInitExt as _, EnvFilter}; | ||
|
||
async fn connection(business_connection: BusinessConnection) -> HandlerResult { | ||
event!( | ||
Level::DEBUG, | ||
?business_connection, | ||
"Received business connection", | ||
); | ||
|
||
Ok(EventReturn::Finish) | ||
} | ||
|
||
async fn message(bot: Bot, message: Message) -> HandlerResult { | ||
event!(Level::DEBUG, ?message, "Received message"); | ||
|
||
bot.send( | ||
SendMessage::new(message.chat().id(), "Hello world!") | ||
.business_connection_id(message.business_connection_id().unwrap()), | ||
) | ||
.await?; | ||
|
||
Ok(EventReturn::Finish) | ||
} | ||
|
||
async fn message_edited(message: Message) -> HandlerResult { | ||
event!(Level::DEBUG, ?message, "Received edited message"); | ||
|
||
Ok(EventReturn::Finish) | ||
} | ||
|
||
async fn messages_deleted(messages_deleted: BusinessMessagesDeleted) -> HandlerResult { | ||
event!(Level::DEBUG, ?messages_deleted, "Received deleted messages"); | ||
|
||
Ok(EventReturn::Finish) | ||
} | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
tracing_subscriber::registry() | ||
.with(fmt::layer()) | ||
.with(EnvFilter::from_env("RUST_LOG")) | ||
.init(); | ||
|
||
let token = std::env::var("BOT_TOKEN").expect("BOT_TOKEN env variable is not set!"); | ||
let bot = Bot::new(token); | ||
|
||
let mut router = Router::new("main"); | ||
router.business_connection.register(connection); | ||
router.business_message.register(message); | ||
router.edited_business_message.register(message_edited); | ||
router.deleted_business_messages.register(messages_deleted); | ||
|
||
let dispatcher = Dispatcher::builder() | ||
.allowed_updates(router.resolve_used_update_types()) | ||
.main_router(router) | ||
.bot(bot) | ||
.build(); | ||
|
||
match dispatcher | ||
.to_service_provider_default() | ||
.unwrap() | ||
.run_polling() | ||
.await | ||
{ | ||
Ok(()) => event!(Level::INFO, "Bot stopped"), | ||
Err(err) => event!(Level::ERROR, error = %err, "Bot stopped"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.