Private
Public Access
1
0

client: implements send_message

This commit is contained in:
2025-05-02 12:03:56 -07:00
parent 2106bce755
commit 07b55f8615
6 changed files with 133 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ use anyhow::Result;
use clap::Subcommand;
use crate::printers::{ConversationPrinter, MessagePrinter};
use kordophone::model::event::Event;
use kordophone::model::outgoing_message::OutgoingMessage;
use futures_util::StreamExt;
@@ -47,6 +48,12 @@ pub enum Commands {
/// Prints all raw updates from the server.
RawUpdates,
/// Sends a message to the server.
SendMessage {
conversation_id: String,
message: String,
},
}
impl Commands {
@@ -58,6 +65,7 @@ impl Commands {
Commands::Messages { conversation_id } => client.print_messages(conversation_id).await,
Commands::RawUpdates => client.print_raw_updates().await,
Commands::Events => client.print_events().await,
Commands::SendMessage { conversation_id, message } => client.send_message(conversation_id, message).await,
}
}
}
@@ -123,6 +131,17 @@ impl ClientCli {
Ok(())
}
pub async fn send_message(&mut self, conversation_id: String, message: String) -> Result<()> {
let outgoing_message = OutgoingMessage::builder()
.conversation_id(conversation_id)
.text(message)
.build();
let message = self.api.send_message(outgoing_message).await?;
println!("Message sent: {}", message.guid);
Ok(())
}
}