cal.pub0.org/apps/ai
Leo Giovanetti 096b306fa2 feat: linked users with same email address 2023-10-05 11:37:55 -03:00
..
src feat: linked users with same email address 2023-10-05 11:37:55 -03:00
.env.example feat: Cal AI V1.1.0 (#11446) 2023-09-22 19:23:19 -04:00
README.md refactor: Use template literal instead of '+' operator (#11444) 2023-10-03 11:52:19 -07:00
next-env.d.ts
next.config.js perf: Removed unused queries for user event types (#10568) 2023-09-05 11:35:02 -07:00
package.json fix: prisma import in extract user route in Cal AI (#11625) 2023-09-29 13:53:38 -07:00
tsconfig.json

README.md

Cal.com Email Assistant

Welcome to the first stage of Cal.ai!

This app lets you chat with your calendar via email:

  • Turn informal emails into bookings eg. forward "wanna meet tmrw at 2pm?"
  • List and rearrange your bookings eg. "Cancel my next meeting"
  • Answer basic questions about your busiest times eg. "How does my Tuesday look?"

The core logic is contained in agent/route.ts. Here, a LangChain Agent Executor is tasked with following your instructions. Given your last-known timezone, working hours, and busy times, it attempts to CRUD your bookings.

The AI agent can only choose from a set of tools, without ever seeing your API key.

Emails are cleaned and routed in receive/route.ts using MailParser.

Incoming emails are routed by email address. Addresses are verified by DKIM record, making it hard to spoof them.

Getting Started

Development

If you haven't yet, please run the root setup steps.

Before running the app, please see env.mjs for all required environment variables. You'll need:

To stand up the API and AI apps simultaneously, simply run yarn dev:ai.

Email Router

To expose the AI app, run ngrok http 3000 (or the AI app's port number) in a new terminal. You may need to install nGrok.

To forward incoming emails to the Node.js server, one option is to use SendGrid's Inbound Parse Webhook.

  1. Sign up for an account
  2. Go to Settings > Inbound Parse > Add Host & URL.
  3. For subdomain, use <sub>.<domain>.com for now, where sub can be any subdomain but domain.com will need to be verified via MX records in your environment variables, eg. on Vercel.
  4. Use the nGrok URL from above as the Destination URL.
  5. Activate "POST the raw, full MIME message".
  6. Send an email to <anyone>@ai.example.com. You should see a ping on the nGrok listener and Node.js server.
  7. Adjust the logic in receive/route.ts, save to hot-reload, and send another email to test the behaviour.

Please feel free to improve any part of this architecture.