An autonomous email inbox management agent powered by ChatBotKit. Sign in with Google, connect the personal secrets required by your ChatBotKit bot, then toggle pre-defined tasks on and off to let the agent draft responses, categorize emails, and generate daily digests automatically.
Note: This template is deliberately bare-bones. It provides the minimal structure and wiring needed to get a working app, intentionally leaving styling, layout, and architectural choices open so you can build on top without fighting existing opinions.
ChatBotKit provides the conversational AI backbone that powers the Inbox Agent's email processing. Instead of building complex NLP pipelines from scratch, you get:
- Pre-built AI models for understanding email context, sentiment, and intent
- Task scheduling for automated, recurring inbox processing
- Bot customization to tailor how your inbox agent behaves
- Server-side SDK for secure, authenticated API calls
- Personal secrets for secure OAuth connection management (Gmail, etc.)
- Google OAuth Sign-In - Secure authentication using your Google account
- Dedicated Connections Page - Connect and manage the integrations required by your bot via ChatBotKit personal secrets with connect/revoke controls
- Pre-Defined Tasks - Three built-in tasks (email drafting, categorization, daily digest) that users simply toggle on or off
- Autonomous Operation - The ChatBotKit bot handles email processing through its configured abilities on automatic schedules
- ChatBotKit Integration - Powered by ChatBotKit's task, contact, and GraphQL APIs
- Next.js 16 - App Router with server actions
- ChatBotKit SDK -
@chatbotkit/sdkfor server-side operations (tasks, contacts, connections) - next-auth - Authentication with Google OAuth provider
- shadcn/ui - Accessible UI components built on Radix primitives
- Tailwind CSS - Utility-first styling
npm installCopy .env.example to .env.local and fill in the required values:
cp .env.example .env.local- Go to Google Cloud Console
- Create a new project (or select existing)
- Create OAuth 2.0 credentials (Web application type)
- Add
http://localhost:3000/api/auth/callback/googleas an authorized redirect URI - Copy the Client ID and Client Secret to your
.env.local
- Create an account at ChatBotKit
- Create a new bot with the email abilities and personal secrets your workflow needs
- Copy your API secret token from Tokens
- Add the bot ID and API secret to your
.env.local
npm run devOpen http://localhost:3000 to get started.
| Variable | Description |
|---|---|
CHATBOTKIT_API_SECRET |
Your ChatBotKit API secret token |
CHATBOTKIT_BOT_ID |
The bot ID configured with Gmail abilities |
NEXTAUTH_SECRET |
Random string for NextAuth session encryption |
NEXTAUTH_URL |
Your app URL (e.g., http://localhost:3000) |
GOOGLE_CLIENT_ID |
Google OAuth client ID (for user sign-in) |
GOOGLE_CLIENT_SECRET |
Google OAuth client secret |
- User signs in via Google OAuth (basic profile/email scopes only)
- NextAuth manages the session with JWT strategy
- Protected routes redirect unauthenticated users to the sign-in page
- After sign-in, the
/connectpage lists all personal secrets required by the configured ChatBotKit bot - Each connection shows its authentication status (connected/disconnected)
- Users click "Connect" to authenticate via OAuth popup (managed by ChatBotKit)
- OAuth callbacks are handled via
postMessageto update connection status in real time - Users can revoke connections at any time with a confirmation dialog
- Once all connections are established, the dashboard shows pre-defined tasks
- Each task has a simple on/off toggle - no configuration needed
- Turning a task on creates it in ChatBotKit with its pre-set schedule
- Turning a task off deletes it from ChatBotKit, stopping execution
- Task status (active, running, error) is displayed in real time
| Task | Description | Schedule |
|---|---|---|
| Draft Email Responses | Scans inbox, analyzes emails, and drafts replies for review | Every hour |
| Categorize & Label Emails | Categorizes emails by type and applies labels | Every hour |
| Daily Inbox Digest | Generates a summary of inbox activity and highlights | Daily |
The template leverages ChatBotKit's task system for autonomous email processing:
- Users sign in and connect their services once
- They toggle on the tasks they want the agent to perform
- The ChatBotKit task scheduler runs the bot automatically on each task's schedule
- The bot uses its Gmail abilities (via personal secrets) to process emails autonomously
- No manual intervention needed after initial setup
actions/
connections.js # Server actions: listConnections, revokeConnection
tasks.js # Server actions: getTaskStates, enableTask, disableTask + task catalog
app/
layout.jsx # Root layout with providers
page.jsx # Landing page (redirects to /connect or /auth)
auth/signin/page.jsx # Google sign-in page
connect/page.jsx # Connections page (server: lists connections + ConnectionList)
dashboard/
page.jsx # Dashboard page (server: checks connections, fetches task states)
dashboard-page.jsx # Dashboard page (client: pre-defined task toggles)
api/auth/[...nextauth]/
route.ts # NextAuth API route
components/
app/
app-header.jsx # Shared authenticated header with avatar dropdown
connections/
connection-list.jsx # Connection list with connect/revoke + OAuth callback handling
providers.jsx # Session provider wrapper
ui/
alert-dialog.jsx # Alert dialog component (Radix)
avatar.jsx # Avatar component (shadcn/ui)
button.jsx # Button component (shadcn/ui)
card.jsx # Card component (shadcn/ui)
dropdown-menu.jsx # Dropdown menu component (Radix)
separator.jsx # Separator component (shadcn/ui)
lib/
auth-options.js # NextAuth configuration
chatbotkit.js # ChatBotKit client singleton
contact.js # Contact fingerprint generation (UUID v5)
session.js # Session validation helper
utils.js # Utility functions (cn)
middleware.ts # Auth middleware for protected routes
Edit your ChatBotKit bot's backstory and abilities to customize how it processes emails:
- Gmail abilities - Configure which Gmail actions the bot can perform (read, label, draft)
- Priority detection - Configure rules for what constitutes high/medium/low priority
- Auto-labeling - Define label categories based on email content
- Response drafting - Set tone, length, and style for draft replies
To add more pre-defined tasks, edit the TASK_CATALOG array in actions/tasks.js:
{
key: 'my-task',
name: 'My Custom Task',
description: 'What the agent should do...',
schedule: '@every 1d',
icon: 'file-text',
}

