Skip to content

Commit fb4189f

Browse files
committed
init
1 parent ac0a92f commit fb4189f

File tree

7 files changed

+360
-3
lines changed

7 files changed

+360
-3
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import insertchat from "../../insertchat.app.mjs";
2+
3+
export default {
4+
key: "insertchat-create-lead",
5+
name: "Create Lead",
6+
description: "Creates a new lead within Insertchat.",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
insertchat,
11+
leadContactInfo: {
12+
propDefinition: [
13+
insertchat,
14+
"leadContactInfo",
15+
],
16+
},
17+
leadStatus: {
18+
propDefinition: [
19+
insertchat,
20+
"leadStatus",
21+
],
22+
optional: true,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.insertchat.createNewLead(this.leadContactInfo, this.leadStatus);
27+
$.export("$summary", `Created lead with ID: ${response.id}`);
28+
return response;
29+
},
30+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import insertchat from "../../insertchat.app.mjs";
2+
3+
export default {
4+
key: "insertchat-delete-lead",
5+
name: "Delete Lead",
6+
description: "Deletes an existing lead from InsertChat. [See the documentation](https://docs.insertchat.com/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
insertchat,
11+
leadId: {
12+
propDefinition: [
13+
insertchat,
14+
"leadId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.insertchat.deleteLead(this.leadId);
20+
$.export("$summary", `Successfully deleted lead with ID: ${this.leadId}`);
21+
return response;
22+
},
23+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import insertchat from "../../insertchat.app.mjs";
2+
3+
export default {
4+
key: "insertchat-push-message-existing-chat",
5+
name: "Push Message to Existing Chat",
6+
description: "Pushes a new message into an existing chat session in InsertChat",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
insertchat,
11+
chatSessionId: {
12+
propDefinition: [
13+
insertchat,
14+
"chatSessionId",
15+
],
16+
},
17+
messageContent: {
18+
propDefinition: [
19+
insertchat,
20+
"messageContent",
21+
],
22+
},
23+
messageSender: {
24+
propDefinition: [
25+
insertchat,
26+
"messageSender",
27+
],
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.insertchat.pushMessage(
33+
this.chatSessionId,
34+
this.messageContent,
35+
this.messageSender,
36+
);
37+
$.export("$summary", `Successfully pushed message to chat session ${this.chatSessionId}`);
38+
return response;
39+
},
40+
};
Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,126 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "insertchat",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
leadContactInfo: {
8+
type: "object",
9+
label: "Lead Contact Information",
10+
description: "The contact information for the lead (name, email, phone, etc.)",
11+
required: true,
12+
},
13+
leadStatus: {
14+
type: "string",
15+
label: "Lead Status",
16+
description: "The status of the lead (new, in-progress, converted)",
17+
optional: true,
18+
},
19+
leadId: {
20+
type: "string",
21+
label: "Lead ID",
22+
description: "The unique identifier for the lead",
23+
required: true,
24+
},
25+
chatSessionId: {
26+
type: "string",
27+
label: "Chat Session ID",
28+
description: "The unique identifier for the chat session",
29+
required: true,
30+
},
31+
messageContent: {
32+
type: "string",
33+
label: "Message Content",
34+
description: "The content of the message to be pushed into the chat session",
35+
required: true,
36+
},
37+
messageSender: {
38+
type: "string",
39+
label: "Message Sender",
40+
description: "The sender of the message (user or ai)",
41+
optional: true,
42+
},
43+
userInfo: {
44+
type: "object",
45+
label: "User Info",
46+
description: "The user's information",
47+
required: true,
48+
},
49+
chatTranscript: {
50+
type: "string",
51+
label: "Chat Transcript",
52+
description: "The transcript of the chat session",
53+
required: true,
54+
},
55+
},
556
methods: {
6-
// this.$auth contains connected account data
757
authKeys() {
858
console.log(Object.keys(this.$auth));
959
},
60+
_baseUrl() {
61+
return "https://api.insertchat.com";
62+
},
63+
async _makeRequest(opts = {}) {
64+
const {
65+
$ = this, method = "GET", path = "/", headers, ...otherOpts
66+
} = opts;
67+
return axios($, {
68+
...otherOpts,
69+
method,
70+
url: this._baseUrl() + path,
71+
headers: {
72+
...headers,
73+
Authorization: `Bearer ${this.$auth.api_token}`,
74+
},
75+
});
76+
},
77+
async emitNewChatbot() {
78+
return this._makeRequest({
79+
path: "/chatbots/new",
80+
});
81+
},
82+
async emitNewLead(contactInfo) {
83+
return this._makeRequest({
84+
method: "POST",
85+
path: "/leads/new",
86+
data: contactInfo,
87+
});
88+
},
89+
async emitNewChatSession(userInfo, chatTranscript) {
90+
return this._makeRequest({
91+
method: "POST",
92+
path: "/chats/new",
93+
data: {
94+
userInfo,
95+
chatTranscript,
96+
},
97+
});
98+
},
99+
async createNewLead(contactInfo, leadStatus) {
100+
return this._makeRequest({
101+
method: "POST",
102+
path: "/leads",
103+
data: {
104+
contactInfo,
105+
status: leadStatus,
106+
},
107+
});
108+
},
109+
async deleteLead(leadId) {
110+
return this._makeRequest({
111+
method: "DELETE",
112+
path: `/leads/${leadId}`,
113+
});
114+
},
115+
async pushMessage(sessionId, messageContent, sender) {
116+
return this._makeRequest({
117+
method: "POST",
118+
path: `/chats/${sessionId}/messages`,
119+
data: {
120+
content: messageContent,
121+
sender,
122+
},
123+
});
124+
},
10125
},
11-
};
126+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import insertchat from "../../insertchat.app.mjs";
2+
3+
export default {
4+
key: "insertchat-new-ai-chatbot",
5+
name: "New AI Chatbot",
6+
description: "Emit new event when a new AI chatbot is created.",
7+
version: "0.0.1",
8+
type: "source",
9+
dedupe: "unique",
10+
props: {
11+
insertchat,
12+
db: "$.service.db",
13+
timer: {
14+
type: "$.interface.timer",
15+
default: {
16+
intervalSeconds: 60 * 15, // by default, run every 15 minutes
17+
},
18+
},
19+
},
20+
methods: {
21+
generateMeta(data) {
22+
const {
23+
id, created_at,
24+
} = data;
25+
return {
26+
id,
27+
summary: `New AI Chatbot: ${id}`,
28+
ts: Date.parse(created_at),
29+
};
30+
},
31+
},
32+
async run() {
33+
const chatbot = await this.insertchat.emitNewChatbot();
34+
const meta = this.generateMeta(chatbot);
35+
this.$emit(chatbot, meta);
36+
},
37+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import insertchat from "../../insertchat.app.mjs";
2+
3+
export default {
4+
key: "insertchat-new-chat-session",
5+
name: "New Chat Session",
6+
description: "Emit new event when a new chat session is initiated. [See the documentation](https://docs.insertchat.com)",
7+
version: "0.0.{{ts}}",
8+
type: "source",
9+
dedupe: "unique",
10+
props: {
11+
insertchat,
12+
db: "$.service.db",
13+
timer: {
14+
type: "$.interface.timer",
15+
default: {
16+
intervalSeconds: 60,
17+
},
18+
},
19+
userInfo: {
20+
propDefinition: [
21+
insertchat,
22+
"userInfo",
23+
],
24+
},
25+
chatTranscript: {
26+
propDefinition: [
27+
insertchat,
28+
"chatTranscript",
29+
],
30+
},
31+
},
32+
methods: {
33+
generateMeta(data) {
34+
const {
35+
id, created_at,
36+
} = data;
37+
return {
38+
id,
39+
summary: `New chat session: ${id}`,
40+
ts: Date.parse(created_at),
41+
};
42+
},
43+
},
44+
async run() {
45+
const lastRun = this.db.get("lastRun") || this.timer.timestamp;
46+
const results = await this.insertchat.emitNewChatSession(this.userInfo, this.chatTranscript);
47+
for (const result of results) {
48+
const timestamp = Date.parse(result.created_at);
49+
if (timestamp > lastRun) {
50+
this.$emit(result, this.generateMeta(result));
51+
}
52+
}
53+
this.db.set("lastRun", this.timer.timestamp);
54+
},
55+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import insertchat from "../../insertchat.app.mjs";
2+
3+
export default {
4+
key: "insertchat-new-lead",
5+
name: "New Lead Created",
6+
description: "Emits a new event when a new lead is created. Best for real-time CRM integration.",
7+
version: "0.0.{{ts}}",
8+
type: "source",
9+
dedupe: "unique",
10+
props: {
11+
insertchat,
12+
db: "$.service.db",
13+
timer: {
14+
type: "$.interface.timer",
15+
default: {
16+
intervalSeconds: 60,
17+
},
18+
},
19+
leadContactInfo: {
20+
propDefinition: [
21+
insertchat,
22+
"leadContactInfo",
23+
],
24+
required: true,
25+
},
26+
},
27+
methods: {
28+
_getLeadId() {
29+
return this.db.get("leadId") || null;
30+
},
31+
_setLeadId(leadId) {
32+
this.db.set("leadId", leadId);
33+
},
34+
},
35+
hooks: {
36+
async deploy() {
37+
const lead = await this.insertchat.emitNewLead(this.leadContactInfo);
38+
this._setLeadId(lead.id);
39+
this.$emit(lead, {
40+
id: lead.id,
41+
summary: `New Lead: ${lead.name}`,
42+
ts: Date.now(),
43+
});
44+
},
45+
},
46+
async run() {
47+
const lead = await this.insertchat.emitNewLead(this.leadContactInfo);
48+
if (lead.id !== this._getLeadId()) {
49+
this._setLeadId(lead.id);
50+
this.$emit(lead, {
51+
id: lead.id,
52+
summary: `New Lead: ${lead.name}`,
53+
ts: Date.now(),
54+
});
55+
}
56+
},
57+
};

0 commit comments

Comments
 (0)