telegram-rs/telegram-bot

How to create SendMessage with chat_id and send it?

dimparf opened this issue · 2 comments

I want to send a message from an external system (without api.stream())
Something like this:

let message = SendMessage::new(ChatId(233), "Text message");
telegram_api.send(message);

What was the answer?

let token = std::env::var("TELEGRAM_BOT_TOKEN").unwrap();
  let chat_id = std::env::var("TELEGRAM_CHAT_ID").unwrap();
  let api = telegram_bot::Api::new(token);
  let chat_id = chat_id.parse::<i64>().unwrap();
  let chat = telegram_bot::ChatId::from(chat_id);
  let text = String::from("Hello, world!");
  let request = telegram_bot::types::requests::send_message::SendMessage::new(chat, text);
  api.send(request).await.unwrap();

Probably something like this?