commune-ai 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +76 -21
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -27,51 +27,106 @@ pnpm add commune-ai
27
27
 
28
28
  ---
29
29
 
30
+ ## How to Setup (Dashboard Steps)
31
+
32
+ **Before you can receive emails, you need to set up your domain, inbox, and API key in the Commune dashboard.**
33
+
34
+ ### 1. Create and Verify Domain
35
+ 1. Go to your [Commune dashboard](https://your-dashboard.com)
36
+ 2. Sign up and create an organization
37
+ 3. Go to **Domains** → Click **"Add Domain"**
38
+ 4. Enter a subdomain (e.g., `agent.yourcompany.com`)
39
+ 5. Click **"Create"** - DNS records will be shown
40
+ 6. Add these DNS records to your DNS provider:
41
+ ```
42
+ Type: MX Name: agent Value: feedback-smtp.us-east-1.amazonses.com Priority: 10
43
+ Type: CNAME Name: _dmarc.agent Value: _dmarc.agent.yourcompany.com
44
+ Type: TXT Name: agent Value: v=spf1 include:amazonses.com ~all
45
+ Type: TXT Name: _dmarc.agent Value: v=DMARC1; p=quarantine; rua=mailto:dmarc@yourcompany.com
46
+ ```
47
+ 7. Click **"Verify"** in the dashboard (wait 5-10 minutes for DNS propagation)
48
+
49
+ ### 2. Create Inbox
50
+ 1. In the dashboard, go to **Inboxes**
51
+ 2. Click **"Create Inbox"**
52
+ 3. Enter a local part (e.g., `support`, `help`, `agent`)
53
+ 4. This creates an email address like `support@agent.yourcompany.com`
54
+ 5. **Copy the Domain ID and Inbox ID** - you'll need these for your webhook
55
+
56
+ ### 3. Create API Key
57
+ 1. Go to **API Keys** in the dashboard
58
+ 2. Click **"Create Key"**
59
+ 3. Enter a name (e.g., "production-agent")
60
+ 4. **Copy the API key immediately** (it only shows once!)
61
+ 5. Store it securely as an environment variable
62
+
63
+ ### 4. Configure Webhook
64
+ 1. In your domain settings, go to **Webhooks**
65
+ 2. Set the webhook endpoint URL to your server's webhook handler
66
+ 3. Configure webhook events (usually "email.received")
67
+ 4. **Optional:** Set a webhook secret for verification
68
+
69
+ ### 5. Environment Variables
70
+ ```bash
71
+ # Required
72
+ COMMUNE_API_KEY=cmk_your_api_key_from_dashboard
73
+
74
+ # Optional (for self-hosting)
75
+ COMMUNE_BASE_URL=https://your-self-hosted-api.com
76
+ ```
77
+
78
+ ---
79
+
30
80
  ## Receive emails instantly
31
81
 
32
82
  Get emails delivered to your agent as structured webhook data.
33
83
 
34
84
  ```ts
85
+ import "dotenv/config";
35
86
  import express from "express";
36
87
  import { CommuneClient, createWebhookHandler } from "commune-ai";
37
88
 
89
+ // Initialize with your API key from dashboard
38
90
  const client = new CommuneClient({
39
- apiKey: process.env.COMMUNE_API_KEY,
91
+ apiKey: process.env.COMMUNE_API_KEY, // ← From Step 3 above
40
92
  });
41
93
 
94
+ // Handle incoming emails
42
95
  const handler = createWebhookHandler({
43
96
  onEvent: async (message, context) => {
44
- // Every email arrives as structured data:
45
- // message = {
46
- // channel: "email",
47
- // conversation_id: "thread_id",
48
- // participants: [{ role: "sender", identity: "user@example.com" }],
49
- // content: "Can you help with pricing?",
50
- // metadata: { subject: "Pricing Question", ... }
51
- // }
97
+ console.log(`📧 New email: ${message.content}`);
52
98
 
53
- console.log(`New email: ${message.content}`);
99
+ // Find sender's email address
100
+ const sender = message.participants.find(p => p.role === "sender")?.identity;
101
+ if (!sender) return;
54
102
 
55
103
  // Your agent logic here
56
104
  const reply = `Thanks for your email! I'll help with that.`;
57
105
 
58
106
  // Reply in the same email thread
59
- const sender = message.participants.find(p => p.role === "sender")?.identity;
60
- if (sender) {
61
- await client.messages.send({
62
- to: sender,
63
- text: reply,
64
- conversation_id: message.conversation_id,
65
- domainId: context.payload.domainId,
66
- inboxId: context.payload.inboxId,
67
- });
68
- }
107
+ await client.messages.send({
108
+ to: sender,
109
+ text: reply,
110
+ conversation_id: message.conversation_id,
111
+ domainId: context.payload.domainId, // ← From Step 2 above
112
+ inboxId: context.payload.inboxId, // ← From Step 2 above
113
+ });
114
+
115
+ console.log(`✅ Replied to: ${sender}`);
69
116
  },
70
117
  });
71
118
 
119
+ // Set up webhook endpoint
72
120
  const app = express();
73
121
  app.post("/webhook", express.raw({ type: "*/*" }), handler);
74
- app.listen(3000, () => console.log("Agent listening on :3000"));
122
+
123
+ // Health check
124
+ app.get("/health", (req, res) => res.json({ status: "ok" }));
125
+
126
+ app.listen(3000, () => {
127
+ console.log("🤖 Agent listening on port 3000");
128
+ console.log("📧 Send emails to your inbox address to test!");
129
+ });
75
130
  ```
76
131
 
77
132
  **Email structure:**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commune-ai",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Email infrastructure for AI agents - webhooks, threads, history, and semantic search",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",