Skip to content

Commit

Permalink
List Telnyx phone numbers (PipedreamHQ#11681)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjabali authored May 1, 2024
1 parent b5f7ccb commit 1a28dc3
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "telnyx-get-messaging-profiles",
name: "Get Messaging Profiles",
description: "Get a list of messaging profiles. See documentation [here](https://developers.telnyx.com/api/messaging/list-messaging-profiles)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
telnyxApp,
Expand Down
137 changes: 137 additions & 0 deletions components/telnyx/actions/get-phone-numbers/get-phone-numbers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import telnyxApp from "../../telnyx.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "telnyx-get-phone-numbers",
name: "Get Phone Numbers",
description: "Get a list of phone numbers. See documentation [here](https://developers.telnyx.com/api/numbers/list-phone-numbers)",
version: "0.0.1",
type: "action",
props: {
telnyxApp,
pageSize: {
type: "integer",
label: "Page Size",
description: "The size of the page.",
optional: true,
min: 1,
max: 250,
default: 20,
},
pageNumber: {
type: "integer",
label: "Page Number",
description: "The page number to load.",
optional: true,
min: 1,
default: 1,
},
tag: {
type: "string",
label: "Tag",
description: "Filter by tag.",
optional: true,
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "Filter by phone number. Requires at least three digits. Non-numerical characters will result in no values being returned.",
optional: true,
},
status: {
type: "string",
label: "Status",
description: "Filter by phone number status.",
options: Object.values(constants.phoneNumberStatus),
optional: true,
},
connectionId: {
type: "string",
label: "Connection Id",
description: "Filter by connection Id.",
optional: true,
},
contains: {
type: "string",
label: "Contains",
description: "Filter contains connection name. Requires at least three characters.",
optional: true,
},
startsWith: {
type: "string",
label: "Starts With",
description: "Filter starts with connection name. Requires at least three characters.",
optional: true,
},
endsWith: {
type: "string",
label: "Ends With",
description: "Filter ends with connection name. Requires at least three characters.",
optional: true,
},
equals: {
type: "string",
label: "Equals",
description: "Filter by connection name.",
optional: true,
},
paymentMethod: {
type: "string",
label: "Payment Method",
description: "Filter by usage payment method.",
options: Object.values(constants.paymentMethods),
optional: true,
},
billingGroupId: {
type: "string",
label: "Billing Group Id",
description: "Filter by the billing group Id associated with phone numbers. To filter to only phone numbers that have no billing group associated them, set the value of this filter to the string 'null'.",
optional: true,
},
emergencyAddressId: {
type: "string",
label: "Emergency Address Id",
description: "Filter by the emergency_address_id associated with phone numbers. To filter only phone numbers that have no emergency address associated with them, set the value of this filter to the string 'null'.",
optional: true,
},
customerReference: {
type: "string",
label: "Customer Reference",
description: "Filter numbers via the customer reference set.",
optional: true,
},
sort: {
type: "string",
label: "Sort",
description: "Specifies the sort order for results. If not given, results are sorted by created_at in descending order.",
options: Object.values(constants.sortPhoneNumbers),
optional: true,
},
},
async run({ $ }) {
const phoneNumbers = await this.telnyxApp.getPhoneNumbers({
$,
params: {
"page[size]": this.pageSize || 20,
"page[number]": this.pageNumber || 1,
"filter[tag]": this.tag,
"filter[phone_number]": this.phoneNumber,
"filter[status]": this.status,
"filter[connection_id]": this.connectionId,
"filter[voice.connection_name][contains]": this.contains,
"filter[voice.connection_name][starts_with]": this.startsWith,
"filter[voice.connection_name][ends_with]": this.endsWith,
"filter[voice.connection_name][eq]": this.equals,
"filter[voice.usage_payment_method]": this.paymentMethod,
"filter[billing_group_id]": this.billingGroupId,
"filter[emergency_address_id]": this.emergencyAddressId,
"filter[customer_reference]": this.customerReference,
"sort": this.sort,
},
});
$.export("$summary", `Successfully retrieved ${phoneNumbers.data.length} phone number${phoneNumbers.data.length === 1
? ""
: "s"}.`);
return phoneNumbers;
},
};
19 changes: 10 additions & 9 deletions components/telnyx/actions/send-message/send-message.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "telnyx-send-message",
name: "Send Message",
description: "Send an SMS or MMS message. See documentation [here](https://developers.telnyx.com/docs/messaging/messages/send-message)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
telnyxApp,
Expand All @@ -15,17 +15,18 @@ export default {
"messagingProfileId",
],
},
phoneNumber: {
optional: true,
propDefinition: [
telnyxApp,
"phoneNumber",
],
},
to: {
type: "string",
label: "To",
description: "Receiving address (+E.164 formatted phone number or short code).",
},
from: {
type: "string",
label: "From",
description: "Sending address (+E.164 formatted phone number or short code). Required if sending with a phone number, short code, or alphanumeric sender ID. See [Sending a message on the Telnyx platform](https://developers.telnyx.com/docs/messaging/messages/send-message) for more details.",
optional: true,
},
text: {
type: "string",
label: "Text",
Expand Down Expand Up @@ -84,9 +85,9 @@ export default {
$,
data: {
to: this.to,
from: this.from,
from: this.phoneNumber,
text: this.text,
messaging_profile_id: this.messaging_profile_id,
messaging_profile_id: this.messagingProfileId,
subject: this.subject,
media_urls: this.mediaUrls,
webhook_url: this.webhookUrl,
Expand Down
28 changes: 28 additions & 0 deletions components/telnyx/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const phoneNumberStatus = {
"PURCHASE PENDING": "purchase_pending",
"PURCHASE FAILED": "purchase_failed",
"PORT PENDING": "port_pending",
"ACTIVE": "active",
"DELETED": "deleted",
"PORT FAILED": "port_failed",
"EMERGENCY ONLY": "emergency_only",
"PORTED OUT": "ported_out",
"PORT OUT PENDING": "port_out_pending",
};

const paymentMethods = {
"PAY PER MINUTE": "pay-per-minute",
"CHANNEL": "channel",
};

const sortPhoneNumbers = {
"PURCHASED AT": "purchased_at",
"PHONE NUMBER": "phone_number",
"CONNECTION NAME": "connection_name",
"USAGE PAYMENT METHOD": "usage_payment_method",
};
export default {
phoneNumberStatus,
paymentMethods,
sortPhoneNumbers,
};
2 changes: 1 addition & 1 deletion components/telnyx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/telnyx",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream Telnyx Components",
"main": "telnyx.app.mjs",
"keywords": [
Expand Down
29 changes: 24 additions & 5 deletions components/telnyx/telnyx.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
description: "The Id of the messaging profile to use for sending the message.",
async options({ page }) {
const params = {
"page[number]": page || 1,
"page[number]": page + 1,
};
const profiles = await this.getMessagingProfiles({
params,
Expand All @@ -21,12 +21,25 @@ export default {
}));
},
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "The phone number to send the message from.",
async options({ page }) {
const params = {
"page[number]": page + 1,
};
const phoneNumbers = await this.getPhoneNumbers({
params,
});
return phoneNumbers.data.map((phoneNumber) => ({
label: phoneNumber.phone_number,
value: phoneNumber.phone_number,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
},
getHeaders() {
return {
"Content-Type": "application/json",
Expand Down Expand Up @@ -71,5 +84,11 @@ export default {
...args,
});
},
async getPhoneNumbers(args) {
return this.makeRequest({
path: "/phone_numbers",
...args,
});
},
},
};

0 comments on commit 1a28dc3

Please sign in to comment.