commune-ai 0.1.3 → 0.1.5

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 +171 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -36,14 +36,8 @@ pnpm add commune-ai
36
36
  2. Sign up and create an organization
37
37
  3. Go to **Domains** → Click **"Add Domain"**
38
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
- ```
39
+ 5. Click **"Create"** - The dashboard will show DNS records to add
40
+ 6. Add the DNS records shown in the dashboard to your DNS provider
47
41
  7. Click **"Verify"** in the dashboard (wait 5-10 minutes for DNS propagation)
48
42
 
49
43
  ### 2. Create Inbox
@@ -226,11 +220,179 @@ const searchResults = await client.search({
226
220
  });
227
221
 
228
222
  console.log(`Found ${searchResults.length} relevant emails`);
229
- for (const result of searchResults) {
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Manage Inboxes Programmatically
228
+
229
+ Create and manage email inboxes for your agents programmatically.
230
+
231
+ ### Create Multiple Inboxes
232
+
233
+ Set up different inboxes for different purposes:
234
+
235
+ ```ts
236
+ import { CommuneClient } from "commune-ai";
237
+
238
+ const client = new CommuneClient({
239
+ apiKey: process.env.COMMUNE_API_KEY,
240
+ });
241
+
242
+ // Create inboxes for different departments
243
+ async function setupInboxes(domainId: string) {
244
+ const supportInbox = await client.inboxes.create(domainId, {
245
+ localPart: "support", // Creates support@yourdomain.com
246
+ agent: {
247
+ id: "support-agent",
248
+ name: "Support Bot",
249
+ metadata: { department: "customer-success" }
250
+ },
251
+ status: "active",
252
+ });
253
+
254
+ const salesInbox = await client.inboxes.create(domainId, {
255
+ localPart: "sales", // Creates sales@yourdomain.com
256
+ agent: {
257
+ id: "sales-agent",
258
+ name: "Sales Bot",
259
+ metadata: { department: "sales" }
260
+ },
261
+ status: "active",
262
+ });
263
+
264
+ return { supportInbox, salesInbox };
265
+ }
266
+ ```
267
+
268
+ ### Set Webhooks for Specific Inboxes
269
+
270
+ Configure webhooks per inbox to route emails to different handlers:
271
+
272
+ ```ts
273
+ async function configureWebhooks(domainId: string, inboxes: any) {
274
+ // Support inbox webhook
275
+ await client.inboxes.setWebhook(domainId, inboxes.supportInbox.id, {
276
+ endpoint: "https://your-api.com/webhooks/support",
277
+ events: ["email.received"],
278
+ });
279
+
280
+ // Sales inbox webhook
281
+ await client.inboxes.setWebhook(domainId, inboxes.salesInbox.id, {
282
+ endpoint: "https://your-api.com/webhooks/sales",
283
+ events: ["email.received"],
284
+ });
285
+ }
286
+ ```
287
+
288
+ ### List and Manage Inboxes
289
+
290
+ ```ts
291
+ // List all inboxes for a domain
292
+ const inboxes = await client.inboxes.list(domainId);
293
+ console.log(`Found ${inboxes.length} inboxes`);
294
+
295
+ // Update an inbox
296
+ await client.inboxes.update(domainId, inboxId, {
297
+ localPart: "help", // Change from "support" to "help"
298
+ status: "active",
299
+ });
300
+
301
+ // Delete an inbox
302
+ await client.inboxes.remove(domainId, inboxId);
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Listen for Specific Inbox Events
308
+
309
+ Route incoming emails based on which inbox received them:
310
+
311
+ ```ts
312
+ import { createWebhookHandler } from "commune-ai";
313
+
314
+ const handler = createWebhookHandler({
315
+ onEvent: async (message, context) => {
316
+ const { inboxId, inboxAddress } = context.payload;
317
+
318
+ console.log(`📧 Email received at: ${inboxAddress}`);
319
+
320
+ // Route to different handlers based on inbox
321
+ if (inboxAddress?.includes("support")) {
322
+ await handleSupportEmail(message, context);
323
+ } else if (inboxAddress?.includes("sales")) {
324
+ await handleSalesEmail(message, context);
325
+ } else {
326
+ // Default handler for other inboxes
327
+ await handleGeneralEmail(message, context);
328
+ }
329
+ },
330
+ });
331
+
332
+ // Example handlers
333
+ async function handleSupportEmail(message: any, context: any) {
334
+ const sender = message.participants.find(p => p.role === "sender")?.identity;
335
+ if (sender) {
336
+ await client.messages.send({
337
+ to: sender,
338
+ text: "Thanks for contacting support! We'll get back to you soon.",
339
+ conversation_id: message.conversation_id,
340
+ domainId: context.payload.domainId,
341
+ inboxId: context.payload.inboxId,
342
+ });
343
+ }
344
+ }
345
+
346
+ async function handleSalesEmail(message: any, context: any) {
347
+ const sender = message.participants.find(p => p.role === "sender")?.identity;
348
+ if (sender) {
349
+ await client.messages.send({
350
+ to: sender,
351
+ text: "Thanks for your interest! A sales representative will contact you.",
352
+ conversation_id: message.conversation_id,
353
+ domainId: context.payload.domainId,
354
+ inboxId: context.payload.inboxId,
355
+ });
356
+ }
357
+ }
358
+ ```
359
+
360
+ ---
361
+
362
+ ## Semantic Search (Coming Soon)
363
+
364
+ Search across all emails in your organization using natural language queries.
365
+
366
+ ```ts
367
+ import { CommuneClient } from "commune-ai";
368
+
369
+ const client = new CommuneClient({
370
+ apiKey: process.env.COMMUNE_API_KEY,
371
+ });
372
+
373
+ // Find emails similar to a query
374
+ const results = await client.search({
375
+ query: "What were the pricing questions from last week?",
376
+ limit: 10,
377
+ threshold: 0.7, // Similarity threshold 0-1
378
+ before: "2024-12-31", // Only search recent emails
379
+ sender: "customer@example.com", // Filter by sender (optional)
380
+ });
381
+
382
+ console.log(`Found ${results.length} relevant emails:`);
383
+ for (const result of results) {
230
384
  console.log(`Match (${result.similarity.toFixed(2)}): ${result.message.content}`);
385
+ console.log(`Highlights: ${result.highlights.join(", ")}`);
231
386
  }
232
387
  ```
233
388
 
389
+ **What you get:**
390
+ - **Natural language queries** - Search like "pricing issues from enterprise customers"
391
+ - **Similarity scores** - Ranked results by relevance (0-1)
392
+ - **Highlighted matches** - Text snippets showing why the email matched
393
+ - **Filtering options** - By date range, sender, or other criteria
394
+ - **Fast results** - AI-powered semantic matching
395
+
234
396
  ---
235
397
 
236
398
  ## Complete agent example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commune-ai",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Email infrastructure for AI agents - webhooks, threads, history, and semantic search",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",