Struct slack::RtmClient
[−]
[src]
pub struct RtmClient { // some fields omitted }
The actual messaging client.
Methods
impl RtmClient
[src]
fn new(token: &str) -> RtmClient
Creates a new client from a token
fn get_name(&self) -> Option<String>
Returns the name of the bot/user connected to the client. Only valid after login, otherwise None.
fn get_id(&self) -> Option<String>
Returns the id of the bot/user connected to the client. Only valid after login, otherwise None.
fn get_team(&self) -> Option<Team>
Returns the Team struct of the bot/user connected to the client. / Only valid after login, otherwise None.
fn get_user_id(&self, username: &str) -> Option<&String>
Get a user id from a username Only valid after login.
fn get_channel_id(&self, channel_name: &str) -> Option<&String>
Get a channel id from a channel name, note that channel_name does not begin with a '#' Only valid after login.
fn get_group_id(&self, group_name: &str) -> Option<&String>
Get a group id from a group name Only valid after login.
fn get_users(&self) -> Vec<User>
Returns a vector of Users from the team the bot/client is connected to. Only valid after login.
fn get_channels(&self) -> Vec<Channel>
Returns a vector of Channels from the team the bot/client is connected to. Only valid after login.
fn get_groups(&self) -> Vec<Group>
Returns a vector of Groups from the team the bot/client is connected to. Only valid after login.
fn get_start_ims(&self) -> Option<Vec<Im>>
Returns a vector of Ims received on login the bot/client is connected to. Only valid after login, otherwise None.
fn get_msg_uid(&self) -> isize
Returns a unique identifier to be used in the 'id' field of a message sent to slack.
fn send(&mut self, s: &str) -> Result<(), Error>
Allows sending a json string message over the websocket connection. Note that this only passes the message over a channel to the Messaging task, and therfore a succesful return value does not mean the message has been actually put on the wire yet. Note that you will need to form a valid json reply yourself if you use this method, and you will also need to retrieve a unique id for the message via RtmClient.get_msg_uid() Only valid after login.
fn send_message(&self, chan: &str, msg: &str) -> Result<isize, Error>
Allows sending a textual string message over the websocket connection, to the requested channel id. Ideal usage would be EG: extract the channel in on_receive and then send back a message to the channel. Note that this only passes the message over a channel to the Messaging task, and therfore a succesful return value does not mean the message has been actually put on the wire yet. This method also handles getting a unique id and formatting the actual json sent. Only valid after login.
fn login(&mut self) -> Result<(WsClient, Receiver<WsMessage>), Error>
Logs in to slack. Call this before calling run. Alternatively use login_and_run
fn run<T: EventHandler>(&mut self, handler: &mut T, client: WsClient, rx: Receiver<WsMessage>) -> Result<(), Error>
Runs the message receive loop
fn login_and_run<T: EventHandler>(&mut self, 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 an point, or an Ok(()) on succesful close. Takes a EventHandler (implemented by the user) to call events handlers on. once the first on_receive() or on_ping is called on the EventHandler, you can soon the 'Only valid after login' methods are safe to use. Sending is run in a thread in parallel while the receive loop runs on the main thread. Both loops should end on return. Sending should be thread safe as the messages are passed in via a channel in RtmClient.send and RtmClient.send_message
fn list_users(&mut self) -> Result<Vec<User>, Error>
Uses https://api.slack.com/methods/users.list to get a list of users
fn list_channels(&mut self) -> Result<Vec<Channel>, Error>
Uses https://api.slack.com/methods/channels.list to get a list of channels
fn list_groups(&mut self) -> Result<Vec<Group>, Error>
Uses https://api.slack.com/methods/groups.list to get a list of groups
fn update_users(&mut self) -> Result<Vec<User>, Error>
Uses https://api.slack.com/methods/users.list to update users
fn update_channels(&mut self) -> Result<Vec<Channel>, Error>
Uses https://api.slack.com/methods/channels.list to update channels
fn update_groups(&mut self) -> Result<Vec<Group>, Error>
Uses https://api.slack.com/methods/groups.list to update groups
fn post_message(&self, channel: &str, json_payload: &str, attachments: Option<&str>) -> Result<PostMessageResponse, Error>
Wraps https://api.slack.com/methods/chat.postMessage json_payload can be a json formatted action or simple text that will be posted as a message. See https://api.slack.com/docs/formatting
fn delete_message(&self, channel: &str, timestamp: &str) -> Result<DeleteResponse, Error>
Wraps https://api.slack.com/methods/chat.delete to delete a message See the slack api docs for timestamp formatting.
fn mark(&self, channel: &str, timestamp: &str) -> Result<MarkResponse, Error>
Wraps https://api.slack.com/methods/channels.mark to set the read cursor in a channel See the slack api docs for timestamp formatting.
fn set_topic(&self, channel: &str, topic: &str) -> Result<SetTopicResponse, Error>
Wraps https://api.slack.com/methods/channels.setTopic if channel starts with a # then it will be looked up with get_channel_id topic will be json escaped.
fn set_purpose(&self, channel: &str, purpose: &str) -> Result<SetPurposeResponse, Error>
Wraps https://api.slack.com/methods/channels.setPurpose if channel starts with a # then it will be looked up with get_channel_id purpose will be json escaped.
fn add_reaction_timestamp(&self, emoji_name: &str, channel: &str, timestamp: &str) -> Result<AddResponse, Error>
Wraps https://api.slack.com/methods/reactions.add to add an emoji reaction to a message if channel starts with a # then it will be looked up with get_channel_id
fn add_reaction_file(&self, emoji_name: &str, file: &str) -> Result<AddResponse, Error>
Wraps https://api.slack.com/methods/reactions.add to add an emoji reaction to a file
fn add_reaction_file_comment(&self, emoji_name: &str, file_comment: &str) -> Result<AddResponse, Error>
Wraps https://api.slack.com/methods/reactions.add to add an emoji reaction to a file comment
fn update_message(&self, channel: &str, timestamp: &str, json_payload: &str, attachments: Option<&str>) -> Result<UpdateResponse, Error>
Wraps https://api.slack.com/methods/chat.update json_payload can be a json formatted action or simple text that will be posted as a message. See https://api.slack.com/docs/formatting
fn im_open(&self, user_id: &str) -> Result<OpenResponse, Error>
Wraps https://api.slack.com/methods/im.open to open a direct message channel with a user.
fn channels_history(&self, channel_id: &str, latest: Option<&str>, oldest: Option<&str>, inclusive: Option<bool>, count: Option<u32>) -> Result<HistoryResponse, Error>
Wraps https://api.slack.com/methods/channels.history to retrieve the history of messages and events from a channel.
fn im_close(&self, channel_id: &str) -> Result<CloseResponse, Error>
Wraps https://api.slack.com/methods/im.close to close a direct message channel.
fn im_history(&self, channel_id: &str, latest: Option<&str>, oldest: Option<&str>, inclusive: Option<bool>, count: Option<u32>) -> Result<HistoryResponse, Error>
Wraps https://api.slack.com/methods/im.history to retrieve the history of messages and events from a direct message channel.
fn im_list(&self) -> Result<ListResponse, Error>
Wraps https://api.slack.com/methods/im.list to get the list of all open direct message channels the user has open.
fn im_mark(&self, channel_id: &str, timestamp: &str) -> Result<MarkResponse, Error>
Wraps https://api.slack.com/methods/im.mark to move the read cursor in a direct message channel.