dashboard_card.py 1.3 KB

123456789101112131415161718192021222324252627
  1. """Slack's Channels-page card (Desktop + web dashboard): the PlatformEntry ``dashboard_*`` /
  2. ``docs_url`` fields register() spreads in. Kept apart from adapter.py, which is over its size cap."""
  3. import re
  4. # Write checks (kept in sync with ChannelsPage.tsx): reject tokens pasted into the wrong field.
  5. # "*" is the allow-all wildcard; allowlists split like the adapter's parser.
  6. _MEMBER_ID_RE = re.compile(r"[UW][A-Z0-9]{2,}")
  7. _ENV_VALUE_RULES = {
  8. "SLACK_BOT_TOKEN": (
  9. lambda v: v.startswith("xoxb-"),
  10. "Slack Bot Token must start with xoxb-. Paste the bot token from OAuth & Permissions."),
  11. "SLACK_APP_TOKEN": (
  12. lambda v: v.startswith("xapp-"),
  13. "Slack App Token must start with xapp-. Paste the app-level token from Basic Information > App-Level Tokens."),
  14. "SLACK_ALLOWED_USERS": (
  15. lambda v: all(u == "*" or _MEMBER_ID_RE.fullmatch(u)
  16. for u in (p.strip() for p in v.split(",")) if u),
  17. "Slack allowed user IDs must be comma-separated member IDs like U01ABC2DEF3."),
  18. }
  19. DASHBOARD_CARD = dict(
  20. dashboard_description="Use Hermes from Slack via Socket Mode. Add allowed Slack member IDs so connected bots can respond.",
  21. docs_url="https://api.slack.com/apps",
  22. dashboard_env_vars=("SLACK_BOT_TOKEN", "SLACK_APP_TOKEN", "SLACK_ALLOWED_USERS"),
  23. env_value_rules=_ENV_VALUE_RULES,
  24. )