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
impl DraftMessage
Sourcepub fn new(
text: impl Into<Cow<'static, str>>,
recipient: impl Into<UserID>,
) -> DraftMessage
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.
Sourcepub fn quick_reply_option(
self,
label: impl Into<String>,
metadata: impl Into<String>,
description: Option<String>,
) -> Self
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:
labelhas a maximum of 36 characters, including spaces.metadatahas a maximum of 1000 characters, including spaces.descriptionhas 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.
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.
Sourcepub fn attach_media(self, media_id: MediaId) -> Self
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.
Sourcepub async fn send(self, token: &Token) -> Result<Response<DirectMessage>, Error>
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.