0

As the title suggests, I'm wondering how we could:

  • Create a channel
  • Send user an initial message

right after the user installs the Slack app (distributable app) for the first time in a workspace?

A similar question was asked previously but the answer was too concise, and I wonder if someone could be so kind to give a hint using this sample Django Slack app code? Cheers.

Nahua Kang
  • 366
  • 1
  • 7
  • 19

2 Answers2

2

On the 'OAuth & Permissions' page of your app, there is a section for 'Redirect URLs'

What it does is that when user installs the app, it redirects to the user implemented endpoint.

OAuth Flow

  1. when the user installs the app using 'Add To Slack' button or using https://slack.com/oauth/authorize


    Details here : https://api.slack.com/legacy/oauth#authenticating-users-with-oauth__the-oauth-flow__step-1---sending-users-to-authorize-andor-install

  2. The generated code is redirected to your specified endpoint - "Redirect URL" https://api.slack.com/legacy/oauth#authenticating-users-with-oauth__the-oauth-flow__step-2---users-are-redirected-to-your-server-with-a-verification-code

  3. Solution: Now you need to implement this endpoint to generate access token https://api.slack.com/legacy/oauth#authenticating-users-with-oauth__the-oauth-flow__step-3---exchanging-a-verification-code-for-an-access-token

  • After generating token, you can write your code to :
    1. Create a channel
    2. Send user an initial message
Suyash Gaur
  • 2,481
  • 2
  • 9
  • 22
  • Thanks for the info! I'm asking more specifically along the sample app code link I posted since `slackapi/bolt-python` is supposed to take care of OAuth and I just don't know how to define post-installation behaviors given that dependency. – Nahua Kang Jul 13 '21 at 08:41
  • 1
    Please go through : https://slack.dev/bolt-python/concepts#authenticating-oauth It mentions about : Bolt for Python will create a Redirect URL 'slack/oauth_redirect', which Slack uses to redirect users after they complete your app’s installation flow. – Suyash Gaur Jul 14 '21 at 07:28
0

After reading Suyash's explanations, I carefully examined the sample code provided by bolt-python for Django again and realized:

  1. bolt-python takes care of OAuth flow and we only need to specify the correct URLs (for redirect URLs as well as event subscriptions, interactivity, etc.) in the app panel.
  2. What one could do is perform all these desired installation actions inside DjangoInstallationStore.save method because that's when an installation is finally completed. In my case I created a SlackManager with a specific method which I could use (via local import) to perform post-installation actions.
Nahua Kang
  • 366
  • 1
  • 7
  • 19