slackapi / node-slack-sdk

Slack Developer Kit for Node.js

Home Page:https://slack.dev/node-slack-sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to set user status without a typescript error

richardaum opened this issue Β· comments

The code related to set profile info is not properly defined on Typescript. That is because its parameters are not correct:

export interface UsersProfileSetArguments extends WebAPICallOptions, TokenOverridable {
    profile?: string;
    user?: string;
    name?: string;
    value?: string;
}

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/rtm-api
  • @slack/webhooks
  • @slack/oauth
  • @slack/socket-mode
  • @slack/types
  • I don't know

Reproducible in:

The Slack SDK version

3.16.0

Node.js runtime version

v21.4.0

OS info

ProductName: macOS
ProductVersion: 13.6.2
BuildVersion: 22G320
Darwin Kernel Version 22.6.0: Thu Nov 2 07:43:57 PDT 2023; root:xnu-8796.141.3.701.17~6/RELEASE_ARM64_T6000

Steps to reproduce:

Submit the following code to Typescript:

app.client.users.profile.set({
    profile: {
      status_text: "riding a train",
      status_emoji: ":mountain_railway:",
      status_expiration: 0,
    },
  });

Expected result:

No errors

Actual result:

Type '{ status_text: string; status_emoji: string; status_expiration: number; }' is not assignable to type 'string'.ts(2322)

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. πŸ™‡

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

hi, @richardaum! Thanks for your question πŸ™Œ

At first glance of the parameter declaration and types provided for users.profile.set, it looks correct to me. Based on the error you provided, it looks like there is a type incompatibility with your profile. This might be because you are passing in the profile value as a raw object when it's expecting a string. Could you try using a JSON.stringify() to turn the object into a string? As seen in the documentation for profile:

"Collection of key:value pairs presented as a URL-encoded JSON hash. At most 50 fields may be set. Each field name is limited to 255 characters."

I would try something like this:

const profileStringify = JSON.stringify({
      status_text: "riding a train",
      status_emoji: ":mountain_railway:",
      status_expiration: 0,
    })

app.client.users.profile.set({
    profile: profileStringify,
  });

hi, @richardaum! πŸ‘‹

I got an update from a member of our team that this issue was also able to recreated on their end and they've been working on adding some more type safety to the node SDK - their WIP PR can be found here. They're hoping to land a release candidate for these changes this week, which will be in v7.0.0.

When v7.0.0 is released, the profile field will be typed as a JSON object so this issue should be fixed. In the meantime, feel free to use the above JSON.stringify() as a workaround until v7.0.0 is available!

πŸ‘‹ It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

With 7.0 out now, this should no longer be an issue, but a workaround as mention is available to JSON.stringify the relevant field for web-api 6.x.