A Slack bot that automatically detects and previews bioRxiv and medRxiv preprint links shared in Slack channels.
- Go to https://api.slack.com/apps
- Click "Create New App" → "From scratch"
- Name your app (e.g., "bioRxiv Preview Bot") and select your workspace
- Click "Create App"
- In your app settings, go to OAuth & Permissions (left sidebar)
- Under Bot Token Scopes, add:
chat:write- To post messageslinks:read- To read shared links (required for link_shared events)
- Scroll up and click Install to Workspace
- Authorize the app and copy the Bot User OAuth Token (starts with
xoxb-)- This is your
SLACK_BOT_TOKEN
- This is your
Important: Slack only sends
link_sharedevents for domains you register for unfurling. This step is required!
- In your app settings, go to Event Subscriptions (left sidebar)
- Scroll down to find App unfurl domains (or look for "Unfurl domains" in the left sidebar under Features)
- Add the following domains:
biorxiv.orgmedrxiv.orgcell.comsciencedirect.com
- After adding domains, you MUST reinstall the app:
- Go to OAuth & Permissions
- Click Reinstall to Workspace
- Authorize the app again
- Without this step, Slack will NOT send
link_sharedevents for bioRxiv/medRxiv links!
Important: The bot will NOT work without subscribing to bot events. This step is required!
- Go to Event Subscriptions (left sidebar)
- Toggle Enable Events to ON
- Set Request URL to your Vercel deployment URL (you'll update this after deployment):
- Format:
https://your-project.vercel.app/api/slack-events - For now, you can use a placeholder or come back after deployment
- Format:
- Subscribe to bot events (this is required!):
- Scroll down to Subscribe to bot events
- Click Add Bot User Event
- Add:
link_shared- This allows the bot to detect when links are shared - Without this event, the bot will not receive notifications about shared links
- Click Save Changes
- In your app settings, go to Basic Information
- Under App Credentials, copy the Signing Secret
- This is your
SLACK_SIGNING_SECRET
- This is your
-
Install Vercel CLI (if not already installed):
npm i -g vercel
-
Login to Vercel:
vercel login
-
Deploy the project:
vercel
- Follow the prompts to link/create your project
- Note the deployment URL (e.g.,
https://your-project.vercel.app)
-
Go to your project on vercel.com
-
Navigate to Settings → Environment Variables
-
Add the following variables:
SLACK_SIGNING_SECRET- Your Slack app's signing secretSLACK_BOT_TOKEN- Your bot's OAuth token (starts withxoxb-)PAPERS_CHANNEL_ID(optional) - Channel ID to restrict bot to specific channel
-
Redeploy after adding environment variables:
vercel --prod
- Go back to your Slack app settings → Event Subscriptions
- Update the Request URL to:
https://your-project.vercel.app/api/slack-events - Slack will verify the URL (should show a green checkmark)
- Verify bot events subscription:
- Scroll down to Subscribe to bot events
- Make sure
link_sharedis listed (if not, add it now) - This is required for the bot to work!
- Click Save Changes
- In Slack, go to the channel where you want the bot to work
- Type
/invite @YourBotNameor add the bot through channel settings - The bot will now respond to bioRxiv/medRxiv links shared in that channel
If you want the bot to only work in a specific channel (e.g., #papers):
- Get the channel ID:
- Right-click the channel → "View channel details" → Copy the Channel ID
- Or use the Slack API to get it
- Set the
PAPERS_CHANNEL_IDenvironment variable in Vercel to that channel ID - Redeploy
- Share a bioRxiv or medRxiv link in your Slack channel
- The bot should automatically post a preview with title, authors, and abstract
npm install
vercel devThis will start a local server. You'll need to use a tool like ngrok to expose it to Slack for testing.
If you post a link but see no logs at all in Vercel, Slack isn't calling your endpoint. Check these in order:
-
Verify Endpoint is Reachable
- Visit
https://your-project.vercel.app/api/slack-eventsin your browser - You should see a JSON response with environment variable status
- If you get an error, the deployment may have failed
- Visit
-
Check Slack Event Subscriptions Configuration
- Go to your Slack app → Event Subscriptions
- Verify Enable Events is toggled ON (green toggle at the top)
- Check the Request URL field - it should show a green checkmark ✅ next to it
- If there's a red X or error message, the URL verification failed
- The URL must be exactly:
https://your-project.vercel.app/api/slack-events - Try clicking "Save Changes" - Slack will attempt to verify the URL
- If verification fails, check that your Vercel deployment is live and the endpoint is accessible
-
Verify Bot Events Subscription
- In Event Subscriptions, scroll to Subscribe to bot events
- Ensure
link_sharedis listed (if not, add it and save) - This is the #1 reason events don't fire!
-
Check Bot is in Channel
- The bot must be invited to the channel where you're posting
- Type
/invite @YourBotNamein the channel - Or add the bot through channel settings → Integrations
- This is critical - the bot won't receive events if it's not in the channel!
-
Verify Bot Token Scopes
- Go to OAuth & Permissions
- Ensure
chat:writescope is added - If you added scopes after installation, click Reinstall to Workspace
-
Test the URL Verification
- Since the endpoint is reachable (you can see the health check), verify the Request URL in Slack:
- In Event Subscriptions, check if the Request URL shows a green checkmark ✅
- If it shows a red X or error, the URL might be incorrect
- To trigger a new verification: add a space to the Request URL, then remove it, then click "Save Changes"
- Or try changing the URL slightly and changing it back
- After saving, check your Vercel logs - you should see a
url_verificationevent - If you see the verification event in logs, Slack can reach your endpoint
-
Test with a Direct Message
- Try posting a bioRxiv link in a DM with the bot
- This helps isolate channel permission issues
- Make sure the bot can receive DMs (check app settings)
-
Important: How
link_sharedEvents Work- The
link_sharedevent only fires when Slack unfurls (previews) a link - If link previews are disabled in your workspace/channel, the event won't fire
- Try posting a link and wait a few seconds for Slack to unfurl it
- Make sure link previews are enabled in your Slack workspace settings
- The event fires when Slack processes the link for preview, not immediately when posted
- The
-
Double-Check the Most Common Issues
- ✅
link_sharedevent is subscribed (Event Subscriptions → Subscribe to bot events) - ✅ Bot is invited to the channel
- ✅ Request URL has a green checkmark in Slack
- ✅ Enable Events is toggled ON
- ✅ Link previews are enabled in Slack
- ✅
-
Bot not responding (but logs show events):
- Check that the bot is invited to the channel
- Verify
link_sharedevent is subscribed - Check Vercel logs for API errors
-
Signature verification failed:
- Verify
SLACK_SIGNING_SECRETenvironment variable is set correctly in Vercel - Make sure there are no extra spaces when copying the secret
- Verify
-
No preview posted (but handler is called):
- Check Vercel function logs for errors
- Ensure
link_sharedbot event is subscribed (most common issue!) - Verify the link is a valid bioRxiv/medRxiv URL with a DOI
-
URL verification failed:
- Ensure the Request URL in Slack matches your Vercel deployment URL exactly
- No trailing slashes, correct protocol (https), correct path