cal/apps/ai
Peer Richelsen c57de8f43f
chore: more cal.ai changes (#11590)
2023-09-28 18:09:17 +00:00
..
src chore: more cal.ai changes (#11590) 2023-09-28 18:09:17 +00:00
.env.example feat: Cal AI V1.1.0 (#11446) 2023-09-22 19:23:19 -04: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 feat: Cal AI V1.1.0 (#11446) 2023-09-22 19:23:19 -04:00
README.md chore: more cal.ai changes (#11590) 2023-09-28 18:09:17 +00:00
tsconfig.json

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.