Skip to content

Commit 9817ebb

Browse files
committed
[Components] vida #14121
Sources - New Incoming Conversation (Instant) - New Conversation (Instant) Actions - Provide Context
1 parent dcbaac7 commit 9817ebb

File tree

8 files changed

+215
-206
lines changed

8 files changed

+215
-206
lines changed
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import vida from "../../vida.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "vida-provide-context",
6-
name: "Upload Additional Context for Conversation",
5+
name: "Add Context",
76
description: "Uploads additional context for a conversation with your AI agent. Helpful when integrating data from external CRMs. [See the documentation](https://vida.io/docs/api-reference/knowledge/add-context)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
vida,
12-
aiAgentId: {
13-
propDefinition: [
14-
vida,
15-
"aiAgentId",
16-
],
11+
target: {
12+
type: "string",
13+
label: "Target",
14+
description: "Phone number in E.164 format or VIDA username of the user.",
1715
},
18-
additionalContext: {
19-
propDefinition: [
20-
vida,
21-
"additionalContext",
22-
],
16+
context: {
17+
type: "string",
18+
label: "Context",
19+
description: "Context information to inject",
2320
},
2421
},
2522
async run({ $ }) {
26-
const response = await this.vida.uploadConversationContext({
27-
aiAgentId: this.aiAgentId,
28-
additionalContext: this.additionalContext,
23+
const response = await this.vida.addContext({
24+
$,
25+
data: {
26+
target: this.target,
27+
context: this.context,
28+
},
2929
});
30-
$.export("$summary", `Successfully uploaded additional context for AI agent ${this.aiAgentId}`);
30+
$.export("$summary", `Successfully uploaded additional context for target ${this.target}`);
3131
return response;
3232
},
3333
};

components/vida/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/vida",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Vida Components",
55
"main": "vida.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import vida from "../../vida.app.mjs";
2+
3+
export default {
4+
props: {
5+
vida,
6+
http: {
7+
type: "$.interface.http",
8+
customResponse: false,
9+
},
10+
db: "$.service.db",
11+
label: {
12+
type: "string",
13+
label: "Label",
14+
description: "Friendly label for webhook",
15+
},
16+
},
17+
methods: {
18+
filterEvent() {
19+
return true;
20+
},
21+
},
22+
hooks: {
23+
async activate() {
24+
await this.vida.createWebhook({
25+
data: {
26+
url: this.http.endpoint,
27+
label: this.label,
28+
type: "conversation",
29+
},
30+
});
31+
},
32+
async deactivate() {
33+
await this.vida.deleteWebhook({
34+
data: {
35+
url: this.http.endpoint,
36+
},
37+
});
38+
},
39+
},
40+
async run({ body }) {
41+
if (this.filterEvent(body)) {
42+
this.$emit(body, {
43+
id: body.uuid,
44+
summary: this.getSummary(body),
45+
ts: body.timestamp,
46+
});
47+
}
48+
},
49+
};
Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,19 @@
1-
import vida from "../../vida.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
33

44
export default {
5+
...common,
56
key: "vida-new-conversation-instant",
6-
name: "New Conversation Instant",
7-
description: "Emit new events after completion of any communication handled by your Vida AI agent, be it a call, text, or email. [See the documentation](https://vida.io/docs/api-reference/webhooks/add-webhook)",
8-
version: "0.0.{{ts}}",
7+
name: "New Conversation (Instant)",
8+
description: "Emit new events after completion of any communication handled by your Vida AI agent, be it a call, text, or email.",
9+
version: "0.0.1",
910
type: "source",
1011
dedupe: "unique",
11-
props: {
12-
vida,
13-
http: {
14-
type: "$.interface.http",
15-
customResponse: true,
12+
methods: {
13+
...common.methods,
14+
getSummary(event) {
15+
return `New conversation created: ${event.uuid}`;
1616
},
17-
db: "$.service.db",
18-
},
19-
hooks: {
20-
async deploy() {
21-
// No historical data to fetch
22-
},
23-
async activate() {
24-
const webhookId = await this.vida._makeRequest({
25-
method: "POST",
26-
path: "/webhooks",
27-
data: {
28-
url: this.http.endpoint,
29-
label: "Pipedream Webhook",
30-
type: "conversation",
31-
},
32-
});
33-
this.db.set("webhookId", webhookId);
34-
},
35-
async deactivate() {
36-
const webhookId = this.db.get("webhookId");
37-
await this.vida._makeRequest({
38-
method: "DELETE",
39-
path: `/webhooks/${webhookId}`,
40-
});
41-
},
42-
},
43-
async run(event) {
44-
console.log("Emitting event...");
45-
this.$emit(event.body, {
46-
id: event.body.id || event.body.timestamp || new Date().toISOString(),
47-
summary: `New communication event: ${event.body.type}`,
48-
ts: Date.parse(event.body.timestamp) || Date.now(),
49-
});
5017
},
18+
sampleEmit,
5119
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export default {
2+
"from": 999999999999,
3+
"fromUser": "integrations__test",
4+
"to": 1269579,
5+
"toUser": "integrations",
6+
"rate": 0,
7+
"usdRate": 0,
8+
"timestamp": 1727728969,
9+
"date": "2024-09-30T20:42:49.000Z",
10+
"message": "Call from integrations",
11+
"content-type": "text/plain",
12+
"disposition-notification": null,
13+
"roomId": "1269579:1269579",
14+
"status": "success",
15+
"attachments": [],
16+
"isLive": false,
17+
"aiAgent": false,
18+
"aiReward": null,
19+
"aiRewardUsd": null,
20+
"aiLeadRating": null,
21+
"aiLeadRatingReason": null,
22+
"aiAgentOverride": null,
23+
"gift": false,
24+
"source": "call",
25+
"uuid": "86547d26-9b89-41a6-afd1-292085c9b846",
26+
"campaignId": "campa861346f6104e3e4762ef5b936e2984fb",
27+
"fromNumber": "+1234567890",
28+
"toNumber": "integrations",
29+
"notify": false,
30+
"targetInbox": "inbox",
31+
"type": "call",
32+
"duration": 1,
33+
"direction": "outbound",
34+
"missedCall": false,
35+
"bypassAgent": false,
36+
"cnamSpam": false,
37+
"selfCall": true,
38+
"callingUserIsContact": false,
39+
"agentOutcome": null,
40+
"summary": null,
41+
"callDialog": [],
42+
"campaign": true,
43+
"diversion": null,
44+
"voicemailRecording": null,
45+
"eventType": "outbound-call",
46+
"forcedCampaign": true,
47+
"conversation": "",
48+
"collectedData": null,
49+
"functionsRun": []
50+
}
Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,22 @@
1-
import vida from "../../vida.app.mjs";
2-
import crypto from "crypto";
3-
import { axios } from "@pipedream/platform";
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
43

54
export default {
5+
...common,
66
key: "vida-new-incoming-conversation-instant",
7-
name: "New Incoming Conversation Instant",
8-
description: "Emit a new event when an incoming call or message is received before answered by an agent. Useful for providing context about the caller or messenger to your agent before response. [See the documentation](https://vida.io/docs/api-reference/webhooks/add-webhook)",
9-
version: "0.0.{{ts}}",
7+
name: "New Incoming Conversation (Instant)",
8+
description: "Emit new event when an incoming call or message is received before answered by an agent. Useful for providing context about the caller or messenger to your agent before response.",
9+
version: "0.0.1",
1010
type: "source",
1111
dedupe: "unique",
12-
props: {
13-
vida,
14-
http: {
15-
type: "$.interface.http",
16-
customResponse: true,
17-
},
18-
db: "$.service.db",
19-
agent: {
20-
propDefinition: [
21-
vida,
22-
"agent",
23-
],
24-
},
25-
communicationSource: {
26-
propDefinition: [
27-
vida,
28-
"communicationSource",
29-
],
30-
},
31-
},
3212
methods: {
33-
async activate() {
34-
const webhookResponse = await this.vida._makeRequest({
35-
method: "POST",
36-
path: "/webhooks",
37-
data: {
38-
url: this.http.endpoint,
39-
label: "Pipedream Vida Webhook",
40-
type: "conversation",
41-
},
42-
});
43-
this.db.set("webhookId", webhookResponse.id);
13+
...common.methods,
14+
getSummary(event) {
15+
return `New incoming ${event.body.communicationSource} from ${event.body.source}`;
4416
},
45-
async deactivate() {
46-
const webhookId = this.db.get("webhookId");
47-
if (webhookId) {
48-
await this.vida._makeRequest({
49-
method: "DELETE",
50-
path: `/webhooks/${webhookId}`,
51-
});
52-
}
17+
filterEvents(body) {
18+
return body.direction === "inbound";
5319
},
5420
},
55-
async run(event) {
56-
const computedSignature = crypto.createHmac("sha256", this.vida.$auth.api_token).update(event.body.rawBody)
57-
.digest("base64");
58-
if (computedSignature !== event.headers["x-vida-signature"]) {
59-
this.http.respond({
60-
status: 401,
61-
body: "Unauthorized",
62-
});
63-
return;
64-
}
65-
this.http.respond({
66-
status: 200,
67-
body: "OK",
68-
});
69-
this.$emit(event.body, {
70-
id: event.body.id,
71-
summary: `New incoming ${event.body.communicationSource} from ${event.body.source}`,
72-
ts: Date.now(),
73-
});
74-
},
21+
sampleEmit,
7522
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export default {
2+
"from": 999999999999,
3+
"fromUser": "integrations__test",
4+
"to": 1269579,
5+
"toUser": "integrations",
6+
"rate": 0,
7+
"usdRate": 0,
8+
"timestamp": 1727728969,
9+
"date": "2024-09-30T20:42:49.000Z",
10+
"message": "Call from integrations",
11+
"content-type": "text/plain",
12+
"disposition-notification": null,
13+
"roomId": "1269579:1269579",
14+
"status": "success",
15+
"attachments": [],
16+
"isLive": false,
17+
"aiAgent": false,
18+
"aiReward": null,
19+
"aiRewardUsd": null,
20+
"aiLeadRating": null,
21+
"aiLeadRatingReason": null,
22+
"aiAgentOverride": null,
23+
"gift": false,
24+
"source": "call",
25+
"uuid": "86547d26-9b89-41a6-afd1-292085c9b846",
26+
"campaignId": "campa861346f6104e3e4762ef5b936e2984fb",
27+
"fromNumber": "+1234567890",
28+
"toNumber": "integrations",
29+
"notify": false,
30+
"targetInbox": "inbox",
31+
"type": "call",
32+
"duration": 1,
33+
"direction": "inbound",
34+
"missedCall": false,
35+
"bypassAgent": false,
36+
"cnamSpam": false,
37+
"selfCall": true,
38+
"callingUserIsContact": false,
39+
"agentOutcome": null,
40+
"summary": null,
41+
"callDialog": [],
42+
"campaign": true,
43+
"diversion": null,
44+
"voicemailRecording": null,
45+
"eventType": "inbound-call",
46+
"forcedCampaign": true,
47+
"conversation": "",
48+
"collectedData": null,
49+
"functionsRun": []
50+
}

0 commit comments

Comments
 (0)