Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions components/insertchat/actions/create-lead/create-lead.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import insertchat from "../../insertchat.app.mjs";

export default {
key: "insertchat-create-lead",
name: "Create Lead",
description: "Creates a new lead within Insertchat. [See the documentation](https://www.postman.com/gold-star-239225/insertchat/request/uiugp1c/create-a-lead)",
version: "0.0.1",
type: "action",
props: {
insertchat,
chatbotId: {
propDefinition: [
insertchat,
"chatbotId",
],
},
firstName: {
type: "string",
label: "First Name",
description: "First name of the lead",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Last name of the lead",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email address of the lead",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Phone number of the lead",
optional: true,
},
address: {
type: "string",
label: "Address",
description: "Address of the lead",
optional: true,
},
website: {
type: "string",
label: "Website",
description: "Website of the lead",
optional: true,
},
company: {
type: "string",
label: "Company",
description: "Company of the lead",
optional: true,
},
},
async run({ $ }) {
const response = await this.insertchat.createLead({
$,
data: {
widget_uid: this.chatbotId,
first_name: this.firstName,
last_name: this.lastName,
email: this.email,
phone: this.phone,
address: this.address,
website: this.website,
company: this.company,
},
});
$.export("$summary", `Created lead with ID: ${response.uid}`);
return response;
},
};
26 changes: 26 additions & 0 deletions components/insertchat/actions/delete-lead/delete-lead.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import insertchat from "../../insertchat.app.mjs";

export default {
key: "insertchat-delete-lead",
name: "Delete Lead",
description: "Deletes an existing lead from InsertChat. [See the documentation](https://www.postman.com/gold-star-239225/insertchat/request/2vgc20j/delete-a-lead)",
version: "0.0.1",
type: "action",
props: {
insertchat,
leadId: {
propDefinition: [
insertchat,
"leadId",
],
},
},
async run({ $ }) {
const response = await this.insertchat.deleteLead({
$,
leadId: this.leadId,
});
$.export("$summary", `Successfully deleted lead with ID: ${this.leadId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import insertchat from "../../insertchat.app.mjs";

export default {
key: "insertchat-push-message-existing-chat",
name: "Push Message to Existing Chat",
description: "Pushes a new message into an existing chat session in InsertChat. [See the documentation](https://www.postman.com/gold-star-239225/insertchat/request/me7mcwa/push-a-message-into-a-chat-session)",
version: "0.0.1",
type: "action",
props: {
insertchat,
chatbotId: {
propDefinition: [
insertchat,
"chatbotId",
],
},
chatSessionId: {
propDefinition: [
insertchat,
"chatSessionId",
(c) => ({
chatbotId: c.chatbotId,
}),
],
},
role: {
type: "string",
label: "Role",
description: "Role to send message as",
options: [
"user",
"assistant",
],
},
message: {
type: "string",
label: "Message Content",
description: "The content of the message to be pushed into the chat session",
},
},
run({ $ }) {
// method works, but times out if we await the response
this.insertchat.pushMessage({
$,
data: new URLSearchParams({
widget_uid: this.chatbotId,
chat_uid: this.chatSessionId,
role: this.role,
input: this.message,
}),
});
$.export("$summary", `Successfully pushed message to chat session ${this.chatSessionId}`);
// nothing to return
},
};
161 changes: 156 additions & 5 deletions components/insertchat/insertchat.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,162 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "insertchat",
propDefinitions: {},
propDefinitions: {
chatbotId: {
type: "string",
label: "Chatbot ID",
description: "The unique identifier for the chatbot",
async options({ page }) {
const { data } = await this.listChatbots({
params: {
page: page + 1,
},
});
return data?.map(({
uid: value, label,
}) => ({
value,
label,
})) || [];
},
},
leadId: {
type: "string",
label: "Lead ID",
description: "The unique identifier for the lead",
async options({ page }) {
const { data } = await this.listLeads({
params: {
page: page + 1,
},
});
return data?.map(({
uid: value, first_name: firstName, last_name: lastName,
}) => ({
value,
label: firstName || lastName
? (`${firstName} ${lastName}`).trim()
: value,
})) || [];
},
},
chatSessionId: {
type: "string",
label: "Chat Session ID",
description: "The unique identifier for the chat session",
async options({
chatbotId, page,
}) {
const { data } = await this.listChatSessions({
chatbotId,
page: page + 1,
});
return data?.map(({
uid: value, label,
}) => ({
value,
label,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_appId() {
return this.$auth.app_uid;
},
_baseUrl() {
return "https://api.insertchat.com/v1";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
...headers,
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
});
},
listChatbots(opts = {}) {
return this._makeRequest({
path: `/${this._appId()}/widgets`,
...opts,
});
},
listLeads(opts = {}) {
return this._makeRequest({
path: `/${this._appId()}/contacts`,
...opts,
});
},
listChatSessions({
chatbotId, ...opts
}) {
return this._makeRequest({
path: `/${this._appId()}/chats/history/${chatbotId}?expand[0]=messages`,
...opts,
});
},
createLead(opts = {}) {
return this._makeRequest({
method: "POST",
path: `/${this._appId()}/contacts`,
...opts,
});
},
deleteLead({
leadId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/${this._appId()}/contacts/${leadId}`,
...opts,
});
},
pushMessage(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/embeds/messages",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
...opts,
});
},
async *paginate({
fn,
args,
max,
}) {
args = {
...args,
params: {
...args?.params,
page: 1,
},
};
let done, count = 0;
do {
const {
data, meta,
} = await fn(args);
for (const item of data) {
yield item;
if (max && ++count >= max) {
return;
}
done = args.params.page === meta.last_page;
args.params.page++;
}
} while (!done);
},
},
};
};
7 changes: 5 additions & 2 deletions components/insertchat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/insertchat",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream InsertChat Components",
"main": "insertchat.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
Loading
Loading