Skip to content

Commit dcbaac7

Browse files
committed
vida init
1 parent a3c822c commit dcbaac7

File tree

5 files changed

+256
-3
lines changed

5 files changed

+256
-3
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import vida from "../../vida.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "vida-provide-context",
6+
name: "Upload Additional Context for Conversation",
7+
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}}",
9+
type: "action",
10+
props: {
11+
vida,
12+
aiAgentId: {
13+
propDefinition: [
14+
vida,
15+
"aiAgentId",
16+
],
17+
},
18+
additionalContext: {
19+
propDefinition: [
20+
vida,
21+
"additionalContext",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.vida.uploadConversationContext({
27+
aiAgentId: this.aiAgentId,
28+
additionalContext: this.additionalContext,
29+
});
30+
$.export("$summary", `Successfully uploaded additional context for AI agent ${this.aiAgentId}`);
31+
return response;
32+
},
33+
};

components/vida/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import vida from "../../vida.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
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}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
vida,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: true,
16+
},
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+
});
50+
},
51+
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import vida from "../../vida.app.mjs";
2+
import crypto from "crypto";
3+
import { axios } from "@pipedream/platform";
4+
5+
export default {
6+
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}}",
10+
type: "source",
11+
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+
},
32+
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);
44+
},
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+
}
53+
},
54+
},
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+
},
75+
};

components/vida/vida.app.mjs

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,105 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "vida",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
agent: {
8+
type: "string",
9+
label: "Agent",
10+
description: "The agent handling the communication",
11+
async options({ prevContext }) {
12+
const page = prevContext?.page || 1;
13+
const response = await this._makeRequest({
14+
method: "GET",
15+
path: "/agents",
16+
params: {
17+
page,
18+
},
19+
});
20+
const options = response.map((agent) => ({
21+
label: agent.name,
22+
value: agent.id,
23+
}));
24+
return {
25+
options,
26+
context: {
27+
page: page + 1,
28+
},
29+
};
30+
},
31+
},
32+
communicationSource: {
33+
type: "string",
34+
label: "Communication Source",
35+
description: "The source of the communication",
36+
options: [
37+
"call",
38+
"text",
39+
"email",
40+
],
41+
},
42+
aiAgentId: {
43+
type: "string",
44+
label: "AI Agent Identity",
45+
description: "The identity of the AI agent the additional context is for",
46+
},
47+
additionalContext: {
48+
type: "string",
49+
label: "Additional Context",
50+
description: "The additional context information to upload",
51+
},
52+
},
553
methods: {
6-
// this.$auth contains connected account data
754
authKeys() {
855
console.log(Object.keys(this.$auth));
956
},
57+
_baseUrl() {
58+
return "https://api.vida.dev/api/v2";
59+
},
60+
async _makeRequest(opts = {}) {
61+
const {
62+
$ = this, method = "GET", path = "/", headers, ...otherOpts
63+
} = opts;
64+
return axios($, {
65+
...otherOpts,
66+
method,
67+
url: `${this._baseUrl()}${path}`,
68+
headers: {
69+
...headers,
70+
Authorization: `Bearer ${this.$auth.api_token}`,
71+
},
72+
});
73+
},
74+
async emitIncomingCommunicationEvent({
75+
agent, communicationSource,
76+
}) {
77+
return this._makeRequest({
78+
method: "POST",
79+
path: "/communication/incoming",
80+
data: {
81+
agent,
82+
source: communicationSource,
83+
},
84+
});
85+
},
86+
async emitCompletedCommunicationEvent() {
87+
return this._makeRequest({
88+
method: "POST",
89+
path: "/communication/completed",
90+
});
91+
},
92+
async uploadConversationContext({
93+
aiAgentId, additionalContext,
94+
}) {
95+
return this._makeRequest({
96+
method: "POST",
97+
path: "/context",
98+
data: {
99+
target: aiAgentId,
100+
context: additionalContext,
101+
},
102+
});
103+
},
10104
},
11105
};

0 commit comments

Comments
 (0)