slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno
https://api.slack.com/automation
MIT License
155 stars 27 forks source link

[QUERY] How to create bot tokens for apps created via CLI? #283

Closed tsarni closed 6 months ago

tsarni commented 6 months ago

Question

How can I create an xoxb token for app created and deployed by slack CLI?

Context

The https://api.slack.com/apps list the app I have developing using the deno-slack-sdk but they are greyd out and they have tooltip saying that apps created by CLI can only be managed by CLI. So I cannot find a way to create the xoxb token. For some reason the local version of bot I can manage via https://api.slack.com/apps/{app_id}, but not the ones deployed.

Environment

deno 1.40.2 (release, aarch64-apple-darwin) v8 12.1.285.6 typescript 5.3.3 ProductName: macOS ProductVersion: 14.2.1 BuildVersion: 23C71 Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020 "deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.5.0/", "deno-slack-api/": "https://deno.land/x/deno_slack_api@2.1.2/",

srajiang commented 6 months ago

Hi @tsarni! Are you planning on deploying your app with Slack, or are you trying to host your app on your own infrastructure and that's why you're looking to get the xoxb?

Today, unfortunately we don't make it super easy to use the deno-slack-sdk and self-host. So there isn't a great way for you to get your app's token with Slack once installed.

If you're deploying with Slack however, you don't need to manage your xoxb token at all. Function execution events will come with a just in time token, and the SDK will should care of sending that along with your requests.

tsarni commented 6 months ago

I am using Slack managed service infra. The issue is that that I need to make a separate call to Slack Conversations.API for which I need to have xoxb token. The reason is that I need to check whether app_mention is being called from within a thread or from main channel as this was not possible to be achieved otherwise via app_mention event. So granted it is a bit of hack. I can create the token for the local bot as the managed of that is somehow possible from the UI. I can actually even use the same xoxb token from the deployed app, but that then requires the local version of the app to invited in the same channel or otherwise the https://slack.com/api/conversations.replies will return error "not_in_channel".

srajiang commented 6 months ago

@tsarni - Alright, that's helpful to know!

Have you tried using the client.apiCall method within your function handler to make the conversations API method call you need? Deno SDK should take care of passing a client argument in to your function handler that's setup with the just in time token I mentioned.

Something like this: https://github.com/slack-samples/deno-triage-bot/blob/2290a1e0676a51a0899bbdc2e43a1663dff0e01b/functions/triage.ts#L199-L206

srajiang commented 6 months ago

One other thing to know is that token is available as a property you can use on the SlackFunction context. Thisis not a xoxb token, mind you. It's a xwfp and is not long-lived. So you can also use this property if needed.

tsarni commented 6 months ago

Thanks @srajiang I will will give these a try.