From 1611573014aba65cc3a42ddb04bed559249990a8 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 16 May 2024 16:01:08 -0300 Subject: [PATCH 1/5] pidj init --- .../actions/create-contact/create-contact.mjs | 42 +++++++ .../initiate-survey/initiate-survey.mjs | 44 +++++++ .../actions/send-message/send-message.mjs | 28 +++++ components/pidj/package.json | 2 +- components/pidj/pidj.app.mjs | 118 +++++++++++++++++- 5 files changed, 228 insertions(+), 6 deletions(-) create mode 100644 components/pidj/actions/create-contact/create-contact.mjs create mode 100644 components/pidj/actions/initiate-survey/initiate-survey.mjs create mode 100644 components/pidj/actions/send-message/send-message.mjs diff --git a/components/pidj/actions/create-contact/create-contact.mjs b/components/pidj/actions/create-contact/create-contact.mjs new file mode 100644 index 0000000000000..57b9f93b57bb9 --- /dev/null +++ b/components/pidj/actions/create-contact/create-contact.mjs @@ -0,0 +1,42 @@ +import pidj from "../../pidj.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "pidj-create-contact", + name: "Create Contact", + description: "Initiates a process to add a new contact to your Pidj account.", + version: "0.0.1", + type: "action", + props: { + pidj, + contactInformation: { + propDefinition: [ + pidj, + "contactInformation", + ], + }, + additionalNotes: { + propDefinition: [ + pidj, + "additionalNotes", + ], + optional: true, + }, + tags: { + propDefinition: [ + pidj, + "tags", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.pidj.addContact({ + contactInformation: this.contactInformation, + additionalNotes: this.additionalNotes, + tags: this.tags, + }); + $.export("$summary", "Successfully added a new contact"); + return response; + }, +}; diff --git a/components/pidj/actions/initiate-survey/initiate-survey.mjs b/components/pidj/actions/initiate-survey/initiate-survey.mjs new file mode 100644 index 0000000000000..d42874ea28dcd --- /dev/null +++ b/components/pidj/actions/initiate-survey/initiate-survey.mjs @@ -0,0 +1,44 @@ +import pidj from "../../pidj.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "pidj-initiate-survey", + name: "Initiate Survey", + description: "Triggers a pre-configured text survey to a specific contact. Requires the contact's information and the survey ID.", + version: "0.0.1", + type: "action", + props: { + pidj, + contactInformation: { + propDefinition: [ + pidj, + "contactInformation", + ], + }, + surveyId: { + propDefinition: [ + pidj, + "surveyId", + ], + }, + scheduleTimeForSurvey: { + propDefinition: [ + pidj, + "scheduleTimeForSurvey", + (c) => ({ + optional: true, + }), + ], + }, + }, + async run({ $ }) { + const response = await this.pidj.triggerSurvey({ + contactInformation: this.contactInformation, + surveyId: this.surveyId, + scheduleTimeForSurvey: this.scheduleTimeForSurvey, + }); + + $.export("$summary", `Successfully initiated survey with ID ${this.surveyId} for contact ${this.contactInformation.email || this.contactInformation.phone}`); + return response; + }, +}; diff --git a/components/pidj/actions/send-message/send-message.mjs b/components/pidj/actions/send-message/send-message.mjs new file mode 100644 index 0000000000000..bec32e98aa3de --- /dev/null +++ b/components/pidj/actions/send-message/send-message.mjs @@ -0,0 +1,28 @@ +import pidj from "../../pidj.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "pidj-send-message", + name: "Send Message", + description: "Sends a text message to a specified phone number from your pidj account.", + version: "0.0.{{ts}}", + type: "action", + props: { + pidj, + recipientPhoneNumber: pidj.propDefinitions.recipientPhoneNumber, + messageText: pidj.propDefinitions.messageText, + scheduledSendTime: { + ...pidj.propDefinitions.scheduledSendTime, + optional: true, + }, + }, + async run({ $ }) { + const response = await this.pidj.sendMessage({ + recipientPhoneNumber: this.recipientPhoneNumber, + messageText: this.messageText, + scheduledSendTime: this.scheduledSendTime, + }); + $.export("$summary", `Message successfully sent to ${this.recipientPhoneNumber}`); + return response; + }, +}; diff --git a/components/pidj/package.json b/components/pidj/package.json index a89e4b3ad710b..3f12de9287127 100644 --- a/components/pidj/package.json +++ b/components/pidj/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/pidj/pidj.app.mjs b/components/pidj/pidj.app.mjs index 6041c775ac137..68c0c5abb8f6b 100644 --- a/components/pidj/pidj.app.mjs +++ b/components/pidj/pidj.app.mjs @@ -1,11 +1,119 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "pidj", - propDefinitions: {}, + propDefinitions: { + contactInformation: { + type: "object", + label: "Contact's Information", + description: "The contact's information including name, email, and phone number.", + }, + additionalNotes: { + type: "string", + label: "Additional Notes", + description: "Any additional notes related to the contact.", + optional: true, + }, + tags: { + type: "string[]", + label: "Tags", + description: "Tags related to the contact.", + optional: true, + }, + recipientPhoneNumber: { + type: "string", + label: "Recipient's Phone Number", + description: "The phone number of the message recipient.", + }, + messageText: { + type: "string", + label: "Message Text", + description: "The text of the message to be sent.", + }, + scheduledSendTime: { + type: "string", + label: "Scheduled Send Time", + description: "The scheduled time to send the message, in ISO 8601 format.", + optional: true, + }, + surveyId: { + type: "string", + label: "Survey ID", + description: "The ID of the survey to be triggered.", + }, + scheduleTimeForSurvey: { + type: "string", + label: "Schedule Time for Survey", + description: "The scheduled time to initiate the survey, in ISO 8601 format.", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.gopidj.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "GET", + path, + data, + params, + headers, + ...otherOpts + } = opts; + return axios($, { + method, + url: this._baseUrl() + path, + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + ...headers, + }, + data, + params, + ...otherOpts, + }); + }, + async addContact({ + contactInformation, additionalNotes, tags, + }) { + return this._makeRequest({ + method: "POST", + path: "/contacts", + data: { + contactInformation, + additionalNotes, + tags, + }, + }); + }, + async sendMessage({ + recipientPhoneNumber, messageText, scheduledSendTime, + }) { + return this._makeRequest({ + method: "POST", + path: "/messages/send", + data: { + recipientPhoneNumber, + messageText, + scheduledSendTime, + }, + }); + }, + async triggerSurvey({ + contactInformation, surveyId, scheduleTimeForSurvey, + }) { + return this._makeRequest({ + method: "POST", + path: "/surveys/trigger", + data: { + contactInformation, + surveyId, + scheduleTimeForSurvey, + }, + }); }, }, -}; \ No newline at end of file +}; From 1740343e73505f7c894cdf19dccc2b313e455815 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 17 May 2024 11:41:10 -0300 Subject: [PATCH 2/5] [Components] pidj #11935 Ations - Create Contact - Send Message - Initiate Survey --- .../actions/create-contact/create-contact.mjs | 166 ++++- .../initiate-survey/initiate-survey.mjs | 55 +- .../actions/send-message/send-message.mjs | 38 +- components/pidj/common/constants.mjs | 599 ++++++++++++++++++ components/pidj/package.json | 6 +- components/pidj/pidj.app.mjs | 158 ++--- 6 files changed, 901 insertions(+), 121 deletions(-) create mode 100644 components/pidj/common/constants.mjs diff --git a/components/pidj/actions/create-contact/create-contact.mjs b/components/pidj/actions/create-contact/create-contact.mjs index 57b9f93b57bb9..7977572e4dab8 100644 --- a/components/pidj/actions/create-contact/create-contact.mjs +++ b/components/pidj/actions/create-contact/create-contact.mjs @@ -1,42 +1,172 @@ +import { TIMEZONE_OPTIONS } from "../../common/constants.mjs"; import pidj from "../../pidj.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "pidj-create-contact", name: "Create Contact", - description: "Initiates a process to add a new contact to your Pidj account.", + description: "Initiates a process to add a new contact to your Pidj account. [See the documentation](https://pidj.co/wp-content/uploads/2023/06/Pidj-API-Technical-Document-v3-1.pdf).", version: "0.0.1", type: "action", props: { pidj, - contactInformation: { - propDefinition: [ - pidj, - "contactInformation", - ], + phoneNumber: { + type: "string", + label: "Phone Number", + description: "Phone number for the contact. This must be in E.164 format. **e.g., +18885552222**", }, - additionalNotes: { - propDefinition: [ - pidj, - "additionalNotes", - ], + emailAddress: { + type: "string", + label: "Email Address", + description: "The contact's email address.", optional: true, }, - tags: { + firstName: { + type: "string", + label: "First Name", + description: "The contact's first name.", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "The contact's last name.", + optional: true, + }, + businessName: { + type: "string", + label: "Business Name", + description: "The contact's business name.", + optional: true, + }, + displayName: { + type: "string", + label: "Display Name", + description: "The contact's display name, if present, and different from first and last name.", + optional: true, + }, + groupId: { propDefinition: [ pidj, - "tags", + "groupId", ], optional: true, }, + timezone: { + type: "string", + label: "Timezone", + description: "Timezone identifier for the contact. If omitted, this will default to the account value.", + options: TIMEZONE_OPTIONS, + optional: true, + }, + externalId: { + type: "string", + label: "External Id", + description: "The external ID of the contact from your own system. This may be used in any enabled integrations to cross-identify the contact record.", + optional: true, + }, + homeAddressStreet1: { + type: "string", + label: "Home Street 1", + description: "The home street address 1.", + optional: true, + }, + homeAddressStreet2: { + type: "string", + label: "Home Street 2", + description: "The home street address 2.", + optional: true, + }, + homeAddressCity: { + type: "string", + label: "Home City", + description: "The home city address.", + optional: true, + }, + homeAddressState: { + type: "string", + label: "Home State", + description: "The home state address. Must be the standard 2 character abbreviation (**ANSI2-letter** or **USPS**). Any other values will be discarded. [See further information](https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations).", + optional: true, + }, + homeAddressPostal: { + type: "string", + label: "Home Postal", + description: "Valid 5 or 10 digit zipcode (US addresses). British, Canadian, and Australian postal codes also supported.", + optional: true, + }, + homeAddressCountry: { + type: "string", + label: "Home Country", + description: "Must be either **ISO 3166-1 alpha-2** or **ISO 3166-1 alpha-3**. Any other values will be discarded. [See further information](https://en.wikipedia.org/wiki/ISO_3166-1).", + optional: true, + }, + businessAddressStreet1: { + type: "string", + label: "Business Street 1", + description: "The business street address 1.", + optional: true, + }, + businessAddressStreet2: { + type: "string", + label: "Business Street 2", + description: "The business street address 2.", + optional: true, + }, + businessAddressCity: { + type: "string", + label: "Business City", + description: "The business city address.", + optional: true, + }, + businessAddressState: { + type: "string", + label: "Business State", + description: "The business state address. Must be the standard 2 character abbreviation (**ANSI2-letter** or **USPS**). Any other values will be discarded. [See further information](https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations).", + optional: true, + }, + businessAddressPostal: { + type: "string", + label: "Business Postal", + description: "Valid 5 or 10 digit zipcode (US addresses). British, Canadian, and Australian postal codes also supported.", + optional: true, + }, + businessAddressCountry: { + type: "string", + label: "Business Country", + description: "Must be either **ISO 3166-1 alpha-2** or **ISO 3166-1 alpha-3**. Any other values will be discarded. [See further information](https://en.wikipedia.org/wiki/ISO_3166-1).", + optional: true, + }, }, async run({ $ }) { const response = await this.pidj.addContact({ - contactInformation: this.contactInformation, - additionalNotes: this.additionalNotes, - tags: this.tags, + $, + data: { + phone_number: this.phoneNumber, + email_address: this.emailAddress, + first_name: this.firstName, + last_name: this.lastName, + business_name: this.businessName, + display_name: this.displayName, + group: this.groupId, + timezone: this.timezone, + external_id: this.externalId, + addresses: { + home_street_1: this.homeAddressStreet1, + home_street_2: this.homeAddressStreet2, + home_city: this.homeAddressCity, + home_state: this.homeAddressState, + home_postal: this.homeAddressPostal, + home_country: this.homeAddressCountry, + business_street_1: this.businessAddressStreet1, + business_street_2: this.businessAddressStreet2, + business_city: this.businessAddressCity, + business_state: this.businessAddressState, + business_postal: this.businessAddressPostal, + business_country: this.businessAddressCountry, + }, + }, }); - $.export("$summary", "Successfully added a new contact"); + $.export("$summary", `Successfully added a new contact with Id: ${response.id}`); return response; }, }; diff --git a/components/pidj/actions/initiate-survey/initiate-survey.mjs b/components/pidj/actions/initiate-survey/initiate-survey.mjs index d42874ea28dcd..d2739548e08f7 100644 --- a/components/pidj/actions/initiate-survey/initiate-survey.mjs +++ b/components/pidj/actions/initiate-survey/initiate-survey.mjs @@ -1,44 +1,69 @@ +import { ConfigurationError } from "@pipedream/platform"; import pidj from "../../pidj.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "pidj-initiate-survey", name: "Initiate Survey", - description: "Triggers a pre-configured text survey to a specific contact. Requires the contact's information and the survey ID.", + description: "Triggers a pre-configured text survey to a specific contact. Requires the contact's information and the survey ID. [See the documentation](https://pidj.co/wp-content/uploads/2023/06/Pidj-API-Technical-Document-v3-1.pdf).", version: "0.0.1", type: "action", props: { pidj, - contactInformation: { + surveyId: { propDefinition: [ pidj, - "contactInformation", + "surveyId", ], }, - surveyId: { + contactId: { propDefinition: [ pidj, - "surveyId", + "contactId", ], + optional: true, }, - scheduleTimeForSurvey: { + toNumber: { propDefinition: [ pidj, - "scheduleTimeForSurvey", - (c) => ({ - optional: true, - }), + "toNumber", ], + optional: true, + }, + fromNumber: { + propDefinition: [ + pidj, + "fromNumber", + ], + optional: true, + }, + groupId: { + propDefinition: [ + pidj, + "groupId", + ], + optional: true, }, }, async run({ $ }) { + if ((!this.contactId && !this.toNumber) || (this.contactId && this.toNumber)) { + throw new ConfigurationError("You must provide either Contact Id or To Number."); + } + if ((!this.fromNumber && !this.groupId) || (this.fromNumber && this.groupId)) { + throw new ConfigurationError("You must provide either From Number or Group Id."); + } + const response = await this.pidj.triggerSurvey({ - contactInformation: this.contactInformation, - surveyId: this.surveyId, - scheduleTimeForSurvey: this.scheduleTimeForSurvey, + $, + data: { + survey_id: this.surveyId, + contact_id: this.contactId, + to_number: this.toNumber, + from_number: this.fromNumber, + group_id: this.groupId, + }, }); - $.export("$summary", `Successfully initiated survey with ID ${this.surveyId} for contact ${this.contactInformation.email || this.contactInformation.phone}`); + $.export("$summary", `Successfully initiated survey for contact ${this.contactId || this.toNumber}`); return response; }, }; diff --git a/components/pidj/actions/send-message/send-message.mjs b/components/pidj/actions/send-message/send-message.mjs index bec32e98aa3de..9ed8b04c93777 100644 --- a/components/pidj/actions/send-message/send-message.mjs +++ b/components/pidj/actions/send-message/send-message.mjs @@ -1,27 +1,43 @@ +import { ConfigurationError } from "@pipedream/platform"; import pidj from "../../pidj.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "pidj-send-message", name: "Send Message", - description: "Sends a text message to a specified phone number from your pidj account.", - version: "0.0.{{ts}}", + description: "Sends a text message to a specified phone number from your pidj account. [See the documentation](https://pidj.co/wp-content/uploads/2023/06/Pidj-API-Technical-Document-v3-1.pdf).", + version: "0.0.1", type: "action", props: { pidj, - recipientPhoneNumber: pidj.propDefinitions.recipientPhoneNumber, - messageText: pidj.propDefinitions.messageText, - scheduledSendTime: { - ...pidj.propDefinitions.scheduledSendTime, - optional: true, + groupId: { + propDefinition: [ + pidj, + "groupId", + ], + }, + toNumber: { + propDefinition: [ + pidj, + "toNumber", + ], + }, + textBody: { + type: "string", + label: "Text Body", + description: "The text to send. Message lengths greater than 1,600 characters will be truncated. Messages with emoji and special characters may have a smaller limit due to encoding requirements. [See Pidj FAQ for details](https://pidjco.gopidj.com/faq).", }, }, async run({ $ }) { const response = await this.pidj.sendMessage({ - recipientPhoneNumber: this.recipientPhoneNumber, - messageText: this.messageText, - scheduledSendTime: this.scheduledSendTime, + $, + data: { + group_id: this.groupId, + to_number: this.toNumber, + text_body: this.textBody, + }, }); + if (response.status != "success") throw new ConfigurationError(response.message); + $.export("$summary", `Message successfully sent to ${this.recipientPhoneNumber}`); return response; }, diff --git a/components/pidj/common/constants.mjs b/components/pidj/common/constants.mjs new file mode 100644 index 0000000000000..7e1205e5046a7 --- /dev/null +++ b/components/pidj/common/constants.mjs @@ -0,0 +1,599 @@ +export const TIMEZONE_OPTIONS = [ + "Africa/Abidjan", + "Africa/Accra", + "Africa/Addis_Ababa", + "Africa/Algiers", + "Africa/Asmara", + "Africa/Asmera", + "Africa/Bamako", + "Africa/Bangui", + "Africa/Banjul", + "Africa/Bissau", + "Africa/Blantyre", + "Africa/Brazzaville", + "Africa/Bujumbura", + "Africa/Cairo", + "Africa/Casablanca", + "Africa/Ceuta", + "Africa/Conakry", + "Africa/Dakar", + "Africa/Dar_es_Salaam", + "Africa/Djibouti", + "Africa/Douala", + "Africa/El_Aaiun", + "Africa/Freetown", + "Africa/Gaborone", + "Africa/Harare", + "Africa/Johannesburg", + "Africa/Juba", + "Africa/Kampala", + "Africa/Khartoum", + "Africa/Kigali", + "Africa/Kinshasa", + "Africa/Lagos", + "Africa/Libreville", + "Africa/Lome", + "Africa/Luanda", + "Africa/Lubumbashi", + "Africa/Lusaka", + "Africa/Malabo", + "Africa/Maputo", + "Africa/Maseru", + "Africa/Mbabane", + "Africa/Mogadishu", + "Africa/Monrovia", + "Africa/Nairobi", + "Africa/Ndjamena", + "Africa/Niamey", + "Africa/Nouakchott", + "Africa/Ouagadougou", + "Africa/Porto-Novo", + "Africa/Sao_Tome", + "Africa/Timbuktu", + "Africa/Tripoli", + "Africa/Tunis", + "Africa/Windhoek", + "America/Adak", + "America/Anchorage", + "America/Anguilla", + "America/Antigua", + "America/Araguaina", + "America/Argentina/Buenos_Aires", + "America/Argentina/Catamarca", + "America/Argentina/ComodRivadavia", + "America/Argentina/Cordoba", + "America/Argentina/Jujuy", + "America/Argentina/La_Rioja", + "America/Argentina/Mendoza", + "America/Argentina/Rio_Gallegos", + "America/Argentina/Salta", + "America/Argentina/San_Juan", + "America/Argentina/San_Luis", + "America/Argentina/Tucuman", + "America/Argentina/Ushuaia", + "America/Aruba", + "America/Asuncion", + "America/Atikokan", + "America/Atka", + "America/Bahia", + "America/Bahia_Banderas", + "America/Barbados", + "America/Belem", + "America/Belize", + "America/Blanc-Sablon", + "America/Boa_Vista", + "America/Bogota", + "America/Boise", + "America/Buenos_Aires", + "America/Cambridge_Bay", + "America/Campo_Grande", + "America/Cancun", + "America/Caracas", + "America/Catamarca", + "America/Cayenne", + "America/Cayman", + "America/Chicago", + "America/Chihuahua", + "America/Ciudad_Juarez", + "America/Coral_Harbour", + "America/Cordoba", + "America/Costa_Rica", + "America/Creston", + "America/Cuiaba", + "America/Curacao", + "America/Danmarkshavn", + "America/Dawson", + "America/Dawson_Creek", + "America/Denver", + "America/Detroit", + "America/Dominica", + "America/Edmonton", + "America/Eirunepe", + "America/El_Salvador", + "America/Ensenada", + "America/Fort_Nelson", + "America/Fort_Wayne", + "America/Fortaleza", + "America/Glace_Bay", + "America/Godthab", + "America/Goose_Bay", + "America/Grand_Turk", + "America/Grenada", + "America/Guadeloupe", + "America/Guatemala", + "America/Guayaquil", + "America/Guyana", + "America/Halifax", + "America/Havana", + "America/Hermosillo", + "America/Indiana/Indianapolis", + "America/Indiana/Knox", + "America/Indiana/Marengo", + "America/Indiana/Petersburg", + "America/Indiana/Tell_City", + "America/Indiana/Vevay", + "America/Indiana/Vincennes", + "America/Indiana/Winamac", + "America/Indianapolis", + "America/Inuvik", + "America/Iqaluit", + "America/Jamaica", + "America/Jujuy", + "America/Juneau", + "America/Kentucky/Louisville", + "America/Kentucky/Monticello", + "America/Knox_IN", + "America/Kralendijk", + "America/La_Paz", + "America/Lima", + "America/Los_Angeles", + "America/Louisville", + "America/Lower_Princes", + "America/Maceio", + "America/Managua", + "America/Manaus", + "America/Marigot", + "America/Martinique", + "America/Matamoros", + "America/Mazatlan", + "America/Mendoza", + "America/Menominee", + "America/Merida", + "America/Metlakatla", + "America/Mexico_City", + "America/Miquelon", + "America/Moncton", + "America/Monterrey", + "America/Montevideo", + "America/Montreal", + "America/Montserrat", + "America/Nassau", + "America/New_York", + "America/Nipigon", + "America/Nome", + "America/Noronha", + "America/North_Dakota/Beulah", + "America/North_Dakota/Center", + "America/North_Dakota/New_Salem", + "America/Nuuk", + "America/Ojinaga", + "America/Panama", + "America/Pangnirtung", + "America/Paramaribo", + "America/Phoenix", + "America/Port-au-Prince", + "America/Port_of_Spain", + "America/Porto_Acre", + "America/Porto_Velho", + "America/Puerto_Rico", + "America/Punta_Arenas", + "America/Rainy_River", + "America/Rankin_Inlet", + "America/Recife", + "America/Regina", + "America/Resolute", + "America/Rio_Branco", + "America/Rosario", + "America/Santa_Isabel", + "America/Santarem", + "America/Santiago", + "America/Santo_Domingo", + "America/Sao_Paulo", + "America/Scoresbysund", + "America/Shiprock", + "America/Sitka", + "America/St_Barthelemy", + "America/St_Johns", + "America/St_Kitts", + "America/St_Lucia", + "America/St_Thomas", + "America/St_Vincent", + "America/Swift_Current", + "America/Tegucigalpa", + "America/Thule", + "America/Thunder_Bay", + "America/Tijuana", + "America/Toronto", + "America/Tortola", + "America/Vancouver", + "America/Virgin", + "America/Whitehorse", + "America/Winnipeg", + "America/Yakutat", + "America/Yellowknife", + "Antarctica/Casey", + "Antarctica/Davis", + "Antarctica/DumontDUrville", + "Antarctica/Macquarie", + "Antarctica/Mawson", + "Antarctica/McMurdo", + "Antarctica/Palmer", + "Antarctica/Rothera", + "Antarctica/South_Pole", + "Antarctica/Syowa", + "Antarctica/Troll", + "Antarctica/Vostok", + "Arctic/Longyearbyen", + "Asia/Aden", + "Asia/Almaty", + "Asia/Amman", + "Asia/Anadyr", + "Asia/Aqtau", + "Asia/Aqtobe", + "Asia/Ashgabat", + "Asia/Ashkhabad", + "Asia/Atyrau", + "Asia/Baghdad", + "Asia/Bahrain", + "Asia/Baku", + "Asia/Bangkok", + "Asia/Barnaul", + "Asia/Beirut", + "Asia/Bishkek", + "Asia/Brunei", + "Asia/Calcutta", + "Asia/Chita", + "Asia/Choibalsan", + "Asia/Chongqing", + "Asia/Chungking", + "Asia/Colombo", + "Asia/Dacca", + "Asia/Damascus", + "Asia/Dhaka", + "Asia/Dili", + "Asia/Dubai", + "Asia/Dushanbe", + "Asia/Famagusta", + "Asia/Gaza", + "Asia/Harbin", + "Asia/Hebron", + "Asia/Ho_Chi_Minh", + "Asia/Hong_Kong", + "Asia/Hovd", + "Asia/Irkutsk", + "Asia/Istanbul", + "Asia/Jakarta", + "Asia/Jayapura", + "Asia/Jerusalem", + "Asia/Kabul", + "Asia/Kamchatka", + "Asia/Karachi", + "Asia/Kashgar", + "Asia/Kathmandu", + "Asia/Katmandu", + "Asia/Khandyga", + "Asia/Kolkata", + "Asia/Krasnoyarsk", + "Asia/Kuala_Lumpur", + "Asia/Kuching", + "Asia/Kuwait", + "Asia/Macao", + "Asia/Macau", + "Asia/Magadan", + "Asia/Makassar", + "Asia/Manila", + "Asia/Muscat", + "Asia/Nicosia", + "Asia/Novokuznetsk", + "Asia/Novosibirsk", + "Asia/Omsk", + "Asia/Oral", + "Asia/Phnom_Penh", + "Asia/Pontianak", + "Asia/Pyongyang", + "Asia/Qatar", + "Asia/Qostanay", + "Asia/Qyzylorda", + "Asia/Rangoon", + "Asia/Riyadh", + "Asia/Saigon", + "Asia/Sakhalin", + "Asia/Samarkand", + "Asia/Seoul", + "Asia/Shanghai", + "Asia/Singapore", + "Asia/Srednekolymsk", + "Asia/Taipei", + "Asia/Tashkent", + "Asia/Tbilisi", + "Asia/Tehran", + "Asia/Tel_Aviv", + "Asia/Thimbu", + "Asia/Thimphu", + "Asia/Tokyo", + "Asia/Tomsk", + "Asia/Ujung_Pandang", + "Asia/Ulaanbaatar", + "Asia/Ulan_Bator", + "Asia/Urumqi", + "Asia/Ust-Nera", + "Asia/Vientiane", + "Asia/Vladivostok", + "Asia/Yakutsk", + "Asia/Yangon", + "Asia/Yekaterinburg", + "Asia/Yerevan", + "Atlantic/Azores", + "Atlantic/Bermuda", + "Atlantic/Canary", + "Atlantic/Cape_Verde", + "Atlantic/Faeroe", + "Atlantic/Faroe", + "Atlantic/Jan_Mayen", + "Atlantic/Madeira", + "Atlantic/Reykjavik", + "Atlantic/South_Georgia", + "Atlantic/St_Helena", + "Atlantic/Stanley", + "Australia/ACT", + "Australia/Adelaide", + "Australia/Brisbane", + "Australia/Broken_Hill", + "Australia/Canberra", + "Australia/Currie", + "Australia/Darwin", + "Australia/Eucla", + "Australia/Hobart", + "Australia/LHI", + "Australia/Lindeman", + "Australia/Lord_Howe", + "Australia/Melbourne", + "Australia/North", + "Australia/NSW", + "Australia/Perth", + "Australia/Queensland", + "Australia/South", + "Australia/Sydney", + "Australia/Tasmania", + "Australia/Victoria", + "Australia/West", + "Australia/Yancowinna", + "Brazil/Acre", + "Brazil/DeNoronha", + "Brazil/East", + "Brazil/West", + "Canada/Atlantic", + "Canada/Central", + "Canada/Eastern", + "Canada/Mountain", + "Canada/Newfoundland", + "Canada/Pacific", + "Canada/Saskatchewan", + "Canada/Yukon", + "CET", + "Chile/Continental", + "Chile/EasterIsland", + "CST6CDT", + "Cuba", + "EET", + "Egypt", + "Eire", + "EST", + "EST5EDT", + "Etc/GMT", + "Etc/GMT+0", + "Etc/GMT+1", + "Etc/GMT+10", + "Etc/GMT+11", + "Etc/GMT+12", + "Etc/GMT+2", + "Etc/GMT+3", + "Etc/GMT+4", + "Etc/GMT+5", + "Etc/GMT+6", + "Etc/GMT+7", + "Etc/GMT+8", + "Etc/GMT+9", + "Etc/GMT-0", + "Etc/GMT-1", + "Etc/GMT-10", + "Etc/GMT-11", + "Etc/GMT-12", + "Etc/GMT-13", + "Etc/GMT-14", + "Etc/GMT-2", + "Etc/GMT-3", + "Etc/GMT-4", + "Etc/GMT-5", + "Etc/GMT-6", + "Etc/GMT-7", + "Etc/GMT-8", + "Etc/GMT-9", + "Etc/GMT0", + "Etc/Greenwich", + "Etc/UCT", + "Etc/Universal", + "Etc/UTC", + "Etc/Zulu", + "Europe/Amsterdam", + "Europe/Andorra", + "Europe/Astrakhan", + "Europe/Athens", + "Europe/Belfast", + "Europe/Belgrade", + "Europe/Berlin", + "Europe/Bratislava", + "Europe/Brussels", + "Europe/Bucharest", + "Europe/Budapest", + "Europe/Busingen", + "Europe/Chisinau", + "Europe/Copenhagen", + "Europe/Dublin", + "Europe/Gibraltar", + "Europe/Guernsey", + "Europe/Helsinki", + "Europe/Isle_of_Man", + "Europe/Istanbul", + "Europe/Jersey", + "Europe/Kaliningrad", + "Europe/Kiev", + "Europe/Kirov", + "Europe/Kyiv", + "Europe/Lisbon", + "Europe/Ljubljana", + "Europe/London", + "Europe/Luxembourg", + "Europe/Madrid", + "Europe/Malta", + "Europe/Mariehamn", + "Europe/Minsk", + "Europe/Monaco", + "Europe/Moscow", + "Europe/Nicosia", + "Europe/Oslo", + "Europe/Paris", + "Europe/Podgorica", + "Europe/Prague", + "Europe/Riga", + "Europe/Rome", + "Europe/Samara", + "Europe/San_Marino", + "Europe/Sarajevo", + "Europe/Saratov", + "Europe/Simferopol", + "Europe/Skopje", + "Europe/Sofia", + "Europe/Stockholm", + "Europe/Tallinn", + "Europe/Tirane", + "Europe/Tiraspol", + "Europe/Ulyanovsk", + "Europe/Uzhgorod", + "Europe/Vaduz", + "Europe/Vatican", + "Europe/Vienna", + "Europe/Vilnius", + "Europe/Volgograd", + "Europe/Warsaw", + "Europe/Zagreb", + "Europe/Zaporozhye", + "Europe/Zurich", + "Factory", + "GB", + "GB-Eire", + "GMT", + "GMT+0", + "GMT-0", + "GMT0", + "Greenwich", + "Hongkong", + "HST", + "Iceland", + "Indian/Antananarivo", + "Indian/Chagos", + "Indian/Christmas", + "Indian/Cocos", + "Indian/Comoro", + "Indian/Kerguelen", + "Indian/Mahe", + "Indian/Maldives", + "Indian/Mauritius", + "Indian/Mayotte", + "Indian/Reunion", + "Iran", + "Israel", + "Jamaica", + "Japan", + "Kwajalein", + "Libya", + "MET", + "Mexico/BajaNorte", + "Mexico/BajaSur", + "Mexico/General", + "MST", + "MST7MDT", + "Navajo", + "NZ", + "NZ-CHAT", + "Pacific/Apia", + "Pacific/Auckland", + "Pacific/Bougainville", + "Pacific/Chatham", + "Pacific/Chuuk", + "Pacific/Easter", + "Pacific/Efate", + "Pacific/Enderbury", + "Pacific/Fakaofo", + "Pacific/Fiji", + "Pacific/Funafuti", + "Pacific/Galapagos", + "Pacific/Gambier", + "Pacific/Guadalcanal", + "Pacific/Guam", + "Pacific/Honolulu", + "Pacific/Johnston", + "Pacific/Kanton", + "Pacific/Kiritimati", + "Pacific/Kosrae", + "Pacific/Kwajalein", + "Pacific/Majuro", + "Pacific/Marquesas", + "Pacific/Midway", + "Pacific/Nauru", + "Pacific/Niue", + "Pacific/Norfolk", + "Pacific/Noumea", + "Pacific/Pago_Pago", + "Pacific/Palau", + "Pacific/Pitcairn", + "Pacific/Pohnpei", + "Pacific/Ponape", + "Pacific/Port_Moresby", + "Pacific/Rarotonga", + "Pacific/Saipan", + "Pacific/Samoa", + "Pacific/Tahiti", + "Pacific/Tarawa", + "Pacific/Tongatapu", + "Pacific/Truk", + "Pacific/Wake", + "Pacific/Wallis", + "Pacific/Yap", + "Poland", + "Portugal", + "PRC", + "PST8PDT", + "ROC", + "ROK", + "Singapore", + "Turkey", + "UCT", + "Universal", + "US/Alaska", + "US/Aleutian", + "US/Arizona", + "US/Central", + "US/East-Indiana", + "US/Eastern", + "US/Hawaii", + "US/Indiana-Starke", + "US/Michigan", + "US/Mountain", + "US/Pacific", + "US/Samoa", + "UTC", + "W-SU", + "WET", + "Zulu", +]; diff --git a/components/pidj/package.json b/components/pidj/package.json index 3f12de9287127..989a92e885610 100644 --- a/components/pidj/package.json +++ b/components/pidj/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/pidj", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Pidj Components", "main": "pidj.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.5" } } + diff --git a/components/pidj/pidj.app.mjs b/components/pidj/pidj.app.mjs index 68c0c5abb8f6b..30bfed651a7eb 100644 --- a/components/pidj/pidj.app.mjs +++ b/components/pidj/pidj.app.mjs @@ -4,115 +4,121 @@ export default { type: "app", app: "pidj", propDefinitions: { - contactInformation: { - type: "object", - label: "Contact's Information", - description: "The contact's information including name, email, and phone number.", - }, - additionalNotes: { - type: "string", - label: "Additional Notes", - description: "Any additional notes related to the contact.", - optional: true, - }, - tags: { - type: "string[]", - label: "Tags", - description: "Tags related to the contact.", - optional: true, - }, - recipientPhoneNumber: { - type: "string", - label: "Recipient's Phone Number", - description: "The phone number of the message recipient.", - }, - messageText: { + contactId: { type: "string", - label: "Message Text", - description: "The text of the message to be sent.", + label: "Contact ID", + description: "The ID of the contact.", + async options() { + const { contacts } = await this.listContacts(); + + return contacts.map(({ + id: value, first_name, last_name, display_name, phone_number, + }) => ({ + label: (first_name && last_name) + ? `${first_name} ${last_name}` + : `${display_name || phone_number}`, + value, + })); + }, }, - scheduledSendTime: { + groupId: { type: "string", - label: "Scheduled Send Time", - description: "The scheduled time to send the message, in ISO 8601 format.", + label: "Group Id", + description: "The Id of the group.", + async options() { + const { groups } = await this.listGroups(); + + return groups.map(({ + group_id: value, name: label, + }) => ({ + label, + value, + })); + }, optional: true, }, surveyId: { type: "string", label: "Survey ID", description: "The ID of the survey to be triggered.", + async options() { + const { surveys } = await this.listSurveys(); + + return surveys.map(({ + survey_id: value, name: label, + }) => ({ + label, + value, + })); + }, }, - scheduleTimeForSurvey: { + fromNumber: { type: "string", - label: "Schedule Time for Survey", - description: "The scheduled time to initiate the survey, in ISO 8601 format.", - optional: true, + label: "From Number", + description: "Phone number to send from; this will determine which group the message sends from, and must be an active number from one of your groups. This must be in E.164 format, e.g., +18885552222", + }, + toNumber: { + type: "string", + label: "To Number", + description: "Phone number to send to. This must be in E.164 format, e.g., +18885553333.", }, }, methods: { _baseUrl() { - return "https://api.gopidj.com"; + return "https://api.gopidj.com/api/2020"; }, - async _makeRequest(opts = {}) { - const { - $ = this, - method = "GET", - path, - data, - params, - headers, - ...otherOpts - } = opts; + _auth() { + return { + username: `${this.$auth.account_key}`, + password: `${this.$auth.token}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - method, url: this._baseUrl() + path, + auth: this._auth(), headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${this.$auth.oauth_access_token}`, - ...headers, + "Content-Type": "application/x-www-form-urlencoded", }, - data, - params, - ...otherOpts, + ...opts, }); }, - async addContact({ - contactInformation, additionalNotes, tags, - }) { + addContact(opts = {}) { return this._makeRequest({ method: "POST", + path: "/contact", + ...opts, + }); + }, + listGroups() { + return this._makeRequest({ + path: "/groups", + }); + }, + listSurveys() { + return this._makeRequest({ + path: "/surveys", + }); + }, + listContacts() { + return this._makeRequest({ path: "/contacts", - data: { - contactInformation, - additionalNotes, - tags, - }, }); }, - async sendMessage({ - recipientPhoneNumber, messageText, scheduledSendTime, - }) { + triggerSurvey(opts = {}) { return this._makeRequest({ method: "POST", - path: "/messages/send", - data: { - recipientPhoneNumber, - messageText, - scheduledSendTime, - }, + path: "/survey/initiate", + ...opts, }); }, - async triggerSurvey({ - contactInformation, surveyId, scheduleTimeForSurvey, - }) { + sendMessage(opts = {}) { return this._makeRequest({ method: "POST", - path: "/surveys/trigger", - data: { - contactInformation, - surveyId, - scheduleTimeForSurvey, - }, + path: "/send", + ...opts, }); }, }, From c81b7d8c60c7ad69358ae6ce295718e73381d10f Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 17 May 2024 11:42:20 -0300 Subject: [PATCH 3/5] pnpm update --- pnpm-lock.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6465f2033bb63..7d30a045deac1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6203,7 +6203,10 @@ importers: '@pipedream/platform': 1.5.1 components/pidj: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.5 + dependencies: + '@pipedream/platform': 1.6.5 components/piggy: specifiers: From 9ce4f7e0d250ed9de2c5218cdf0ed4a87e70e6e6 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Wed, 10 Jul 2024 17:03:44 -0300 Subject: [PATCH 4/5] some adjusts --- .../actions/initiate-survey/initiate-survey.mjs | 14 +------------- .../pidj/actions/send-message/send-message.mjs | 2 +- components/pidj/package.json | 3 +-- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/components/pidj/actions/initiate-survey/initiate-survey.mjs b/components/pidj/actions/initiate-survey/initiate-survey.mjs index d2739548e08f7..d05a665b2f4ee 100644 --- a/components/pidj/actions/initiate-survey/initiate-survey.mjs +++ b/components/pidj/actions/initiate-survey/initiate-survey.mjs @@ -20,14 +20,6 @@ export default { pidj, "contactId", ], - optional: true, - }, - toNumber: { - propDefinition: [ - pidj, - "toNumber", - ], - optional: true, }, fromNumber: { propDefinition: [ @@ -45,9 +37,6 @@ export default { }, }, async run({ $ }) { - if ((!this.contactId && !this.toNumber) || (this.contactId && this.toNumber)) { - throw new ConfigurationError("You must provide either Contact Id or To Number."); - } if ((!this.fromNumber && !this.groupId) || (this.fromNumber && this.groupId)) { throw new ConfigurationError("You must provide either From Number or Group Id."); } @@ -57,13 +46,12 @@ export default { data: { survey_id: this.surveyId, contact_id: this.contactId, - to_number: this.toNumber, from_number: this.fromNumber, group_id: this.groupId, }, }); - $.export("$summary", `Successfully initiated survey for contact ${this.contactId || this.toNumber}`); + $.export("$summary", `Successfully initiated survey for contact ${this.contactId}`); return response; }, }; diff --git a/components/pidj/actions/send-message/send-message.mjs b/components/pidj/actions/send-message/send-message.mjs index 9ed8b04c93777..a3b6a6ce8606d 100644 --- a/components/pidj/actions/send-message/send-message.mjs +++ b/components/pidj/actions/send-message/send-message.mjs @@ -38,7 +38,7 @@ export default { }); if (response.status != "success") throw new ConfigurationError(response.message); - $.export("$summary", `Message successfully sent to ${this.recipientPhoneNumber}`); + $.export("$summary", `Message successfully sent to ${this.toNumber}`); return response; }, }; diff --git a/components/pidj/package.json b/components/pidj/package.json index 989a92e885610..a088d58551a78 100644 --- a/components/pidj/package.json +++ b/components/pidj/package.json @@ -13,7 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.6.5" + "@pipedream/platform": "^3.0.0" } } - From b4d208d2735bba8560ddb855574ecba54a02a93d Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Wed, 10 Jul 2024 17:04:26 -0300 Subject: [PATCH 5/5] pnpm update --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04954f288d962..47a84ab41285a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6579,9 +6579,9 @@ importers: components/pidj: specifiers: - '@pipedream/platform': ^1.6.5 + '@pipedream/platform': ^3.0.0 dependencies: - '@pipedream/platform': 1.6.5 + '@pipedream/platform': 3.0.0 components/piggy: specifiers: