pub struct RtmClient { /* private fields */ }Expand description
The actual messaging client.
Implementations§
Source§impl RtmClient
impl RtmClient
Sourcepub fn login(token: &str) -> Result<RtmClient, Error>
pub fn login(token: &str) -> Result<RtmClient, Error>
Logs in to slack. Call this before calling run.
Alternatively use login_and_run.
Sourcepub fn run<T: EventHandler>(&self, handler: &mut T) -> Result<(), Error>
pub fn run<T: EventHandler>(&self, handler: &mut T) -> Result<(), Error>
Runs the message receive loop
Sourcepub fn login_and_run<T: EventHandler>(
token: &str,
handler: &mut T,
) -> Result<(), Error>
pub fn login_and_run<T: EventHandler>( token: &str, handler: &mut T, ) -> Result<(), Error>
Runs the main loop for the client after logging in to slack.
Returns an error if the process fails at any point, or an Ok(()) on successful close.
Takes an EventHandler implemented by the user which will be called when Events are
received.
Examples found in repository?
examples/slack_example.rs (line 74)
65fn main() {
66 let args: Vec<String> = std::env::args().collect();
67 let api_key = match args.len() {
68 0 | 1 => {
69 panic!("No api-key in args! Usage: cargo run --example slack_example -- <api-key>")
70 }
71 x => args[x - 1].clone(),
72 };
73 let mut handler = MyHandler;
74 let r = RtmClient::login_and_run(&api_key, &mut handler);
75 match r {
76 Ok(_) => {}
77 Err(err) => panic!("Error: {}", err),
78 }
79}Sourcepub fn sender(&self) -> &Sender
pub fn sender(&self) -> &Sender
Get a reference thread-safe cloneable message Sender
Examples found in repository?
examples/slack_example.rs (line 50)
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 start_response(&self) -> &StartResponse
pub fn start_response(&self) -> &StartResponse
Returns a reference to the StartResponse.
Examples found in repository?
examples/slack_example.rs (line 38)
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 }Auto Trait Implementations§
impl Freeze for RtmClient
impl RefUnwindSafe for RtmClient
impl Send for RtmClient
impl !Sync for RtmClient
impl Unpin for RtmClient
impl UnsafeUnpin for RtmClient
impl UnwindSafe for RtmClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more