Coder Social home page Coder Social logo

Comments (10)

abdolence avatar abdolence commented on May 24, 2024 1

Also with the recent Slack Morphism changes, I've now needed to include hyper & hyper-rustls in my cargo.toml just to be able to specify the new type of a slack client and slack session. Is there a way around this?

Ok, this was required in your example just because you didn't use type alias:
image

from slack-morphism-rust.

abdolence avatar abdolence commented on May 24, 2024 1

There is also type alias:
SlackHyperClient = SlackClient<SlackClientHyperHttpsConnector> which you may find useful.

from slack-morphism-rust.

abdolence avatar abdolence commented on May 24, 2024 1

I see that you were trying to share this, and if you use only one token per-app this is something you need. You don't need to worry about session objects, it is just a reference to token + client to call multiple methods from Web API in one Rust function, so you can easily create them millions if needed - they are cheap.

    // let slack_workaround = Arc::new(SlackStateWorkaround {
    //     bot_token: slack_bot_token,
    //     slack_client,
    // });

Also keep in mind there are some Web API methods that don't require tokens (such as post_webhook_message), so in this case you won't need to create any session.

That session is basically this:

{
    client: &'a SlackClient<SCHC>,
    token: &'a SlackApiToken,
}

from slack-morphism-rust.

noxasaxon avatar noxasaxon commented on May 24, 2024 1

thanks for the quick responses!

I've updated the code to use the Type Aliases you specified, and this let me remove the hyper dependencies 🙇

Good point about the fact that there are unauthenticated slack API calls, I'll continue sharing around a struct with the Client and Bot Token so that I can make those calls as needed.

Another thing I noticed in your demo, that you didn't protect your routes - for the production you may want to use SlackEventSignatureVerifier (as it is used for hyper routes out of the box).

Good catch! Yeah my plan is to hook up the signature verifier before it goes live, but i want to try and include it as an Axum middleware only for the Slack specific routes and haven't had time to dive down that rabbit hole yet and figure out if its possible 😆 .

thanks a ton for your help and for making this library!

from slack-morphism-rust.

noxasaxon avatar noxasaxon commented on May 24, 2024 1

Closing this issue, but first I wanted to leave code for people to find later if they want to use Axum/Tower with slack-morphism. I updated the demo repo with a an Axum/Tower middleware service, and you can choose to add it as a service layer , where it will protect only the routes above it. Then you can add more (non-slack) routes below it.

Thanks again for your help!

from slack-morphism-rust.

noxasaxon avatar noxasaxon commented on May 24, 2024 1

Hey @abdolence, my bot made it to open source if you're curious how it all turned out. Thanks!

https://github.com/twilio-labs/receptionist-bot-rs

from slack-morphism-rust.

noxasaxon avatar noxasaxon commented on May 24, 2024 1

Haha yeah I forgot to follow up on that one, will do 👍

from slack-morphism-rust.

abdolence avatar abdolence commented on May 24, 2024

Hey, this is an interesting case. Let's discuss if we can find better ergonomics for this.
SlackClientSession is just a lightweight object that was just supposed to be used for consequent calls using the same token in one function and I don't share it personally.

My code is usually read some token (from database/file/environment) for a particular identified workspace, and creates those sessions all the time just to have multiple consequent calls to Web APIs in one rust function without specifying token parameter all the time. This was the main purpose for it.

Why not just to share your token between threads + Arc<SlackClient> everywhere you need? Let me check your source code.

from slack-morphism-rust.

abdolence avatar abdolence commented on May 24, 2024

Another thing I noticed in your demo, that you didn't protect your routes - for the production you may want to use SlackEventSignatureVerifier (as it is used for hyper routes out of the box).

from slack-morphism-rust.

abdolence avatar abdolence commented on May 24, 2024

@noxasaxon Cool stuff, thanks for sharing this. Stories like this give additional motivations :)

PS Feel free to submit PRs if you see absent functions like Reactions API :P

from slack-morphism-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.