Team
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
A simple integration that automatically enriches a Notion database of team members with their Val Town account information. When a new team member is added to your Notion database, this Val automatically fetches their Val Town profile data and populates the relevant fields.
- Automatic Profile Enrichment: Fetches Val Town user data when triggered by Notion webhooks
- Flexible Username Detection: Supports both URL-based and direct username input
- RESTful API: Provides endpoints to manually query Val Town user information
- Error Handling: Graceful handling of missing users or API failures
├── main.tsx # Main Hono app with route mounting
├── routes/
│ ├── api.ts # API endpoints for manual user queries
│ └── tasks.ts # Webhook handler for Notion integration
├── controllers/
│ └── controllers.ts # Business logic for Notion and Val Town operations
└── README.md
- POST
/tasks
- Notion webhook handler that enriches team member data
Note: these are not used in this demo but are included for demonstration purposes later.
- GET
/api/:username
- Returns JSON data for a Val Town user - GET
/api/:username/html
- Returns HTML-formatted user data - GET
/api
- API information endpoint
Set the following environment variable in your Val Town settings:
NOTION_API_KEY=your_notion_integration_token
GLANCE_TEAM_DB_ID=your_database_id
Your Notion database should have the following properties:
Property Name | Type | Description |
---|---|---|
Username | Title | Val Town username (auto-populated) |
URL | URL | Val Town profile URL (can be input or auto-populated) |
Id | Rich Text | Val Town user ID (auto-populated) |
Bio | Rich Text | User bio from Val Town (auto-populated) |
- Create a new integration in your Notion workspace
- Add the integration to your team database
- Create a webhook that points to
https://your-val-url.web.val.run/tasks
- Configure the webhook to trigger on database item creation/updates
- Trigger: When a team member is added/updated in Notion, a webhook is sent to
/tasks
- Data Retrieval: The system fetches the full page data from Notion to get the username
- Username Extraction: Extracts username from either:
- The
URL
field (extracts fromhttps://val.town/u/username
) - The
Username
field directly
- The
- Profile Fetch: Queries the Val Town API for user profile data
- Database Update: Updates the Notion page with the retrieved information
- Add a new team member to your Notion database
- Fill in either the
Username
field or paste their Val Town profile URL in theURL
field - The webhook will automatically trigger and populate the remaining fields
The integration fetches and stores the following data from Val Town:
- Username: Val Town handle
- ID: Unique user identifier
- Bio: User's profile bio (if available)
- URL: Direct link to their Val Town profile
- Profile Image URL: Link to their profile picture
- Missing Users: If a Val Town user doesn't exist, the system gracefully handles the error
- API Failures: Network issues or API errors are logged and return appropriate error responses
- Invalid Data: Malformed webhook data is handled with proper error messages
The project uses:
- Hono: Fast web framework for the API
- Val Town SDK: Official SDK for Val Town API interactions
- Notion SDK: Official SDK for Notion API operations
- TypeScript: For type safety and better development experience
When modifying the Notion database schema, ensure you update the setPage
function in controllers/controllers.ts
to match your new property structure.