FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
glance
glanceTeam
Public
Like
Team
Home
Code
5
controllers
1
routes
2
README.md
C
cron.tsx
H
main.tsx
Branches
3
Pull requests
Remixes
1
History
Environment variables
2
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.
Sign up now
Code
/
Code
/
Search
README.md

Team - Notion & Val Town Integration

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.

Features

  • 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

Project Structure

├── 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

API Endpoints

Webhook Endpoint

  • POST /tasks - Notion webhook handler that enriches team member data

Manual API Endpoints

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

Setup Instructions

1. Environment Variables

Set the following environment variable in your Val Town settings:

NOTION_API_KEY=your_notion_integration_token
GLANCE_TEAM_DB_ID=your_database_id

2. Notion Database Schema

Your Notion database should have the following properties:

Property NameTypeDescription
UsernameTitleVal Town username (auto-populated)
URLURLVal Town profile URL (can be input or auto-populated)
IdRich TextVal Town user ID (auto-populated)
BioRich TextUser bio from Val Town (auto-populated)

3. Notion Integration Setup

  1. Create a new integration in your Notion workspace
  2. Add the integration to your team database
  3. Create a webhook that points to https://your-val-url.web.val.run/tasks
  4. Configure the webhook to trigger on database item creation/updates

How It Works

  1. Trigger: When a team member is added/updated in Notion, a webhook is sent to /tasks
  2. Data Retrieval: The system fetches the full page data from Notion to get the username
  3. Username Extraction: Extracts username from either:
    • The URL field (extracts from https://val.town/u/username)
    • The Username field directly
  4. Profile Fetch: Queries the Val Town API for user profile data
  5. Database Update: Updates the Notion page with the retrieved information

Usage Examples

Notion Workflow

  1. Add a new team member to your Notion database
  2. Fill in either the Username field or paste their Val Town profile URL in the URL field
  3. The webhook will automatically trigger and populate the remaining fields

Val Town Profile Data

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

Error Handling

  • 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

Development

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

Contributing

When modifying the Notion database schema, ensure you update the setPage function in controllers/controllers.ts to match your new property structure.

Code
controllersroutesREADME.md
C
cron.tsx
H
main.tsx
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.