Skip to main content

SlackClient

Struct SlackClient 

Source
pub struct SlackClient {
    http: Client,
    token: String,
}
Expand description

Debug is hand-written because the token must never be printed.

Fields§

§http: Client§token: String

Implementations§

Source§

impl SlackClient

Source

pub fn new(http: Client, token: String) -> Self

Source

pub async fn call<T: DeserializeOwned>( &self, method: &str, params: &[(&str, String)], ) -> Result<T, SlackError>

POST one Web API method. Slack is uniform here, so one helper covers every call the connector makes.

Source

async fn call_text( &self, method: &str, params: &[(&str, String)], ) -> Result<String, SlackError>

POST one Web API method and hand back the body undecoded, for the callers whose decode needs the raw text rather than one envelope.

Source

pub async fn auth_test(&self) -> Result<AuthTest, SlackError>

Who this token belongs to. The first thing to prove on a new workspace.

Source

pub async fn history( &self, channel: &str, oldest: Option<&str>, newest: Option<&str>, limit: u32, cursor: Option<&str>, ) -> Result<MessagePage, SlackError>

One page of a conversation’s history. Each bound is omitted entirely when absent: Slack treats an empty oldest differently from an absent one.

Source

pub async fn replies( &self, channel: &str, ts: &str, oldest: Option<&str>, limit: u32, cursor: Option<&str>, ) -> Result<MessagePage, SlackError>

One page of a thread’s replies. Slack repeats the parent on every page, so the caller dedupes by ts.

Source

pub async fn post_message( &self, channel: &str, text: &str, thread_ts: Option<&str>, ) -> Result<PostedMessage, SlackError>

Post one message, as a root or into an existing thread. Returns the posted message’s ts.

Source

pub async fn update_message( &self, channel: &str, ts: &str, text: &str, ) -> Result<(), SlackError>

Replace the text of one of the user’s own messages. Slack drops existing blocks when text is sent without them, which is what this connector wants: one text body, no stale block.

Source

pub async fn delete_message( &self, channel: &str, ts: &str, ) -> Result<(), SlackError>

Delete one of the user’s own messages.

Source

pub async fn set_reaction( &self, channel: &str, ts: &str, name: &str, add: bool, ) -> Result<(), SlackError>

Add or remove one reaction. reactions.remove requires being the original reaction’s author.

Source

pub async fn get_bytes(&self, url: &str) -> Result<Vec<u8>, SlackError>

GET an absolute URL with the bearer attached. Slack’s private file URLs answer 403 without it, and byte-identically with it.

Source

pub async fn post_bytes( &self, url: &str, body: Vec<u8>, ) -> Result<(), SlackError>

POST raw bytes to an absolute URL. Deliberately no bearer: the upload URL is pre-signed, and it is not the Web API host.

Source

pub async fn file_info(&self, id: &str) -> Result<SlackFile, SlackError>

files.info for one file id.

Source

pub async fn get_upload_url( &self, name: &str, length: usize, ) -> Result<(String, String), SlackError>

files.getUploadURLExternal: the pre-signed URL to POST the bytes to, plus the file id the completion call needs.

Source

pub async fn complete_upload( &self, file_id: &str, channel: &str, thread_ts: Option<&str>, ) -> Result<Vec<SlackFile>, SlackError>

files.completeUploadExternal. It can be called once only, and the file is discarded if it never is.

Source

pub async fn search_messages( &self, query: &str, count: u32, cursor: Option<&str>, ) -> Result<SearchPage, SlackError>

search.messages. Matches text; it cannot find every message that mentions a user, which is what the mention subscription is for.

Source

pub async fn user_info(&self, user: &str) -> Result<SlackUser, SlackError>

users.info for one user id.

Source

pub async fn list_users(&self) -> Result<Vec<SlackUser>, SlackError>

Every member in the workspace, following the cursor. Slack has no server-side name search, so a resolver reads the directory and matches locally.

Source

pub async fn pins(&self, channel: &str) -> Result<Vec<SlackPin>, SlackError>

pins.list for one conversation.

Source

pub async fn bookmarks( &self, channel: &str, ) -> Result<Vec<SlackBookmark>, SlackError>

bookmarks.list for one conversation. The param is channel_id here against channel on pins.list.

Source

pub async fn list_conversations( &self, ) -> Result<Vec<SlackConversation>, SlackError>

Every conversation the token’s user is a member of, paging to the end.

Trait Implementations§

Source§

impl Debug for SlackClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SlackApi for SlackClient

Source§

fn auth_test<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AuthTest, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Who the token belongs to; the boot probe’s only call.
Source§

fn list_conversations<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<SlackConversation>, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn history<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, channel: &'life1 str, oldest: Option<&'life2 str>, newest: Option<&'life3 str>, limit: u32, cursor: Option<&'life4 str>, ) -> Pin<Box<dyn Future<Output = Result<MessagePage, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Source§

fn replies<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, channel: &'life1 str, ts: &'life2 str, oldest: Option<&'life3 str>, limit: u32, cursor: Option<&'life4 str>, ) -> Pin<Box<dyn Future<Output = Result<MessagePage, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Source§

fn post_message<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, channel: &'life1 str, text: &'life2 str, thread_ts: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = Result<PostedMessage, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Post one message, as a root or into an existing thread. Returns the posted message’s ts, the handle a reply, an edit, a delete and a reaction all take, and the channel it landed in - a request can address a user id or a channel name instead of the conversation id.
Source§

fn update_message<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, channel: &'life1 str, ts: &'life2 str, text: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<(), SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Replace the text of one of the authenticated user’s own messages.
Source§

fn delete_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, channel: &'life1 str, ts: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete one of the authenticated user’s own messages.
Source§

fn set_reaction<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, channel: &'life1 str, ts: &'life2 str, name: &'life3 str, add: bool, ) -> Pin<Box<dyn Future<Output = Result<(), SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Add or remove one reaction on a message.
Source§

fn get_bytes<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

GET an absolute URL with the bearer attached, for a private file.
Source§

fn post_bytes<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 str, body: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<(), SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

POST raw bytes to an absolute pre-signed URL, with no bearer.
Source§

fn file_info<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<SlackFile, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

files.info for one file id.
Source§

fn get_upload_url<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, length: usize, ) -> Pin<Box<dyn Future<Output = Result<(String, String), SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

files.getUploadURLExternal: the pre-signed URL to POST the bytes to, plus the file id the completion call needs.
Source§

fn complete_upload<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, file_id: &'life1 str, channel: &'life2 str, thread_ts: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<SlackFile>, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

files.completeUploadExternal, which can be called once only. Returns the files it reports: when Slack fills their shares, that already names the message the upload was posted as.
Source§

fn search_messages<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, count: u32, cursor: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<SearchPage, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

search.messages, always timestamp-ordered. The cursor follows a previous page when one sweep has more hits than one page holds.
Source§

fn user_info<'life0, 'life1, 'async_trait>( &'life0 self, user: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<SlackUser, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

users.info for one user id.
Source§

fn list_users<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<SlackUser>, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Every member in the workspace. Deactivated members are included so the caller decides what a row means.
Source§

fn pins<'life0, 'life1, 'async_trait>( &'life0 self, channel: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<SlackPin>, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

pins.list for one conversation.
Source§

fn bookmarks<'life0, 'life1, 'async_trait>( &'life0 self, channel: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<SlackBookmark>, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

bookmarks.list for one conversation.
Source§

impl UsersPages for SlackClient

Source§

fn users_page<'life0, 'life1, 'async_trait>( &'life0 self, cursor: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<UsersPage, SlackError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more