Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Components - krispcall #13867

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
60 changes: 60 additions & 0 deletions components/krispcall/actions/add-contact/add-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import krispcall from "../../krispcall.app.mjs";

export default {
key: "krispcall-add-contact",
name: "Add Contact",
description: "Creates a new contact. [See the documentation](https://documenter.getpostman.com/view/32476792/2sa3dxfcal)",
luancazarine marked this conversation as resolved.
Show resolved Hide resolved
version: "0.0.1",
type: "action",
props: {
krispcall,
number: {
propDefinition: [
krispcall,
"number",
],
},
name: {
propDefinition: [
krispcall,
"name",
],
optional: true,
},
email: {
propDefinition: [
krispcall,
"email",
],
optional: true,
},
company: {
propDefinition: [
krispcall,
"company",
],
optional: true,
},
address: {
propDefinition: [
krispcall,
"address",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.krispcall.createContact({
$,
data: {
number: this.number,
name: this.name,
email: this.email,
company: this.company,
address: this.address,
},
});
$.export("$summary", `Successfully created contact with ID ${response.id}`);
return response;
},
};
30 changes: 30 additions & 0 deletions components/krispcall/actions/delete-contact/delete-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { parseObject } from "../../common/utils.mjs";
import krispcall from "../../krispcall.app.mjs";

export default {
key: "krispcall-delete-contact",
name: "Delete Contact",
description: "Deletes a list of contacts. [See the documentation](https://documenter.getpostman.com/view/32476792/2sa3dxfcal)",
version: "0.0.1",
type: "action",
props: {
krispcall,
contactIds: {
propDefinition: [
krispcall,
"contactIds",
],
},
},
async run({ $ }) {
const parsedContacts = parseObject(this.contactIds);
const response = await this.krispcall.deleteContacts({
$,
data: {
contacts: parsedContacts,
},
});
$.export("$summary", `Successfully deleted ${parsedContacts.length} contact(s)`);
return response;
},
};
50 changes: 50 additions & 0 deletions components/krispcall/actions/new-mms/new-mms.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import krispcall from "../../krispcall.app.mjs";

export default {
key: "krispcall-new-mms",
name: "Send New MMS",
description: "Send a new MMS to a contact. [See the documentation](https://documenter.getpostman.com/view/32476792/2sa3dxfcal)",
version: "0.0.1",
type: "action",
props: {
krispcall,
fromNumber: {
propDefinition: [
krispcall,
"fromNumber",
],
},
toNumber: {
propDefinition: [
krispcall,
"toNumber",
],
},
content: {
propDefinition: [
krispcall,
"content",
],
optional: true,
},
medias: {
propDefinition: [
krispcall,
"medias",
],
},
},
async run({ $ }) {
const response = await this.krispcall.sendMMS({
$,
data: {
from_number: this.fromNumber,
to_number: this.toNumber,
content: this.content,
medias: this.medias,
},
});
$.export("$summary", `Successfully sent MMS from ${this.fromNumber} to ${this.toNumber}`);
return response;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
};
42 changes: 42 additions & 0 deletions components/krispcall/actions/new-sms/new-sms.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import krispcall from "../../krispcall.app.mjs";

export default {
key: "krispcall-new-sms",
name: "Send New SMS",
description: "Send a new SMS to a number. [See the documentation](https://documenter.getpostman.com/view/32476792/2sa3dxfcal)",
version: "0.0.1",
type: "action",
props: {
krispcall,
fromNumber: {
propDefinition: [
krispcall,
"fromNumber",
],
},
toNumber: {
propDefinition: [
krispcall,
"toNumber",
],
},
content: {
propDefinition: [
krispcall,
"content",
],
},
},
async run({ $ }) {
const response = await this.krispcall.sendSMS({
$,
data: {
from_number: this.fromNumber,
to_number: this.toNumber,
content: this.content,
},
});
$.export("$summary", `Successfully sent SMS to ${this.toNumber}`);
return response;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
};
24 changes: 24 additions & 0 deletions components/krispcall/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
145 changes: 140 additions & 5 deletions components/krispcall/krispcall.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,146 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "krispcall",
propDefinitions: {},
propDefinitions: {
number: {
type: "string",
label: "Number",
description: "The phone number of the contact",
},
name: {
type: "string",
label: "Name",
description: "The name of the contact",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "The email of the contact",
optional: true,
},
company: {
type: "string",
label: "Company",
description: "The company of the contact",
optional: true,
},
address: {
type: "string",
label: "Address",
description: "The address of the contact",
optional: true,
},
fromNumber: {
type: "string",
label: "From Number",
description: "The number from which the SMS/MMS is sent",
async options() {
const numbers = await this.listNumbers();
return numbers.map(({ number }) => number);
},
},
toNumber: {
type: "string",
label: "To Number",
description: "The recipient's phone number",
},
content: {
type: "string",
label: "Content",
description: "The content of the SMS/MMS",
},
medias: {
type: "string[]",
label: "Medias",
description: "The media files for MMS. It should be a valid url field and size should not be greater than 5mb. Upto 5 media lists are supported. Media url should be starting from https. Media url should be public accessible and content-type should be supported by KrispCall app.",
},
contactIds: {
type: "string[]",
label: "Contact Numbers",
description: "The phone numbers of the contacts to delete",
async options() {
const contacts = await this.listContacts();
return contacts.map(({
name, contact_number: number,
}) => ({
label: `${name} ${number}`,
value: number,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return `${this.$auth.url}/api/v1/platform/pipedream`;
},
_headers() {
return {
"X-API-Key": `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listNumbers() {
return this._makeRequest({
path: "/get-numbers",
});
},
listContacts() {
return this._makeRequest({
path: "/get-contacts",
});
},
createContact(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/add-contact",
...opts,
});
},
sendSMS(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/send-sms",
...opts,
});
},
sendMMS(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/send-mms",
...opts,
});
},
deleteContacts(opts = {}) {
return this._makeRequest({
method: "DELETE",
path: "/delete-contacts",
...opts,
});
},
createWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/subscribe",
...opts,
});
},
deleteWebhook(opts = {}) {
return this._makeRequest({
method: "DELETE",
path: "/unsubscribe",
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/krispcall/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/krispcall",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream KrispCall Components",
"main": "krispcall.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1"
}
}
}
Loading
Loading