diff --git a/components/liveswitch/actions/create-contact/create-contact.mjs b/components/liveswitch/actions/create-contact/create-contact.mjs new file mode 100644 index 0000000000000..b86efd667c144 --- /dev/null +++ b/components/liveswitch/actions/create-contact/create-contact.mjs @@ -0,0 +1,52 @@ +import app from "../../liveswitch.app.mjs"; + +export default { + key: "liveswitch-create-contact", + name: "Create Contact", + description: "Create a contact in LiveSwitch [See the documentation](https://developer.liveswitch.com/reference/post_v1-contacts)", + version: "0.0.1", + type: "action", + props: { + app, + phone: { + propDefinition: [ + app, + "phone", + ], + }, + firstName: { + propDefinition: [ + app, + "firstName", + ], + }, + lastName: { + propDefinition: [ + app, + "lastName", + ], + }, + email: { + propDefinition: [ + app, + "email", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.createContact({ + $, + data: { + phone: this.phone, + firstName: this.firstName, + lastName: this.lastName, + email: this.email, + }, + }); + + $.export("$summary", `Successfully created Contact with ID: ${response.id}`); + + return response; + }, +}; diff --git a/components/liveswitch/actions/create-conversation/create-conversation.mjs b/components/liveswitch/actions/create-conversation/create-conversation.mjs new file mode 100644 index 0000000000000..da0428947a4e7 --- /dev/null +++ b/components/liveswitch/actions/create-conversation/create-conversation.mjs @@ -0,0 +1,38 @@ +import app from "../../liveswitch.app.mjs"; + +export default { + key: "liveswitch-create-conversation", + name: "Create Conversation", + description: "Create a conversation in LiveSwitch [See the documentation](https://developer.liveswitch.com/reference/post_v1-conversations)", + version: "0.0.1", + type: "action", + props: { + app, + contactId: { + propDefinition: [ + app, + "contactId", + ], + }, + message: { + propDefinition: [ + app, + "message", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.createConversation({ + $, + data: { + contactId: this.contactId, + message: this.message, + }, + }); + + $.export("$summary", `Successfully created Conversation with ID: ${response.id}`); + + return response; + }, +}; diff --git a/components/liveswitch/actions/update-contact/update-contact.mjs b/components/liveswitch/actions/update-contact/update-contact.mjs new file mode 100644 index 0000000000000..593488339b62b --- /dev/null +++ b/components/liveswitch/actions/update-contact/update-contact.mjs @@ -0,0 +1,59 @@ +import app from "../../liveswitch.app.mjs"; + +export default { + key: "liveswitch-update-contact", + name: "Update Contact", + description: "Update a contact in LiveSwitch [See the documentation](https://developer.liveswitch.com/reference/post_v1-contacts)", + version: "0.0.1", + type: "action", + props: { + app, + contactId: { + propDefinition: [ + app, + "contactId", + ], + }, + phone: { + propDefinition: [ + app, + "phone", + ], + }, + firstName: { + propDefinition: [ + app, + "firstName", + ], + }, + lastName: { + propDefinition: [ + app, + "lastName", + ], + }, + email: { + propDefinition: [ + app, + "email", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.updateContact({ + $, + contactId: this.contactId, + data: { + phone: this.phone, + firstName: this.firstName, + lastName: this.lastName, + email: this.email, + }, + }); + + $.export("$summary", `Successfully updated Contact with ID: ${this.contactId}`); + + return response; + }, +}; diff --git a/components/liveswitch/liveswitch.app.mjs b/components/liveswitch/liveswitch.app.mjs index 12b2910a584db..f1dd1ce333ed6 100644 --- a/components/liveswitch/liveswitch.app.mjs +++ b/components/liveswitch/liveswitch.app.mjs @@ -1,11 +1,104 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "liveswitch", - propDefinitions: {}, + propDefinitions: { + firstName: { + type: "string", + label: "First Name", + description: "Contact's first name", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "Contact's last name", + optional: true, + }, + email: { + type: "string", + label: "Email", + description: "Contact's email", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "Contact's phone number, i.e.: `+1 407-982-1211`", + }, + message: { + type: "string", + label: "Message", + description: "The contents of the text message the user will receive", + }, + contactId: { + type: "string", + label: "Contact ID", + description: "Contact's ID", + async options() { + const response = await this.getContacts(); + return response.map(({ + id, firstName, lastName, + }) => ({ + value: id, + label: `${firstName} ${lastName}`, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://public-api.production.liveswitch.com/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }, + }); + }, + async createContact(args = {}) { + return this._makeRequest({ + path: "/contacts", + method: "post", + ...args, + }); + }, + async updateContact({ + contactId, ...args + }) { + return this._makeRequest({ + path: `/contacts/${contactId}`, + method: "put", + ...args, + }); + }, + async createConversation(args = {}) { + return this._makeRequest({ + path: "/conversations", + method: "post", + ...args, + }); + }, + async getContacts(args = {}) { + return this._makeRequest({ + path: "/contacts", + params: { + page: 1, + pageSize: 100, + }, + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/liveswitch/package.json b/components/liveswitch/package.json index 46f842a73af2f..ec7cde46285d3 100644 --- a/components/liveswitch/package.json +++ b/components/liveswitch/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/liveswitch", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream LiveSwitch Components", "main": "liveswitch.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ca42551ac236e..1f232171e0596 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5660,7 +5660,10 @@ importers: '@pipedream/platform': 1.5.1 components/liveswitch: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/llama_ai: specifiers: @@ -13180,6 +13183,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: + resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sts' + - aws-crt + dev: false + /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13415,7 +13467,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13457,55 +13509,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: - resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - aws-crt - dev: false - /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17798,7 +17801,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq + '@aws-sdk/client-sts': 3.600.0 '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6