-
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.
- Loading branch information
1 parent
22961df
commit 49c6424
Showing
9 changed files
with
166 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
[package] | ||
name = "telegram-tracker" | ||
version = "0.1.4" | ||
version = "0.1.5" | ||
authors = ["Felix <felix.g.borrego@gmail.com>"] | ||
readme = "README.md" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
telegram-client = "1.6.3" | ||
rtdlib = { version = "=1.6.5", features = [ "sys" ] } | ||
|
||
telegram-client = { version="1.7.0"} | ||
rtdlib = { version = "=1.7.0", features = [ "sys" ] } | ||
log = "0.4" | ||
simple_logger = "1.3" | ||
toolkit = "0.1" | ||
colored = "1.9" | ||
regex = "1" | ||
clap = "3.0.0-beta.2" | ||
chrono = "0.4" | ||
futures = "0.3" |
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,40 @@ | ||
use std::io::{self, BufRead}; | ||
|
||
use futures::executor::block_on; | ||
use log::info; | ||
use rtdlib::types::*; | ||
//use rtdlib::*; | ||
use telegram_client::api::aasync::AsyncApi; | ||
use telegram_client::api::Api; | ||
|
||
const TELEGRAM_START_MSG: &str = "TELEGRAM BOT<<<"; | ||
/// Read stdin and forward to channel | ||
pub fn forward_stdin_to_channel_id(api: Api, chat_id: i64) { | ||
info!("Listening stdin to forward to channel... {}", chat_id); | ||
let api = AsyncApi::new(api); | ||
let stdin = io::stdin(); | ||
|
||
for line in stdin.lock().lines() { | ||
let msg_to_send = line.unwrap().trim().to_owned(); | ||
if msg_to_send.starts_with(TELEGRAM_START_MSG) { | ||
let msg_to_send = msg_to_send.replace(TELEGRAM_START_MSG, ""); | ||
let result = block_on(send_msg(&api, chat_id, msg_to_send)); | ||
} | ||
} | ||
} | ||
|
||
async fn send_msg(api: &AsyncApi, chat_id: i64, msg_to_send: String) { | ||
let msg_content = InputMessageContent::InputMessageText( | ||
InputMessageText::builder() | ||
.text(FormattedText::builder().text(msg_to_send).build()) | ||
.clear_draft(true) | ||
.build(), | ||
); | ||
|
||
let msg: SendMessage = SendMessage::builder() | ||
.chat_id(chat_id) | ||
.input_message_content(msg_content) | ||
.build(); | ||
|
||
api.send_message(msg).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
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.