slackapi / bolt-python

A framework to build Slack apps using Python
https://slack.dev/bolt-python/
MIT License
1.05k stars 245 forks source link

Cant see the active commands after installing my slack app in another workspace #1094

Closed dvrshi closed 3 months ago

dvrshi commented 3 months ago
import os
from slack_bolt import App
from dotenv import load_dotenv
import requests
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
import re
import json
from slack_bolt.adapter.flask import SlackRequestHandler
from slack_bolt.oauth.oauth_settings import OAuthSettings
from slack_bolt.oauth.oauth_flow import OAuthFlow
from mongo_db_store import MongoDBInstallationStore
import functions
load_dotenv()

mdbclient = MongoClient(os.environ.get("MONGO_DB_STAGING"), server_api=ServerApi('1'))
try:
    mdbclient.admin.command('ping')
except Exception as e:
    print(e)
    exit()
signing_secret = os.environ["SIGNING_SECRET"]
oauth_settings = OAuthSettings(
    client_id=os.environ["CLIENT_ID"],
    client_secret=os.environ["CLIENT_SECRET"],
    scopes=json.loads(os.environ.get("SCOPES")),
    installation_store=MongoDBInstallationStore(
        client=mdbclient, database="Slack", client_id=os.environ["CLIENT_ID"]
    ),
)
oauth_flow = OAuthFlow(settings=oauth_settings)
app = App(
    # token=os.environ.get("SLACK_TOKEN"),
    signing_secret=os.environ.get("SIGNING_SECRET"),
    oauth_flow=oauth_flow,
)

@app.event('message')
def message(say,event,ack):
    ##this code handles messages events and works well

@app.command("/findprofiles")
def findprofiles(command,ack,say):
    ##these commands work well in the workspace through which I have created the app

@app.command("/findcandidates")
def findcandidates(command,ack,say,context):
    ##these commands work well in the workspace through which I have created the app 

@app.command("/activejobs")
def findactivejobs(command,ack,say,context):
    ##these commands work well in the workspace through which I have created the app 

@app.command("/help")
def printcommands(ack,say):
    ack()
    say(os.environ.get("TUTORIAL"))

if __name__ == "__main__":
    app.start(port=5000)

i can access these commands here, this workspace and account I have used to create the bot image

this is another workspace in which i am testing the bot installation, the message event works fine, i am getting the intended response but here the commands are not there image

in configuration also the commands are visible but not in the app DM for other workspaces image

seratch commented 3 months ago

Hi @dvrshi, thanks for asking the question. If your app is successfully installed with sufficient scopes (commands in this case), the commands will appear shortly after the installation. There could be a short delay on your Slack desktop app side. In the case, reloading/restarting your desktop app may help.

dvrshi commented 3 months ago

Hi @dvrshi, thanks for asking the question. If your app is successfully installed with sufficient scopes (commands in this case), the commands will appear shortly after the installation. There could be a short delay on your Slack desktop app side. In the case, reloading/restarting your desktop app may help.

Hey @seratch thanks for prompt reply as soon as I posted this issue here I realised that I had not mentioned commands in my bot permissions list, thank you for the quick response, I had one other query, I have written this code at a very basic level, there are a few database calls that fetch data and send it here, are there any changes I would need to do to make this code "scalable", i mean when multiple users install this app and use it. I have no idea whether slack bolt handles this type of issue. Do tell if I explained my question poorly

seratch commented 3 months ago

If your app just needs bot scopes, probably your current code should be already good to go. If you're planning to add user scopes too, the implementation could be a bit more complex. Please refer to how the built-in installation stores are implemented: https://github.com/slackapi/python-slack-sdk/tree/main/slack_sdk/oauth/installation_store

Hope this helps. If everything is clear now, would you mind closing this issue? You can create a new issue for a different question at any time!

dvrshi commented 3 months ago

If your app just needs bot scopes, probably your current code should be already good to go. If you're planning to add user scopes too, the implementation could be a bit more complex. Please refer to how the built-in installation stores are implemented: https://github.com/slackapi/python-slack-sdk/tree/main/slack_sdk/oauth/installation_store

Hope this helps. If everything is clear now, would you mind closing this issue? You can create a new issue for a different question at any time!

Thanks, closing the issue

PS. please accept my connection request linkedin (should be from Devarshi)