Skip to main content

RtmClient

Struct RtmClient 

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

The actual messaging client.

Implementations§

Source§

impl RtmClient

Source

pub fn login(token: &str) -> Result<RtmClient, Error>

Logs in to slack. Call this before calling run. Alternatively use login_and_run.

Source

pub fn run<T: EventHandler>(&self, handler: &mut T) -> Result<(), Error>

Runs the message receive loop

Source

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}
Source

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    }
Source

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§

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> 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