slack-rs icon indicating copy to clipboard operation
slack-rs copied to clipboard

Exported API has no available client

Open squidpickles opened this issue 8 years ago • 8 comments

I've been refactoring my code with recent changes to the library.

One change is that we no longer get our user's name or ID on on_connect(), so I'm trying to call slack::api::users::list to find that information.

The problem is the API calls all require a client implementing the SlackWebRequestSender trait. No such client is exposed either by slack or slack_api. The authentication token also needs to be passed to any function that might want to make an API call.

Would it make sense to have something analogous to the RtmClient that essentially wraps the reqwest::Client and an API token? It's what I would likely implement, but I guess my question is whether there's some other way to access a SlackWebRequestSender that I'm missing.

squidpickles avatar May 05 '17 06:05 squidpickles

Once connected you can access the start response which contains a lot of the things previously on the client https://docs.rs/slack/0.17.1/slack/struct.RtmClient.html#method.start_response

Using the api is currently kind of standalone. You can use reqwest for the api client or impl your own. It was the same before i thought.

dten avatar May 05 '17 07:05 dten

Docs.rs isn't linking to the type for some reason but it's here https://docs.rs/slack_api/0.16.1/slack_api/rtm/struct.StartResponse.html

dten avatar May 05 '17 07:05 dten

Ah yes, I did see and then forget about that. Thanks.

That solves my particular issue, but I am still at a bit of a loss as to how to access API functions without rolling my own client. Is that possible?

squidpickles avatar May 05 '17 16:05 squidpickles

@squidpickles Took me quite a while to figure this out, but it seems that the SlackWebRequestSender impl for reqwest only works if the reqwest version in your Cargo.toml matches the one used by slack_api, so 0.4.0 currently.

bwasty avatar May 05 '17 19:05 bwasty

Oh i did have the same problem with versions. If slack api re-exported its one rather than relying on versions matching it would work better i think

dten avatar May 06 '17 14:05 dten

Oh yeah... version mismatch + traits... I have run into that several times before. I don't know why I still don't think to check that. An exported client would help a ton, yes.

squidpickles avatar May 07 '17 01:05 squidpickles

Made a PR: slack-rs/slack-rs-api#42.

bwasty avatar May 07 '17 14:05 bwasty

And another one with an example: #82.

bwasty avatar May 07 '17 15:05 bwasty