66client_id = os .environ ["SLACK_CLIENT_ID" ]
77client_secret = os .environ ["SLACK_CLIENT_SECRET" ]
88signing_secret = os .environ ["SLACK_SIGNING_SECRET" ]
9- state = ' super-secret-state'
9+ state = " super-secret-state"
1010# Scopes needed for this app
11- oauth_scope = ' chat:write, channels:read, channels:join, channels:manage'
11+ oauth_scope = "" . join ([ " chat:write" , " channels:read" , " channels:join" , " channels:manage" ])
1212
1313app = Flask (__name__ )
14+
1415# Route to kick off Oauth flow
1516@app .route ("/begin_auth" , methods = ["GET" ])
1617def pre_install ():
@@ -20,14 +21,14 @@ def pre_install():
2021@app .route ("/finish_auth" , methods = ["GET" , "POST" ])
2122def post_install ():
2223 # Retrieve the auth code and state from the request params
23- auth_code = request .args [' code' ]
24- received_state = request .args [' state' ]
24+ auth_code = request .args [" code" ]
25+ received_state = request .args [" state" ]
2526
26- # An empty string is a valid token for this request
27- client = slack .WebClient (token = "" )
27+ # Token is not required to call the oauth.v2.access method
28+ client = slack .WebClient ()
2829
2930 if received_state == state :
30- # Request the auth tokens from Slack
31+ # Exchange the authorization code for an access token with Slack
3132 response = client .oauth_v2_access (
3233 client_id = client_id ,
3334 client_secret = client_secret ,
@@ -37,7 +38,7 @@ def post_install():
3738 return "Invalid State"
3839
3940 # Save the bot token to an environmental variable or to your data store
40- os .environ ["SLACK_BOT_TOKEN" ] = response [' access_token' ]
41+ os .environ ["SLACK_BOT_TOKEN" ] = response [" access_token" ]
4142
4243 # See if "the-welcome-channel" exists. Create it if it doesn't.
4344 channel_exists ()
@@ -55,7 +56,7 @@ def channel_exists():
5556 exists = False
5657 for k in clist ["channels" ]:
5758 # look for the channel in the list of existing channels
58- if k [' name' ] == ' the-welcome-channel' :
59+ if k [" name" ] == " the-welcome-channel" :
5960 exists = True
6061 break
6162 if exists == False :
@@ -76,13 +77,13 @@ def create_channel():
7677# Sends a DM to the user who joined the channel
7778@slack_events_adapter .on ("member_joined_channel" )
7879def member_joined_channel (event_data ):
79- user = event_data [' event' ][ ' user' ]
80- channelid = event_data [' event' ][ ' channel' ]
80+ user = event_data [" event" ][ " user" ]
81+ channelid = event_data [" event" ][ " channel" ]
8182 token = os .environ ["SLACK_BOT_TOKEN" ]
8283
8384 # In case the app doesn't have access to the oAuth Token
8485 if token is None :
85- print (' ERROR: Autenticate the App!' )
86+ print (" ERROR: Autenticate the App!" )
8687 return
8788 client = slack .WebClient (token = token )
8889
0 commit comments