Setup Guide for Mercury Bank + Slack Integration

Follow these steps to set up your Mercury Bank and Slack integration:

1. Mercury API Setup

  1. Log in to your Mercury account at https://mercury.com
  2. Navigate to Developer Settings
  3. Create a new API key with the following permissions:
    • accounts:read - To read account information
    • transactions:read - To read transaction data
  4. Copy your API key for the next step

Mercury Webhook Setup (If Available)

If Mercury supports webhooks for transaction notifications:

  1. In your Mercury developer settings, look for "Webhooks" or "Event Subscriptions"
  2. Register a new webhook with the following details:
    • URL: Your Val Town HTTP endpoint URL (same as for Slack commands)
    • Events: Subscribe to transaction.created or similar events
    • Authentication: Follow Mercury's instructions for webhook authentication

2. Val Town Environment Variables

Set up the following environment variables in Val Town:

  1. MERCURY_API_KEY - Your Mercury API key from step 1
  2. SLACK_SIGNING_SECRET - You'll get this in step 3
  3. SLACK_WEBHOOK_URL - You'll get this in step 3

3. Slack App Setup

  1. Go to https://api.slack.com/apps and click "Create New App"
  2. Choose "From scratch" and give your app a name (e.g., "Mercury Bank")
  3. Select the workspace where you want to install the app
  4. Under "Basic Information", note your "Signing Secret" and add it to Val Town as SLACK_SIGNING_SECRET
  5. Under "Slash Commands", create a new command:
    • Command: /mercury
    • Request URL: Your Val Town HTTP endpoint URL (copy from the Val Town UI)
    • Short Description: "Interact with your Mercury bank account"
    • Usage Hint: "[balance|transactions|search] [args]"
  6. Under "Incoming Webhooks", activate incoming webhooks
    • Click "Add New Webhook to Workspace"
    • Select the channel where you want transaction notifications to appear
    • Copy the Webhook URL and add it to Val Town as SLACK_WEBHOOK_URL
  7. Under "OAuth & Permissions", add the following scopes:
    • commands - To create slash commands
    • chat:write - To post messages in channels
    • incoming-webhook - To post notifications via webhook
  8. Install the app to your workspace

4. Cron Job Configuration

The integration includes a cron job that checks for new transactions regularly:

  1. In Val Town, locate the cron.ts file
  2. Click on the "Schedule" button to set up the cron schedule
  3. Recommended: Set it to run every 15 minutes (*/15 * * * *)

5. Testing the Integration

  1. In Slack, try the command /mercury help to see available commands
  2. Try /mercury balance to see your account balances
  3. Try /mercury transactions 5 to see your 5 most recent transactions
  4. For transaction notifications:
    • If using webhooks: Make a test transaction in Mercury
    • If using polling: Wait for the cron job to run, or trigger it manually

Troubleshooting

  • If you see "An unexpected error occurred", check your Val Town logs for details
  • Ensure your Mercury API key has the correct permissions
  • Verify that your Slack app is properly configured with the correct URL
  • For transaction notifications, check that the SLACK_WEBHOOK_URL is correctly set

Security Considerations

  • Your Mercury API key has access to sensitive financial data. Keep it secure.
  • Consider implementing additional authentication if multiple users will access this integration.
  • For production use, implement proper request signature verification from Slack and Mercury.