client: implements send_message
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user