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
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import app from "../../textline.app.mjs";

export default {
key: "textline-create-update-contact",
name: "Create Or Update Contact",
description: "Create or update a contact in the Textline address book. [See the documentation](https://textline.docs.apiary.io/#reference/customers/customers/create-a-customer).",
version: "0.0.1",
type: "action",
props: {
app,
phoneNumber: {
propDefinition: [
app,
"phoneNumber",
],
},
email: {
type: "string",
label: "Email",
description: "The email of the contact.",
optional: true,
},
name: {
type: "string",
label: "Name",
description: "The name of the contact.",
optional: true,
},
notes: {
type: "string",
label: "Notes",
description: "Notes about the contact.",
optional: true,
},
tags: {
type: "string[]",
label: "Tags",
description: "Tags associated with the contact.",
optional: true,
},
},
methods: {
updateCustomer({
uuid, ...args
} = {}) {
return this.app.put({
path: `/customer/${uuid}`,
...args,
});
},
createCustomer(args = {}) {
return this.app.post({
path: "/customers",
...args,
});
},
},
async run({ $ }) {
const {
app,
updateCustomer,
createCustomer,
phoneNumber,
email,
name,
notes,
tags,
} = this;

let response;
let uuid;

try {
response = await createCustomer({
$,
data: {
customer: {
phone_number: phoneNumber,
email,
name,
notes,
tags,
},
},
});
} catch (error) {
if (error.response.status === 400 && error.response.data?.errors?.phone_number[0] === "Already in use") {

({ customer: { uuid } } = await app.getCustomerByPhoneNumber({
$,
params: {
phone_number: phoneNumber,
},
}));

} else {
throw error;
}
}

if (!uuid) {
$.export("$summary", `Successfully created the contact with uuid \`${response.customer.uuid}\`.`);
return response;
}

response = await updateCustomer({
$,
uuid,
data: {
customer: {
email,
name,
notes,
tags,
},
},
});

$.export("$summary", `Successfully updated the contact with uuid \`${uuid}\`.`);
return response;
},
};
119 changes: 119 additions & 0 deletions components/textline/actions/send-announcement/send-announcement.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import app from "../../textline.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "textline-send-announcement",
name: "Send Announcement",
description: "Send an announcement to a group of contacts. [See the documentation](https://textline.docs.apiary.io/#reference/messaging-tools/announcements/send-an-announcement).",
version: "0.0.1",
type: "action",
props: {
app,
massTextGroupUuid: {
label: "Mass Text Group UUID",
description: "The UUID of the mass text group.",
propDefinition: [
app,
"groupUuid",
],
},
massTextCommentBody: {
type: "string",
label: "Mass Text Comment Body",
description: "The content of the message to send.",
},
massTextTitle: {
type: "string",
label: "Mass Text Title",
description: "The title of the message.",
},
selectionType: {
type: "string",
label: "Selection Type",
description: "The type of the selection for the announcement.",
reloadProps: true,
options: Object.values(constants.SELECTION_TYPE),
},
},
additionalProps() {
const { selectionType } = this;

if (selectionType === constants.SELECTION_TYPE.TAGS.value) {
return {
tag: {
type: "string",
label: "Tag",
description: "Send to all contacts with this tag.",
},
};
}

if (selectionType === constants.SELECTION_TYPE.PHONE_NUMBERS.value) {
return {
phoneNumbers: {
type: "string[]",
label: "Phone Numbers",
description: "The phone numbers to send the announcement to.",
useQuery: true,
options: async ({
page, query,
}) => {
const { customers } = await this.app.listCustomers({
params: {
page,
page_size: 30,
query: query || "",
},
});
return customers.map(({
name: label, phone_number: value,
}) => ({
label,
value,
}));
},
},
};
}

return {};
},
methods: {
sendAnnouncement(args = {}) {
return this.app.post({
path: "/announcements",
...args,
});
},
},
async run({ $ }) {
const {
sendAnnouncement,
selectionType,
massTextGroupUuid,
massTextCommentBody,
massTextTitle,
tag,
phoneNumbers,
} = this;

const response = await sendAnnouncement({
$,
data: {
selection_type: selectionType,
recipients: {
tag,
phone_numbers: phoneNumbers,
},
mass_text: {
group_uuid: massTextGroupUuid,
comment_body: massTextCommentBody,
title: massTextTitle,
},
},
});

$.export("$summary", "Successfully sent the announcement.");
return response;
},
};
51 changes: 51 additions & 0 deletions components/textline/actions/send-message/send-message.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import app from "../../textline.app.mjs";

export default {
key: "textline-send-message",
name: "Send Message",
description: "Send a new message directly to a contact. [See the documentation](https://textline.docs.apiary.io/#reference/conversations/group-conversations/message-a-phone-number).",
version: "0.0.1",
type: "action",
props: {
app,
phoneNumber: {
propDefinition: [
app,
"phoneNumber",
],
},
comment: {
type: "string",
label: "Message",
description: "The content of the message to send.",
},
},
methods: {
sendMessage(args = {}) {
return this.app.post({
path: "/conversations",
...args,
});
},
},
async run({ $ }) {
const {
sendMessage,
phoneNumber,
comment,
} = this;
const response = await sendMessage({
$,
data: {
phone_number: phoneNumber,
comment: {
body: comment,
},
resolve: "1",
},
});

$.export("$summary", `Successfully sent message to ${phoneNumber}.`);
return response;
},
};
21 changes: 21 additions & 0 deletions components/textline/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const BASE_URL = "https://application.textline.com";
const VERSION_PATH = "/api";
const DEFAULT_LIMIT = 30;

const SELECTION_TYPE = {
TAGS: {
label: "Tags",
value: "tags",
},
PHONE_NUMBERS: {
label: "Phone Numbers",
value: "phone_numbers",
},
};

export default {
BASE_URL,
VERSION_PATH,
DEFAULT_LIMIT,
SELECTION_TYPE,
};
7 changes: 5 additions & 2 deletions components/textline/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/textline",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Textline Components",
"main": "textline.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