This repository has been archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send Telegram messages in a separate task
- Loading branch information
Showing
6 changed files
with
66 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::{redis_client, BotType}; | ||
use log::*; | ||
use redis::AsyncCommands; | ||
use teloxide::prelude::*; | ||
use tokio::sync::mpsc::Receiver; | ||
|
||
#[derive(Debug)] | ||
pub struct Message { | ||
index_id: i64, | ||
user_ids: Vec<i64>, | ||
text: String, | ||
} | ||
|
||
impl Message { | ||
pub fn new(index_id: i64, user_ids: Vec<i64>, text: String) -> Self { | ||
Self { | ||
index_id, | ||
user_ids, | ||
text, | ||
} | ||
} | ||
} | ||
|
||
pub async fn handle_messages(mut rx: Receiver<Message>, bot: BotType) { | ||
let mut conn = redis_client().await.get_async_connection().await.unwrap(); | ||
|
||
while let Some(msg) = rx.recv().await { | ||
for user_id in msg.user_ids { | ||
match bot.send_message(user_id, &msg.text).await { | ||
Ok(_) => debug!("Message sent to Telegram ID={}", user_id), | ||
Err(err) => error!("{}", err), | ||
} | ||
} | ||
let _: () = conn.set("ati:latest", msg.index_id).await.unwrap(); | ||
} | ||
} |
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