pub struct Sender { /* private fields */ }Expand description
Thread-safe API for sending messages asynchronously
Implementations§
Source§impl Sender
impl Sender
Sourcepub fn get_msg_uid(&self) -> usize
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.
Sourcepub fn send(&self, raw: &str) -> Result<(), Error>
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.
Sourcepub fn send_message(&self, channel_id: &str, msg: &str) -> Result<usize, Error>
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?
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 }Sourcepub fn send_typing(&self, channel_id: &str) -> Result<usize, Error>
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.
Sourcepub fn subscribe_presence(&self, user_list: &[&str]) -> Result<usize, Error>
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”