Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MongoDB installation store #1437

Open
1 of 9 tasks
faisalsaifii opened this issue Nov 30, 2023 · 5 comments
Open
1 of 9 tasks

Add MongoDB installation store #1437

faisalsaifii opened this issue Nov 30, 2023 · 5 comments
Labels
discussion M-T: An issue where more input is needed to reach a decision oauth Version: 3x
Milestone

Comments

@faisalsaifii
Copy link

faisalsaifii commented Nov 30, 2023

I'd like to add MongoDB OAuth installation store which is currently not present in here

I recently developed my own app Pollify and wanted to use MongoDB for which there wasn't an installation store available, so I had to create one on my own.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.models (UI component builders)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.rtm (RTM client)
  • slack_sdk.signature (Request Signature Verifier)
@seratch seratch added discussion M-T: An issue where more input is needed to reach a decision Version: 3x oauth and removed untriaged labels Nov 30, 2023
@seratch seratch added this to the 3.x milestone Nov 30, 2023
@seratch
Copy link
Member

seratch commented Nov 30, 2023

Hi @faisalsaifii, thank you so much for submitting this issue! Also, we are glad to know you've implemented your installation store with MongoDB.

Having more options out-of-the-box is great! However, our SDK maintenance team has a little bit limited capacity for this Python tool. Thefore, we'd like to hold off working on this addition until we receive more requests to the idea (i.e. a number of positive reactions from others). Please go ahead with your implementation for now.

@faisalsaifii
Copy link
Author

Hi @seratch, sure I understand.

@MadhabaPatra
Copy link

@faisalsaifii Can you help me with the setup? I also wanted to implement mongodb installation store.

@faisalsaifii
Copy link
Author

Hey @seratch, can I pick this up now?

@tingyiy
Copy link

tingyiy commented Oct 9, 2024

this is my bot only implementation:

class MongoInstallationStore(InstallationStore):

def __init__(self):
    self.db = get_db()

def save(self, installation: Installation):
    self.db.slack_installations.update_one(
        {
            "enterprise_id": installation.enterprise_id,
            "team_id": installation.team_id,
        },
        {"$set": installation.to_dict()},
        upsert=True,
    )
    self.db.slack_bots.update_one(
        {"enterprise_id": installation.enterprise_id, "team_id": installation.team_id},
        {"$set": installation.to_bot().to_dict()},
        upsert=True,
    )

def find_installation(
    self,
    *,
    enterprise_id: Optional[str],
    team_id: Optional[str],
    user_id: Optional[str] = None,
    is_enterprise_install: Optional[bool] = False,
) -> Optional[Installation]:
    if is_enterprise_install:
        result = self.db.slack_installations.find_one(
            {"enterprise_id": enterprise_id, "user_id": user_id}
        )
        if result:
            del result["_id"]
            return Installation(**result)
        result = self.db.slack_installations.find_one({"enterprise_id": enterprise_id})
        if result:
            del result["_id"]
            return Installation(**result)
        return None
    result = self.db.slack_installations.find_one(
        {"team_id": team_id, "user_id": user_id}
    )
    if result:
        del result["_id"]
        return Installation(**result)
    result = self.db.slack_installations.find_one({"team_id": team_id})
    if result:
        del result["_id"]
        return Installation(**result)
    return None

def find_bot(
    self,
    *,
    enterprise_id: Optional[str],
    team_id: Optional[str],
    is_enterprise_install: Optional[bool] = False,
) -> Optional[Bot]:
    """Finds a bot scope installation per workspace / org"""
    if is_enterprise_install:
        result = self.db.slack_bots.find_one({"enterprise_id": enterprise_id})
        if result:
            del result["_id"]
            return Bot(**result)
        return None
    result = self.db.slack_bots.find_one({"team_id": team_id})
    if result:
        del result["_id"]
        return Bot(**result)
    return None

def delete_bot(
    self,
    *,
    enterprise_id: Optional[str],
    team_id: Optional[str],
) -> None:
    """Deletes a bot scope installation per workspace / org"""
    self.db.slack_bots.delete_one({"enterprise_id": enterprise_id, "team_id": team_id})

def delete_installation(
    self,
    *,
    enterprise_id: Optional[str],
    team_id: Optional[str],
    user_id: Optional[str] = None,
) -> None:
    """Deletes an installation that matches the given IDs"""
    if user_id is not None:
        self.db.slack_installations.delete_one(
            {"enterprise_id": enterprise_id, "team_id": team_id, "user_id": user_id}
        )
    else:
        self.db.slack_installations.delete_one(
            {"enterprise_id": enterprise_id, "team_id": team_id}
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion M-T: An issue where more input is needed to reach a decision oauth Version: 3x
Projects
None yet
Development

No branches or pull requests

4 participants