diff --git a/components/ringcentral/actions/create-contact/create-contact.mjs b/components/ringcentral/actions/create-contact/create-contact.mjs new file mode 100644 index 0000000000000..0da88cd4a8e19 --- /dev/null +++ b/components/ringcentral/actions/create-contact/create-contact.mjs @@ -0,0 +1,86 @@ +import ringcentral from "../../ringcentral.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + key: "ringcentral-create-contact", + name: "Create Contact", + description: "Creates a user personal contact. [See the documentation](https://developers.ringcentral.com/api-reference/External-Contacts/createContact)", + version: "0.0.1", + type: "action", + props: { + ringcentral, + accountId: { + propDefinition: [ + ringcentral, + "accountId", + ], + }, + extensionId: { + propDefinition: [ + ringcentral, + "extensionId", + ], + description: "Internal identifier of the RingCentral extension/user", + }, + email: { + type: "string", + label: "Email", + description: "Email address of the contact", + optional: true, + }, + firstName: { + type: "string", + label: "First Name", + description: "First name of the contact", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "Last name of the contact", + optional: true, + }, + mobilePhone: { + type: "string", + label: "Mobile Phone", + description: "Mobile phone of the contact", + optional: true, + }, + additionalOptions: { + type: "object", + label: "Additional Options", + description: "Additional parameters to set for the contact. [See the documentation](https://developers.ringcentral.com/api-reference/External-Contacts/createContact) for all available parameters. Values will be parsed as JSON where applicable. Example: `{ \"notes\": \"Notes for the contact\" }`", + optional: true, + }, + }, + methods: { + createContact({ + accountId, extensionId, ...args + }) { + return this.ringcentral.makeRequest({ + method: "POST", + path: `/account/${accountId}/extension/${extensionId}/address-book/contact`, + ...args, + }); + }, + }, + async run({ $ }) { + const { // eslint-disable-next-line no-unused-vars + ringcentral, createContact, accountId, extensionId, additionalOptions, ...data + } = this; + + const response = + await createContact({ + $, + accountId, + extensionId, + data: { + ...data, + ...(additionalOptions && utils.parseObjectEntries(additionalOptions)), + }, + }); + + $.export("$summary", `Successfully created contact (ID: ${response.id})`); + return response; + }, +}; diff --git a/components/ringcentral/actions/send-sms/send-sms.mjs b/components/ringcentral/actions/send-sms/send-sms.mjs index f499deb45fe3f..c0491cc7130f9 100644 --- a/components/ringcentral/actions/send-sms/send-sms.mjs +++ b/components/ringcentral/actions/send-sms/send-sms.mjs @@ -5,7 +5,7 @@ export default { key: "ringcentral-send-sms", name: "Send SMS", description: "Creates and sends a new text message. See the API docs [here](https://developers.ringcentral.com/api-reference/SMS/createSMSMessage)", - version: "0.5.1", + version: "0.5.2", type: "action", props: { ringcentral, diff --git a/components/ringcentral/common/utils.mjs b/components/ringcentral/common/utils.mjs index e45bcbb520666..10b8f98b9f92a 100644 --- a/components/ringcentral/common/utils.mjs +++ b/components/ringcentral/common/utils.mjs @@ -47,8 +47,32 @@ function parse(value) { } } +function optionalParseAsJSON(value) { + try { + return JSON.parse(value); + } catch (e) { + return value; + } +} + +function parseObjectEntries(value) { + const obj = typeof value === "string" + ? JSON.parse(value) + : value; + return Object.fromEntries( + Object.entries(obj).map(([ + key, + value, + ]) => [ + key, + optionalParseAsJSON(value), + ]), + ); +} + export default { emptyStrToUndefined, parse, emptyObjectToUndefined, + parseObjectEntries, }; diff --git a/components/ringcentral/package.json b/components/ringcentral/package.json index c5c5923c0c4a4..f3c72e1610d0d 100644 --- a/components/ringcentral/package.json +++ b/components/ringcentral/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/ringcentral", - "version": "0.4.1", + "version": "0.5.0", "description": "Pipedream Ringcentral Components", "main": "ringcentral.app.mjs", "keywords": [ @@ -14,6 +14,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.2.0" + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 37826898041cc..8d1e7ad9e236e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10893,8 +10893,8 @@ importers: components/ringcentral: dependencies: '@pipedream/platform': - specifier: ^1.2.0 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 components/ringover: dependencies: