Skip to main content

Sender

Struct Sender 

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

Thread-safe API for sending messages asynchronously

Implementations§

Source§

impl Sender

Source

pub fn get_msg_uid(&self) -> usize

Get the next message id

A value returned from this method must be included in the JSON payload (the id field) when constructing your own message.

Source

pub fn send(&self, raw: &str) -> Result<(), Error>

Send a raw message

Must set message.id using result of get_msg_id().

Success from this API does not guarantee the message is delivered successfully since that runs on a separate task.

Source

pub fn send_message(&self, channel_id: &str, msg: &str) -> Result<usize, Error>

Send a message to the specified channel id

Success from this API does not guarantee the message is delivered successfully since that runs on a separate task.

channel_id is the slack channel id, e.g. UXYZ1234, not #general.

Only valid after RtmClient::run.

Examples found in repository?
examples/slack_example.rs (line 51)
33    fn on_event(&mut self, cli: &RtmClient, event: Event) {
34        println!("on_event(event: {:?})", event);
35        if let Event::Hello = event {
36            // find the general channel id from the `StartResponse`
37            let general_channel_id = cli
38                .start_response()
39                .channels
40                .as_ref()
41                .and_then(|channels| {
42                    channels.iter().find(|chan| match chan.name {
43                        None => false,
44                        Some(ref name) => name == "general",
45                    })
46                })
47                .and_then(|chan| chan.id.as_ref())
48                .expect("general channel not found");
49            let _ = cli
50                .sender()
51                .send_message(&general_channel_id, "Hello world! (rtm)");
52            // Send a message over the real time api websocket
53        }
54    }
Source

pub fn send_typing(&self, channel_id: &str) -> Result<usize, Error>

Marks connected client as being typing to a channel This is mostly used to signal to other peers that a message is being typed. Will have the server send a “user_typing” message to all the peers. Slack doc can be found at https://api.slack.com/rtm under “Typing Indicators”

channel_id is the slack channel id, e.g. UXYZ1234, not #general.

Source

pub fn subscribe_presence(&self, user_list: &[&str]) -> Result<usize, Error>

Subscribes to presence updates for the given users This is due to the update in presence events detailed here: https://api.slack.com/changelog/2017-10-making-rtm-presence-subscription-only

user_list is a slice of the list of users to subscrib, e.g. W839208, not @xyz. The full list of users to subscribe to must be sent each time the subscription should change Slack doc can be found at https://api.slack.com/docs/presence-and-status under “Determining user presence”

Source

pub fn shutdown(&self) -> Result<(), Error>

Shutdown RtmClient

Trait Implementations§

Source§

impl Clone for Sender

Source§

fn clone(&self) -> Sender

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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