Yahor Barkouski
Yahor Barkouski

Reputation: 1556

How to post a message to Slack via user token and Slack API

Is it possible to send a message via Slack API from my current user? I've created a slack user token, documentation also said:

User tokens represent the same access a user has to a workspace -- the channels, conversations, users, reactions, etc. they can see
Write actions with user tokens are performed as if by the user themselves

but when I'm trying to send some requests via Slack API, I get notified that I have no ops for it, example:

-> GET https://slack.com/api/users.identity (+ bearer with my user token)

->

{
    "ok": false,
    "error": "missing_scope",
    "needed": "identity.basic",
    "provided": "identify,app_configurations:read,app_configurations:write"
}

Same when I'm trying to send a message / get a conversations list

Upvotes: 3

Views: 3444

Answers (1)

sandra
sandra

Reputation: 1566

If all you want is to send a message then make sure to add the chat:write scope to your app from your OAuth & Permissions page on your app's management site. Remove all the other scopes, save an re-install your app. You should then be able to send a message using the chat.postMessage method. If you want to use the conversations.list method then you'll need to add the channels:read scope. To use the users.identity method you will need to enable Sign In with Slack as outlined here.

Upvotes: 3

Related Questions