Skip to content

Integrate slackbot with baml client and sage backend #2308

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

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

seawatts
Copy link
Contributor

Pull Request Template

Thanks for taking the time to fill out this pull request!

Issue Reference

Please link to any related issues

  • This PR fixes/closes #[issue number]

Changes

Please describe the changes proposed in this pull request

This PR enables a Slackbot by adding a new Slack Events API endpoint to sage-backend and making the backend more resilient to environment-dependent initialization at build time.

Key changes include:

  • New Slack Events API Route: Added /api/slack/events to handle Slack app_mention and direct messages, including signature verification and URL challenges.
  • Integration with Existing Query Flow: The Slack bot leverages the existing submitQuery action to process user requests and respond in-thread.
  • Lazy Initialization: Refactored OpenAI, Pinecone, NotionLogger, and SlackFeedbackLogger clients to be initialized on demand within request handlers. This prevents build-time failures when environment variables are not present.
  • Dynamic BAML Client Import: Modified submitQuery to dynamically import baml_client at runtime, providing a fallback mechanism (returning top Pinecone docs) if the client is not available (e.g., if not generated during deployment).

Testing

Please describe how you tested these changes

  • Unit tests added/updated
  • Manual testing performed (verified sage-backend builds successfully and outlined Slack configuration for functional testing)
  • Tested in typescript/apps/sage-backend build environment

Screenshots

If applicable, add screenshots to help explain your changes

[Add screenshots here...]

PR Checklist

Please ensure you've completed these items

  • I have read and followed the contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Additional Notes

Add any other context about the PR here

How to configure Slack:

  1. Create a Slack app:
    • Enable Events API and subscribe to bot events: app_mention, message.im.
    • Set Request URL to: <your-sage-backend-url>/api/slack/events.
    • Install the bot to your workspace and note the Bot User OAuth Token.
  2. Required Environment Variables (for deployment, e.g., Vercel):
    • SLACK_SIGNING_SECRET (from your Slack app settings)
    • SLACK_BOUNDARY_BOT_TOKEN (the Bot User OAuth Token)
    • OPENAI_API_KEY
    • PINECONE_API_KEY
    • Optional for logging: NOTION_BOUNDARY_BOT_TOKEN, NOTION_ASK_BAML_LOGS_DATABASE_ID
  3. Usage in Slack: Mention the bot in a channel or DM it (e.g., @baamy find me a friday project).
  4. BAML Client: The submitQuery function now uses an eval-based dynamic import for baml_client. If baml_client is not generated and available at runtime, the bot will provide a fallback response using Pinecone search results. Ensure baml_client is generated per baml_src/generators.baml for full functionality.

Open in Cursor Open in Web

… handling

Co-authored-by: chris.watts.t <chris.watts.t@gmail.com>
Copy link

cursor bot commented Aug 13, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@seawatts seawatts temporarily deployed to boundary-tools-dev August 13, 2025 21:54 — with GitHub Actions Inactive
@seawatts seawatts temporarily deployed to boundary-tools-dev August 13, 2025 21:54 — with GitHub Actions Inactive
@seawatts seawatts temporarily deployed to boundary-tools-dev August 13, 2025 21:54 — with GitHub Actions Inactive
Copy link

vercel bot commented Aug 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
promptfiddle ⬜️ Skipped Aug 13, 2025 9:54pm

Copy link

Copy link

Comment on lines +43 to +44
return text
.replace(/<@[^>]+>/g, '') // remove mentions

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
a user-provided value
may run slow on strings starting with '<@' and with many repetitions of '<@'.
@hellovai
Copy link
Contributor

@seawatts fyi the tests are all failing on:
https://sage-backend-r0ly70tjt-baml.vercel.app/

@seawatts
Copy link
Contributor Author

Yea. Not going to merge this. It was a one shot prompt to see if cursor could do it. It failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants