commune-ai 0.2.0 → 0.2.1
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.
- package/README.md +39 -40
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# commune-ai
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Our email infrastructure**
|
|
4
4
|
|
|
5
5
|
Build agents that receive emails, reply in threads, access conversation history, and search across all organizational emails. Most teams get their first agent responding in **~15 minutes**.
|
|
6
6
|
|
|
@@ -29,7 +29,6 @@ Build agents that receive emails, reply in threads, access conversation history,
|
|
|
29
29
|
- [Reply in email threads](#reply-in-email-threads)
|
|
30
30
|
- [Access conversation history](#access-conversation-history)
|
|
31
31
|
- [Manage Inboxes Programmatically](#manage-inboxes-programmatically)
|
|
32
|
-
- [How Webhooks Work](#how-webhooks-work)
|
|
33
32
|
- [Handle different types of emails](#handle-different-types-of-emails)
|
|
34
33
|
- [Semantic Search (Coming Soon)](#semantic-search-coming-soon)
|
|
35
34
|
- [Complete example](#complete-example)
|
|
@@ -302,52 +301,52 @@ await client.inboxes.remove(domainId, inboxId);
|
|
|
302
301
|
|
|
303
302
|
---
|
|
304
303
|
|
|
305
|
-
##
|
|
304
|
+
## Handle different inbox emails
|
|
306
305
|
|
|
307
|
-
|
|
306
|
+
Set up separate webhook endpoints for different inboxes:
|
|
308
307
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
308
|
+
```ts
|
|
309
|
+
const client = new CommuneClient({
|
|
310
|
+
apiKey: process.env.COMMUNE_API_KEY,
|
|
311
|
+
});
|
|
312
312
|
|
|
313
|
-
|
|
314
|
-
// Webhook flow: Resend → Commune Backend → Your Server
|
|
315
|
-
// Your server uses createWebhookHandler to process webhooks from Commune
|
|
316
|
-
```
|
|
313
|
+
const app = express();
|
|
317
314
|
|
|
318
|
-
|
|
315
|
+
// Sales inbox webhook - handles sales@yourdomain.com
|
|
316
|
+
app.post("/webhook/sales", express.raw({ type: "*/*" }), createWebhookHandler({
|
|
317
|
+
onEvent: async (message, context) => {
|
|
318
|
+
const sender = message.participants.find(p => p.role === "sender")?.identity;
|
|
319
|
+
if (!sender) return;
|
|
319
320
|
|
|
320
|
-
|
|
321
|
+
await client.messages.send({
|
|
322
|
+
to: sender,
|
|
323
|
+
text: "Thanks for your sales inquiry!",
|
|
324
|
+
conversation_id: message.conversation_id,
|
|
325
|
+
domainId: context.payload.domainId,
|
|
326
|
+
inboxId: context.payload.inboxId,
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
}));
|
|
321
330
|
|
|
322
|
-
|
|
323
|
-
app.post("/webhook", express.raw({ type: "*/*" }), createWebhookHandler({
|
|
331
|
+
// Marketing inbox webhook - handles marketing@yourdomain.com
|
|
332
|
+
app.post("/webhook/marketing", express.raw({ type: "*/*" }), createWebhookHandler({
|
|
324
333
|
onEvent: async (message, context) => {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
domainId: context.payload.domainId,
|
|
336
|
-
inboxId: context.payload.inboxId,
|
|
337
|
-
});
|
|
338
|
-
} else if (inboxAddress?.includes("sales")) {
|
|
339
|
-
// Handle sales emails
|
|
340
|
-
const sender = message.participants.find(p => p.role === "sender")?.identity;
|
|
341
|
-
await client.messages.send({
|
|
342
|
-
to: sender,
|
|
343
|
-
text: "Thanks for your sales inquiry!",
|
|
344
|
-
conversation_id: message.conversation_id,
|
|
345
|
-
domainId: context.payload.domainId,
|
|
346
|
-
inboxId: context.payload.inboxId,
|
|
347
|
-
});
|
|
348
|
-
}
|
|
334
|
+
const sender = message.participants.find(p => p.role === "sender")?.identity;
|
|
335
|
+
if (!sender) return;
|
|
336
|
+
|
|
337
|
+
await client.messages.send({
|
|
338
|
+
to: sender,
|
|
339
|
+
text: "Thanks for subscribing to our newsletter!",
|
|
340
|
+
conversation_id: message.conversation_id,
|
|
341
|
+
domainId: context.payload.domainId,
|
|
342
|
+
inboxId: context.payload.inboxId,
|
|
343
|
+
});
|
|
349
344
|
},
|
|
350
345
|
}));
|
|
346
|
+
|
|
347
|
+
app.listen(3000, () => {
|
|
348
|
+
console.log("Agent running on port 3000");
|
|
349
|
+
});
|
|
351
350
|
```
|
|
352
351
|
|
|
353
352
|
---
|
|
@@ -368,7 +367,7 @@ const results = await client.search({
|
|
|
368
367
|
query: "What were the pricing questions from last week?",
|
|
369
368
|
limit: 10,
|
|
370
369
|
threshold: 0.7, // Similarity threshold 0-1
|
|
371
|
-
before: "2024-12-31", // Only search
|
|
370
|
+
before: "2024-12-31", // Only search emails before this date
|
|
372
371
|
sender: "customer@example.com", // Filter by sender (optional)
|
|
373
372
|
});
|
|
374
373
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commune-ai",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Our email infrastructure - webhooks, threads, history, and semantic search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|