Skip to main content

Response

Struct Response 

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

Unified bot response builder

Represents a response that can be sent back to any platform. Each platform adapter converts this to platform-specific format.

The builder methods (with_embed, ephemeral, with_caption, …) apply to whichever kind of response they make sense for. Calling a message builder on an empty response promotes it to a message rather than silently dropping the value, so Response::empty().with_embed(e) sends the embed.

Implementations§

Source§

impl Response

Source

pub fn empty() -> Self

Create an empty response (no reply)

Source

pub fn text(content: impl Into<String>) -> Self

Create a text response

Source

pub fn acknowledge() -> Self

Create an acknowledgement response (deferred)

Source

pub fn embed(embed: Embed) -> Self

Create a response with an embed

Source

pub fn file(file: File) -> Self

Create a file response from an open file handle

Source

pub fn bytes(bytes: impl Into<Vec<u8>>) -> Self

Create a file response from bytes already in memory

Source

pub fn path(path: impl Into<PathBuf>) -> Self

Create a file response that reads path when the response is sent

The filename defaults to the path’s final component.

Source

pub fn with_embed(self, embed: Embed) -> Self

Add an embed to this response

Source

pub fn with_components(self, components: Vec<Component>) -> Self

Add components (buttons, select menus) to this response

Source

pub fn ephemeral(self) -> Self

Make this response ephemeral (only visible to the user)

Platforms without ephemeral messages (Telegram, Matrix) ignore this.

Source

pub fn with_filename(self, name: impl Into<String>) -> Self

Set the filename for a file response

Source

pub fn with_caption(self, caption: impl Into<String>) -> Self

Set the caption for a file response

Source

pub fn is_empty(&self) -> bool

Check if this response carries nothing to send

Source

pub fn is_acknowledge(&self) -> bool

Check if this is an acknowledge response

Source

pub fn content(&self) -> Option<&str>

Get response content if this is a message response

Source

pub fn embeds(&self) -> &[Embed]

Get embeds if this is a message response

Source

pub fn components(&self) -> &[Component]

Get components if this is a message response

Source

pub fn is_ephemeral(&self) -> bool

Check if this response is ephemeral

Source

pub fn is_file(&self) -> bool

Check if this is a file response

Source

pub fn take_file(&mut self) -> Option<FileResponse>

Take the file response data, leaving an empty response in its place

This consumes the file data, so it can only be called once.

Trait Implementations§

Source§

impl Default for Response

Source§

fn default() -> Response

Returns the “default value” for a type. Read more
Source§

impl IntoResponse for Response

Source§

fn into_response(self) -> Response

Convert this type into a bot response

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> ChatActionSenderBounds for T
where T: Send + Sync + ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.