Skip to content

Commit

Permalink
fix: forward reply message
Browse files Browse the repository at this point in the history
  • Loading branch information
AH-dark committed Apr 19, 2024
1 parent c1a38ef commit 3b0cc0e
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,40 @@ impl IForwardingMessageService for ForwardingMessageService {

let chat = update
.chat()
.ok_or_else(|| anyhow::anyhow!("Missing chat"))?;
.ok_or_else(|| anyhow::anyhow!("Missing chat"))?
.to_owned();

let message_id = match &update.kind {
UpdateKind::Message(m) => m.id,
_ => return Ok(()), // ignore non-message updates
};

let client = self.new_bot_client(&bot.bot_token)?;

let r = if chat.id.0 == bot.target_chat_id {
self.handle_target_chat_message(bot, update.clone()).await
self.handle_target_chat_message(bot, update).await
} else if chat.is_private() {
self.handle_forward_message(bot, update.clone()).await
self.handle_forward_message(bot, update).await
} else {
log::debug!("Ignoring message from chat {}", chat.id.0);
return Ok(());
};

match r {
Err(err) => {
log::error!("Error handling message: {}, chat_id: {}", err, chat.id.0);
client
.send_message(chat.id, format!("Error handling message: {}", err))
.reply_to_message_id(message_id)
.await?;
}
Ok(_) => {
log::debug!("Message handled successfully, chat_id: {}", chat.id.0);
client
.send_message(chat.id, "Message sent")
.reply_to_message_id(message_id)
.await?;
}
Ok(_) => {}
}

Ok(())
Expand Down

0 comments on commit 3b0cc0e

Please sign in to comment.