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
3 changes: 0 additions & 3 deletions components/salesmsg/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import salesmsg from "../../salesmsg.app.mjs";

export default {
key: "salesmsg-create-new-contact",
name: "Create New Contact",
version: "0.0.1",
description: "Create a new contact. [See the documentation](https://documenter.getpostman.com/view/13798866/2s935uHgXp#57f25fd9-2de8-4c9c-97f4-79bf7a6eb255)",
type: "action",
props: {
salesmsg,
number: {
type: "string",
label: "Number",
description: "The phone number of the contact.",
},
firstName: {
type: "string",
label: "First Name",
description: "The first name of the contact.",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of the contact.",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "The email of the contact.",
optional: true,
},
colorIndex: {
type: "string",
label: "Color Index",
description: "The color index of the contact.",
optional: true,
},
contactIntegrationId: {
type: "string",
label: "Contact Integration Id",
description: "The integration id of the contact.",
optional: true,
},
phoneType: {
type: "string",
label: "Phone Type",
description: "The type of the phone number. E.g. **phone, etc**",
optional: true,
},
},
async run({ $ }) {
const {
salesmsg,
firstName,
lastName,
colorIndex,
contactIntegrationId,
phoneType,
...params
} = this;

const response = await salesmsg.createContact({
$,
params: {
first_name: firstName,
last_name: lastName,
color_index: colorIndex,
contact_integration_id: contactIntegrationId,
phone_type: phoneType,
...params,
},
});

$.export("$summary", `A new contact with Id: ${response.id} was successfully created!`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import salesmsg from "../../salesmsg.app.mjs";

export default {
key: "salesmsg-get-user-conversations",
name: "Get User Conversations",
version: "0.0.1",
description: "Retrieves the list of all the conversations of a specific contact id. [See the documentation](https://documenter.getpostman.com/view/13798866/2s935uHgXp#27602c5c-e171-4009-b11c-3d19904d7dcd)",
type: "action",
props: {
salesmsg,
},
async run({ $ }) {
const items = this.salesmsg.paginate({
fn: this.salesmsg.listConversations,
});
const responseArray = [];

for await (const item of items) {
responseArray.push(item);
}

$.export("$summary", `${responseArray.length} conversation${responseArray.length > 1
? "s were"
: " was"} successfully fetched!`);
return responseArray;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import salesmsg from "../../salesmsg.app.mjs";

export default {
key: "salesmsg-search-conversations",
name: "Search Conversations",
version: "0.0.1",
description: "Search active conversations in conversation history. [See the documentation](https://documenter.getpostman.com/view/13798866/2s935uHgXp#c9f078a9-931a-45c0-81c7-14d2b745ca5b)",
type: "action",
props: {
salesmsg,
term: {
type: "string",
label: "Term",
description: "Search term (first/last name, email, number, formatted_number, tag)",
},
type: {
type: "string",
label: "Type",
description: "Define search type.",
options: [
"contacts",
"messages",
],
optional: true,
},
},
async run({ $ }) {
const {
salesmsg,
...params
} = this;
const items = salesmsg.paginate({
fn: salesmsg.searchConversations,
perPage: true,
params,
});
const responseArray = [];

for await (const item of items) {
responseArray.push(item);
}

$.export("$summary", `${responseArray.length} conversation${responseArray.length > 1
? "s were"
: " was"} successfully fetched!`);
return responseArray;
},
};
13 changes: 0 additions & 13 deletions components/salesmsg/app/salesmsg.app.ts

This file was deleted.

1 change: 1 addition & 0 deletions components/salesmsg/common/contants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIMIT = 100;
9 changes: 6 additions & 3 deletions components/salesmsg/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"name": "@pipedream/salesmsg",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Salesmsg Components",
"main": "dist/app/salesmsg.app.mjs",
"main": "salesmsg.app.mjs",
"keywords": [
"pipedream",
"salesmsg"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/salesmsg",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.5.1"
}
}

142 changes: 142 additions & 0 deletions components/salesmsg/salesmsg.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { axios } from "@pipedream/platform";
import { LIMIT } from "./common/contants.mjs";

export default {
type: "app",
app: "salesmsg",
propDefinitions: {
contactId: {
type: "string",
label: "Contact Id",
description: "The id of the contact you want to fetch messages.",
async options({ page }) {
const { data } = await this.listContacts({
params: {
page: page + 1,
},
});

return data.map(({
id: value, email: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
_apiUrl() {
return "https://api.salesmessage.com/pub/v2.1";
},
_getHeaders() {
return {
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
const config = {
url: `${this._apiUrl()}/${path}`,
headers: this._getHeaders(),
...opts,
};

return axios($, config);
},
createContact(args = {}) {
return this._makeRequest({
method: "POST",
path: "contacts",
...args,
});
},
listContacts(args = {}) {
return this._makeRequest({
path: "contacts",
...args,
});
},
listConversations(args = {}) {
return this._makeRequest({
path: "conversations",
...args,
});
},
listMessages(args = {}) {
return this._makeRequest({
path: "messages/contacts",
...args,
});
},
searchConversations(args = {}) {
return this._makeRequest({
path: "conversations/search",
...args,
});
},
async *paginate({
fn, params = {
filter: "open",
}, maxResults = null, perPage = false,
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
if (perPage) {
params.page = ++page;
} else {
params.limit = LIMIT;
params.offset = LIMIT * page;
page++;
}
const response = await fn({
params,
});
const data = response.data || response.results || response;

for (const d of data) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = data.length;

} while (hasMore);
},
async *paginateMessages({
maxResults = null, params,
}) {
let hasMore = false;
let count = 0;
let before = false;

do {
params.limit = LIMIT;
if (before) params.before = before;

const data = await this.listMessages({
params,
});

for (const d of data) {
yield d;
before = d.id;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = data.length;

} while (hasMore);
},
},
};
Loading