Public
Likecal-hits-bot
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
A Bluesky bot that posts whenever Seattle Mariners catcher Cal Raleigh gets a hit during a game.
The bot runs as a Val.town scheduled function every 5–10 minutes. It:
- Checks the MLB Stats API for a live or completed Mariners game
- Reads Cal Raleigh's batting stats from the boxscore
- Posts to Bluesky if a new hit or home run has occurred since the last check
- Persists hit state in Val.town blob storage to avoid duplicate posts
Home runs get special treatment — the bot fetches the season HR count and posts with extra flair.
- Runtime: Val.town (serverless, cron-scheduled)
- Bluesky:
@atproto/api - Data: MLB Stats API (free, public, no auth required)
- State: Val.town blob storage
Create an App Password in your Bluesky account settings (Settings → Privacy and Security → App Passwords). Do not use your main account password.
- Create a new Val at val.town
- Paste in the contents of
cal-hits-bot.js - Add environment variables:
BLUESKY_HANDLE— your Bluesky handle (e.g.yourbot.bsky.social)BLUESKY_PASSWORD— the App Password you created
- Set the Val type to Cron with schedule
*/5 * * * *(or whatever)
That's it. Val.town handles execution, logging, and storage.
npm install BLUESKY_HANDLE=your.handle.bsky.social BLUESKY_PASSWORD=your_app_password node cal-hits-bot.js
Change the player ID constant at the top of cal-hits-bot.js. You can look up
any player's ID from the MLB Stats API:
https://statsapi.mlb.com/api/v1/people/search?names=FirstName+LastName
You'll also want to update the team ID used for schedule lookups and the hashtags in the post template.
MIT