Struct Client

Source
pub struct Client {
    pub org_uuid: String,
    pub cookies: String,
}

Fields§

§org_uuid: String§cookies: String

Implementations§

Source§

impl Client

Source

pub async fn new(cookies: String) -> Self

Creates a new instance of the struct.

This function takes a cookies string as input, which is used to get the organization ID. If the organization ID cannot be retrieved (which may happen if the cookies are expired or invalid), an error message is logged and the process is terminated with exit code 1.

§Arguments
  • cookies - A string representing the cookies to be used for getting the organization ID.
§Returns
  • Self - An instance of the struct, with the cookies field set to the input cookies string, and the org_uuid field set to the retrieved organization ID.
§Errors

This function will exit the process if the organization ID cannot be retrieved.

§Examples
use claude::Client;
use std::env::var;
#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    tracing_subscriber::fmt::init();
    let cookies = format!(
        "activitySessionId={}; sessionKey={}",
        var("SESSION_ID").unwrap(),
        var("SESSION_KEY").unwrap()
    );
    let client = Client::new(cookies).await;
    tracing::info!("Client created, {:?}", client);
}
Source

pub async fn get_organization_id(cookies: String) -> Result<String>

Retrieves the organization ID from the API.

This function sends a GET request to the API and deserializes the response into a vector of Response structs. The uuid field of the first Response struct in the vector is then returned.

§Arguments
  • cookies - A string representing the cookies to be used for the request.
§Returns
  • Result<String> - The organization ID, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if the request fails or if the response cannot be deserialized.

Source

pub async fn create_new_chat(&self) -> Result<Conversation>

Creates a new chat conversation.

This function sends a POST request to the API to create a new chat conversation. The payload for the request includes a randomly generated UUID and an empty name.

§Returns
  • Result<Conversation> - The created chat conversation, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if the request fails or if the response cannot be deserialized.

§Examples
use claude::Client;
use std::env::var;
#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    tracing_subscriber::fmt::init();
    let cookies = format!(
        "activitySessionId={}; sessionKey={}",
        var("SESSION_ID").unwrap(),
        var("SESSION_KEY").unwrap()
    );
    let client = Client::new(cookies).await;
    let chat = client.create_new_chat().await.unwrap();
    tracing::info!("{:?}", chat);
}
Source

pub async fn list_all_conversations(&self) -> Result<Vec<Conversation>>

Lists all chat conversations.

This function sends a GET request to the API to retrieve all chat conversations for the organization.

§Returns
  • Result<Vec<Conversation>> - A vector of Conversation structs, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if the request fails or if the response cannot be deserialized.

§Examples
§Examples
use claude::Client;
use std::env::var;
#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    tracing_subscriber::fmt::init();
    let cookies = format!(
        "activitySessionId={}; sessionKey={}",
        var("SESSION_ID").unwrap(),
        var("SESSION_KEY").unwrap()
    );
    let client = Client::new(cookies).await;
    let chats = client.list_all_conversations().await.unwrap();
    tracing::info!("{:?}", chats);
}
Source

pub async fn chat_conversation_history( &self, chat_uuid: &str, ) -> Result<Vec<ChatMessage>>

Retrieves the history of a chat conversation.

This function sends a GET request to the API to retrieve the history of a chat conversation. The history is returned as a vector of ChatMessage structs.

§Arguments
  • chat_uuid - A string representing the UUID of the chat conversation.
§Returns
  • Result<Vec<ChatMessage>> - A vector of ChatMessage structs, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if the request fails or if the response cannot be deserialized.

§Examples
use claude::Client;
use std::env::var;
#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    tracing_subscriber::fmt::init();
    let cookies = format!(
        "activitySessionId={}; sessionKey={}",
        var("SESSION_ID").unwrap(),
        var("SESSION_KEY").unwrap()
    );
    let client = Client::new(cookies).await;
    let chat_hist = client.chat_conversation_history().await.unwrap();
    tracing::info!("{:?}", chat_hist);
}
Source

pub async fn delete_conversation(&self, chat_uuid: &str) -> Result<()>

Deletes a chat conversation.

This function sends a DELETE request to the API to delete a chat conversation.

§Arguments
  • chat_uuid - A string representing the UUID of the chat conversation to be deleted.
§Returns
  • Result<()> - An empty Result, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if the request fails.

§Examples
use claude::Client;
use std::env::var;
#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    tracing_subscriber::fmt::init();
    let cookies = format!(
        "activitySessionId={}; sessionKey={}",
        var("SESSION_ID").unwrap(),
        var("SESSION_KEY").unwrap()
    );
    let client = Client::new(cookies).await;
    let chat_hist = client.delete_conversation("chat_uuid_string").await.unwrap();
}
Source

pub async fn reset_all(&self) -> Result<()>

Resets all chat conversations.

This function retrieves all chat conversations and deletes each one.

§Returns
  • Result<()> - An empty Result, if all chat conversations are successfully deleted. Otherwise, an error.
§Errors

This function will return an error if the retrieval of chat conversations fails or if any chat conversation cannot be deleted.

Source

pub async fn upload_attachment(&self, file_path: &str) -> Result<Value>

Uploads an attachment to the API.

This function sends a POST request to the API to upload a document. The document is read from the file at the specified path and included in the request as a multipart form data. The MIME type of the document is determined based on its file extension.

§Arguments
  • file_path - A string representing the path to the file to be uploaded.
§Returns
  • Result<Value> - The API response, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if the file cannot be opened, if the request fails, or if the response cannot be deserialized.

Source

pub async fn send_message( &self, chat_uuid: &str, prompt: &str, attachments: Option<Vec<&str>>, timeout: Option<u64>, ) -> Result<String>

Sends a message to a chat conversation.

This function sends a POST request to the API to append a message to a chat conversation. The message can include attachments, which are uploaded to the API before the message is sent. The function waits for a response from the API for a specified amount of time before timing out.

§Arguments
  • chat_uuid - A string representing the UUID of the chat conversation.
  • prompt - A string representing the message to be sent.
  • attachments - An optional vector of strings representing the paths to the files to be uploaded as attachments.
  • timeout - An optional number representing the amount of time (in seconds) to wait for a response before timing out.
§Returns
  • Result<String> - The API response, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if an attachment cannot be uploaded, if the request fails, if the response cannot be deserialized, or if the request times out.

Source

pub async fn rename_chat(&self, chat_uuid: &str, title: &str) -> Result<()>

Renames a chat conversation.

This function sends a POST request to the API to rename a chat conversation.

§Arguments
  • chat_uuid - A string representing the UUID of the chat conversation to be renamed.
  • title - A string representing the new title for the chat conversation.
§Returns
  • Result<()> - An empty Result, if the request is successful. Otherwise, an error.
§Errors

This function will return an error if the request fails.

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,