DraftMessage

Struct DraftMessage 

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

Represents a direct message before it is sent.

Because there are several optional items you can add to a DM, this struct allows you to add or skip them using a builder-style struct, much like with DraftTweet.

To begin drafting a direct message, start by calling new with the message text and the User ID of the recipient:

use egg_mode::direct::DraftMessage;

let message = DraftMessage::new("hey, what's up?", recipient.id);

As-is, the draft won’t do anything until you call send to send it:

message.send(&token).await.unwrap();

In between creating the draft and sending it, you can use any of the other adapter functions to add other information to the message. See the documentation for those functions for details.

Implementations§

Source§

impl DraftMessage

Source

pub fn new( text: impl Into<Cow<'static, str>>, recipient: impl Into<UserID>, ) -> DraftMessage

Creates a new DraftMessage with the given text, to be sent to the given recipient.

Note that while this accepts a UserID, Twitter only accepts a numeric ID to denote the recipient. If you pass this function a string Screen Name, a separate user lookup will occur when you send this message. To avoid this extra lookup, use a numeric ID (or the UserID::ID variant of UserID) when creating a DraftMessage.

Source

pub fn quick_reply_option( self, label: impl Into<String>, metadata: impl Into<String>, description: Option<String>, ) -> Self

Adds an Option-type Quick Reply to this draft message.

Quick Replies allow you to request structured input from the other user. They’ll have the opportunity to select from the options you add to the message when you send it. If they select one of the given options, its metadata will be given in the response in the quick_reply_response field.

Note that while description is optional in this call, Twitter will not send the message if only some of the given Quick Replies have description fields.

The fields here have the following length restrictions:

  • label has a maximum of 36 characters, including spaces.
  • metadata has a maximum of 1000 characters, including spaces.
  • description has a maximum of 72 characters, including spaces.

There is a maximum of 20 Quick Reply Options on a single Direct Message. If you try to add more, the oldest one will be removed.

Users can only respond to Quick Replies in the Twitter Web Client, and Twitter for iOS/Android.

It is not possible to respond to a Quick Reply sent to yourself, though Twitter will register the options in the message it returns.

Source

pub fn cta_button( self, label: impl Into<String>, url: impl Into<String>, ) -> Self

Adds a “Call To Action” button to the message.

Buttons allow you to add up to three links to a message. These links act as an extension to the message rather than embedding the URLs into the message text itself. If a Web Intent link is used as the URL, they can also be used to bounce users back into the Twitter UI to perform some action.

The label has a length limit of 36 characters.

There is a maximum of 3 CTA Buttons on a single Direct Message. If you try to add more, the oldest one will be removed.

Source

pub fn attach_media(self, media_id: MediaId) -> Self

Add the given media to this message.

The MediaId needs to have been uploaded via media::upload_media_for_dm. Twitter requires DM-specific media categories for media that will be attached to Direct Messages. In addition, there’s an extra setting available for media attached to Direct Messages. For more information, see the documentation for upload_media_for_dm.

Source

pub async fn send(self, token: &Token) -> Result<Response<DirectMessage>, Error>

Sends this direct message using the given Token.

The recipient must allow DMs from the authenticated user for this to be successful. In practice, this means that the recipient must either follow the authenticated user, or they must have the “allow DMs from anyone” setting enabled. As the latter setting has no visibility on the API, there may be situations where you can’t verify the recipient’s ability to receive the requested DM beforehand.

If the message was successfully sent, this function will return the DirectMessage that was just sent.

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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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