Skip to main content

MessageService

Struct MessageService 

Source
pub struct MessageService { /* private fields */ }
Expand description

消息服务

Implementations§

Source§

impl MessageService

Source

pub fn new(http: Arc<HttpClient>) -> Self

创建新的消息服务

Source

pub fn with_mqtt(http: Arc<HttpClient>, mqtt: Arc<RwLock<MqttClient>>) -> Self

使用 MQTT 客户端创建消息服务

Source

pub async fn get_conversation_messages( &self, conversation_id: &str, cursor: Option<&str>, limit: Option<i32>, ) -> SdkResult<MessagesResponse>

获取会话消息列表(需要认证)

§Arguments
  • conversation_id - 会话 ID
  • cursor - 分页游标(可选)
  • limit - 每页数量(可选,默认 20)
§Returns
  • MessagesResponse - 消息列表
Source

pub async fn send_message( &self, conversation_id: &str, content: &str, message_type: Option<&str>, reply_to_id: Option<&str>, data: Option<Value>, ) -> SdkResult<Message>

发送消息(需要认证)

§Arguments
  • conversation_id - 会话 ID
  • content - 消息内容
  • message_type - 消息类型(默认 “text”)
  • reply_to_id - 回复的消息 ID(可选)
  • data - 附加数据(可选)
§Returns
  • Message - 发送的消息
Source

pub async fn delete_message( &self, conversation_id: &str, message_id: &str, ) -> SdkResult<()>

删除消息(需要认证)

§Arguments
  • conversation_id - 会话 ID
  • message_id - 消息 ID
Source

pub async fn mark_message_as_read( &self, conversation_id: &str, message_id: &str, ) -> SdkResult<()>

标记消息为已读(需要认证)

§Arguments
  • conversation_id - 会话 ID
  • message_id - 消息 ID
Source

pub async fn trigger_sync(&self, conversation_id: Option<&str>) -> SdkResult<()>

触发消息历史同步(需要认证)

调用此接口后,服务端会通过 MQTT 推送消息历史数据

§Arguments
  • conversation_id - 会话 ID(可选,不提供则同步所有会话)
Source

pub async fn publish_message( &self, conversation_id: &str, payload: &[u8], ) -> SdkResult<()>

通过 MQTT 发送消息(需要 MQTT 连接)

§Arguments
  • conversation_id - 会话 ID
  • payload - 消息 payload

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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