Questions
Questions

Reputation: 1

How to get Slack User Token for Slack App to Post Message on User Behalf

I'm trying to make a Slack App that can send messages on user behalf (similar to Giphy, which apparently is different than regular Slack Apps).

In order to send messages as users (not just impersonating using chat:write.customized), I need the user's User Token.

When you install the app, it automatically generates a user token for the installer account, but I need a token for every user that wants to use the app.

The Slack API says "User tokens represent workspace members. They are issued for the user who installed the app and for users who authenticate the app."

How can I get users to authenticate the app and get a token for them? Is that possible?

Thank you!

I've tried searching around, but haven't been able to find much information on this yet. Others have said that you need to use the Slack App oauth page to get tokens, but I'm still not sure how users can "authenticate the app".

Upvotes: 0

Views: 1017

Answers (1)

Shivendra Soni
Shivendra Soni

Reputation: 712

Instead of using legacy tokens, Slack recommends creating a Slack app with the necessary scopes. Here are some alternatives: a. User Token with chat:write.customize scope:

  • Create a Slack app for your workspace
  • Request the chat:write.customize and users:read.email scope
  • (Re)Install the app to your workspace
  • Use the User OAuth Token provided

This allows you to send messages with a custom username and avatar, which can be set to match your own.

To get the user oauth token:

To add the chat:write.customize and users:read.email scopes to your Slack app, you need to modify your app's configuration in the Slack API dashboard. Here's a step-by-step guide on how to do this:

-Go to the Slack API website: Visit https://api.slack.com/apps

  • Select your app:
  • Click on the app you're using for this integration. If you haven't created an app yet, you'll need to create one by clicking "Create New App".
  • Navigate to OAuth & Permissions: -In the left sidebar, under "Features", click on "OAuth & Permissions". -Scroll down to Scopes: --In the "OAuth & Permissions" page, scroll down to the "Scopes" section. -Add Bot Token Scopes: -Under "Bot Token Scopes", click "Add an OAuth Scope". -Add the required scopes: -Search for and add the following scopes:

chat:write.customize users:read.email

Add User Token Scopes (if needed): NOTE: If you're using User tokens, you may also need to add these under "User Token Scopes".

Upvotes: 0

Related Questions