tg-rs / carapax

A Telegram Bot API framework
MIT License
113 stars 12 forks source link

how to send simple msg? #41

Closed pictca closed 4 years ago

pictca commented 4 years ago

I tried to send message in main local thread not in handler function but it's occurred error panic.

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err`
...
thread::spawn(move || {
... // logic stuff
   api_.spawn(api_.execute(SendMessage::new(chat_id, "OK")).then(|r| {
       if let Err(e) = r {
           error!("An error as occured: {:?}", e);
      }
      //Ok(HandlerResult::Continue)
       Ok::<(), ()>(())
     }));
... // logic stuff
});

it's not even go show some error in closure function. How i will solve this? :neutral_face:

pictca commented 4 years ago

I find it! use tokio

thread::spawn(move || {
... // logic stuff
   tokio::run(api_.execute(SendMessage::new(chat_id, "OK")).then(|r| {
       if let Err(e) = r {
           error!("An error as occured: {:?}", e);
      }
      //Ok(HandlerResult::Continue)
       Ok::<(), ()>(())
     }));
... // logic stuff
});