You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I'm trying to create a function that will send a message to users when receiving data from a web form. I am interested in whether it is possible to pass a bot to a function without an argument.
If the bot is passed as an argument to async fn test_message_data, then it (the bot) must be specified in the arguments in async fn post.
async fn post works with the Rocket crate and cannot accept teloxide. How to implement the bot transfer?
//from the code for interacting with the web form
#[post("/message", data = "<form>")]
async fn post(form: Form<Message>, queue: &State<Sender<Message>>) {
let message_web_face = form.into_inner();
let message_time = message_web_face.time;
let message_location = message_web_face.message;
let parsed_data = NaiveDate::parse_from_str(&*message_web_face.data, "%Y-%m-%d");
match parsed_data {
Ok(data) => {
let game_day = parsed_data.expect("REASON").format("%d.%m.%Y");
test_message_data(
message_day.to_string(),
message_time.to_string(),
message_location.to_string(),
)
.await
.unwrap();
println!("{}", message_day);
println!("{}", message_time);
println!("{}", message_location);
}
Err(err) => {
// Обработка ошибки парсинга даты
println!("Failed to parse date {}", err);
}
}
}
//from the telegram bot code
pub async fn run_bot() {
let token = token::TELEGRAM_TOKEN;
let bot = Bot::new(token);
Dispatcher::builder(bot, schema())
.dependencies(dptree::deps![InMemStorage::<State>::new()])
.enable_ctrlc_handler()
.build()
.dispatch()
.await;
}
/* different functions of the bot */
async fn test_message_data(
message_day: String,
message_time: String,
message_location: String
) {
bot.send_message(
msg.chat.id,
"{message_day} {message_time} {message_location}").await?;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi! I'm trying to create a function that will send a message to users when receiving data from a web form. I am interested in whether it is possible to pass a bot to a function without an argument.
If the bot is passed as an argument to async fn test_message_data, then it (the bot) must be specified in the arguments in async fn post.
async fn post works with the Rocket crate and cannot accept teloxide. How to implement the bot transfer?
Beta Was this translation helpful? Give feedback.
All reactions