slackapi / deno-slack-sdk

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

[QUERY] How to fetch email from user ID? #290

Closed asura-io closed 4 months ago

asura-io commented 4 months ago

Question

I have the following workflow:

const inputForm = SampleWorkflow.addStep(
  Schema.slack.functions.OpenForm,
  {
    title: "New Request",
    interactivity: SampleWorkflow.inputs.interactivity,
    submit_label: "Submit request",
    fields: {
      elements: [{
        name: "user",
        title: "User",
        type: Schema.slack.types.user_id,
      },
...

This is used to create a GitLab issue ticket. I would like to insert the requesting user's email in the issue ticket, but I only have the Slack User ID, not the email. Is there a way to extract the email without another web API call? If not, is there an easy way to authenticate with the web API without using a token, since the deno-slack-sdk is already authenticated?

Environment

"deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.7.0/", "deno-slack-api/": "https://deno.land/x/deno_slack_api@2.2.0/",

deno 1.41.2 (release, aarch64-apple-darwin) v8 12.1.285.27 typescript 5.3.3

ProductName: macOS ProductVersion: 13.5 BuildVersion: 22G74 Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020

filmaj commented 4 months ago

You can use the users.info API, but note that your app should also ask for the users.read:email scope to retrieve this part of the user profile.

If this resolves you issue, we appreciate it if you could close the issue. Otherwise, we're here to help.

asura-io commented 4 months ago

How do I authenticate to this API in my deno-slack-sdk app?

I am doing this in local development right now. I am able to run everything via slack login and slack run. Do I need to set an additional token as an env var? Or does the SDK have some way of accessing the token that is passed in by authentication via the CLI?

zimeg commented 4 months ago

@gacharya the scopes for your bot can be set in your app manifest and should be automatically requested when you re-install (re-run) the app in your workspace. A bit more info on manifests can be found in these docs!