Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set user status without a typescript error #1703

Closed
2 of 7 tasks
richardaum opened this issue Dec 11, 2023 · 4 comments
Closed
2 of 7 tasks

Unable to set user status without a typescript error #1703

richardaum opened this issue Dec 11, 2023 · 4 comments
Assignees
Labels
auto-triage-stale question M-T: User needs support to use the project

Comments

@richardaum
Copy link

richardaum commented Dec 11, 2023

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.

@richardaum richardaum changed the title (Set a clear title describing the issue) Unable to set user status without a typescript error Dec 11, 2023
@hello-ashleyintech hello-ashleyintech self-assigned this Dec 11, 2023
@hello-ashleyintech hello-ashleyintech added question M-T: User needs support to use the project and removed untriaged labels Dec 11, 2023
@hello-ashleyintech
Copy link
Contributor

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,
  });

@hello-ashleyintech
Copy link
Contributor

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!

Copy link

👋 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.

@filmaj
Copy link
Contributor

filmaj commented Jan 26, 2024

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.

@filmaj filmaj closed this as completed Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-stale question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

3 participants