Search code examples
slackslack-api

Can I differentiate a Slack display name from a Slack ID?


I'm integrating my software with the Slack API, and I would like to allow the user to configure the Slack settings by writing either the "display name" or the "user ID".

I would like to use an heuristic to differentiate user names from user ids. I read the following in the Slack documentation:

id - this user's ID, which might start with U or W; IDs beginning with U are unique only to a workspace. IDs beginning with W are unique for an entire Enterprise Grid organization and may represent the user on multiple workspaces within it.

Taking a look to a Slack ID, for example (W012A3CDE), it seems that it fits the following specs:

  • Starts with "U" or "W" (confirmed by the documentation)
  • Has no lowercase chars (pretty sure of this)
  • Has at least 1 number (not sure -> need to confirm)
  • Has 9 chars length (not sure -> need to confirm)

If all above are true, I would not be difficult to differentiate the user name from id, and even in an ambiguity case, I would allow to use @ to resolve the ambiguity.

So my question is: Is there any public spec about how Slack user IDs are?


Solution

  • Well, I finally found the public Slack regexp used for the user ID:

    https://github.com/slackapi/slack-api-specs/blob/master/web-api/slack_web_openapi_v2.json#L106

        "defs_user_id": {
            "pattern": "^[UW][A-Z0-9]{8}$",
            "title": "User ID",
            "type": "string"
        },