diff --git a/components/adversus/README.md b/components/adversus/README.md index 2b8eb661c57d8..3632ebc495b58 100644 --- a/components/adversus/README.md +++ b/components/adversus/README.md @@ -2,6 +2,10 @@ Adversus is a powerful dialer and CRM platform tailored to streamline outbound call center operations and enhance sales processes. Leveraging the Adversus API with Pipedream opens up immense possibilities for automating call workflows, syncing lead data, and crafting custom triggers based on call outcomes or performance metrics. By creating serverless workflows on Pipedream, you can connect Adversus to a myriad of other apps and services to optimize lead management, automate repetitive tasks, and gain real-time insights into your sales funnel. +# API Documentation + +For detailed API documentation, please refer to: https://solutions.adversus.io/api + # Example Use Cases - **Automated Lead Syncing with CRM**: Whenever a new lead is added to Adversus, the workflow automatically syncs this lead to your chosen CRM, such as Salesforce or HubSpot. It ensures that any updates made by the sales team in Adversus reflect in the CRM, keeping both systems in harmony and up-to-date. diff --git a/components/adversus/actions/add-note-activity/add-note-activity.mjs b/components/adversus/actions/add-note-activity/add-note-activity.mjs new file mode 100644 index 0000000000000..cc4075f47b643 --- /dev/null +++ b/components/adversus/actions/add-note-activity/add-note-activity.mjs @@ -0,0 +1,89 @@ +import adversus from "../../adversus.app.mjs"; + +export default { + key: "adversus-add-note-activity", + name: "Add Note or Activity", + description: "Add a note or activity to a lead in Adversus. [See the API documentation](https://solutions.adversus.io/api).", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + adversus, + leadId: { + propDefinition: [ + adversus, + "leadId", + ], + }, + note: { + type: "string", + label: "Note", + description: "The note text to add to the lead", + optional: true, + }, + activityType: { + type: "string", + label: "Activity Type", + description: "The type of activity (e.g., 'call', 'email', 'meeting')", + optional: true, + }, + activityDescription: { + type: "string", + label: "Activity Description", + description: "The description of the activity", + optional: true, + }, + additionalFields: { + type: "object", + label: "Additional Fields", + description: "Additional fields to include in the note or activity", + optional: true, + }, + }, + /** + * Execute the action to add a note or activity to a lead + * @param {Object} $ - Pipedream context + * @returns {Promise} The response from adding note/activity + */ + async run({ $ }) { + const promises = []; + + if (this.note) { + promises.push( + this.adversus.addNoteToLead(this.leadId, { + data: { + note: this.note, + ...(this.additionalFields || {}), + }, + }) + ); + } + + if (this.activityType || this.activityDescription) { + promises.push( + this.adversus.addActivityToLead(this.leadId, { + data: { + ...(this.activityType && { type: this.activityType }), + ...(this.activityDescription && { description: this.activityDescription }), + ...(this.additionalFields || {}), + }, + }) + ); + } + + if (promises.length === 0) { + throw new Error("Either 'Note' or 'Activity Type'/'Activity Description' must be provided"); + } + + const results = await Promise.all(promises); + + $.export("$summary", `Successfully added ${promises.length} item(s) to lead ${this.leadId}`); + + return results.length === 1 ? results[0] : results; + }, +}; + diff --git a/components/adversus/actions/assign-to-campaign/assign-to-campaign.mjs b/components/adversus/actions/assign-to-campaign/assign-to-campaign.mjs new file mode 100644 index 0000000000000..acc131ea4918e --- /dev/null +++ b/components/adversus/actions/assign-to-campaign/assign-to-campaign.mjs @@ -0,0 +1,52 @@ +import adversus from "../../adversus.app.mjs"; + +export default { + key: "adversus-assign-to-campaign", + name: "Assign Lead to Campaign", + description: "Assign a lead to a campaign in Adversus. [See the API documentation](https://solutions.adversus.io/api).", + version: "0.0.1", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + adversus, + leadId: { + propDefinition: [ + adversus, + "leadId", + ], + }, + campaignId: { + propDefinition: [ + adversus, + "campaignId", + ], + }, + additionalFields: { + type: "object", + label: "Additional Fields", + description: "Additional fields to include when assigning to campaign", + optional: true, + }, + }, + /** + * Execute the action to assign a lead to a campaign + * @param {Object} $ - Pipedream context + * @returns {Promise} The response from assigning the lead to campaign + */ + async run({ $ }) { + const response = await this.adversus.assignLeadToCampaign(this.leadId, this.campaignId, { + data: { + ...(this.additionalFields || {}), + }, + }); + + $.export("$summary", `Successfully assigned lead ${this.leadId} to campaign ${this.campaignId}`); + + return response; + }, +}; + diff --git a/components/adversus/actions/change-lead-status/change-lead-status.mjs b/components/adversus/actions/change-lead-status/change-lead-status.mjs new file mode 100644 index 0000000000000..995d543cf1cb4 --- /dev/null +++ b/components/adversus/actions/change-lead-status/change-lead-status.mjs @@ -0,0 +1,52 @@ +import adversus from "../../adversus.app.mjs"; + +export default { + key: "adversus-change-lead-status", + name: "Change Lead Status", + description: "Change the status of a lead in Adversus. [See the API documentation](https://solutions.adversus.io/api).", + version: "0.0.1", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + adversus, + leadId: { + propDefinition: [ + adversus, + "leadId", + ], + }, + statusId: { + propDefinition: [ + adversus, + "statusId", + ], + }, + additionalFields: { + type: "object", + label: "Additional Fields", + description: "Additional fields to include when changing the status", + optional: true, + }, + }, + /** + * Execute the action to change a lead's status + * @param {Object} $ - Pipedream context + * @returns {Promise} The response from changing the lead status + */ + async run({ $ }) { + const response = await this.adversus.changeLeadStatus(this.leadId, this.statusId, { + data: { + ...(this.additionalFields || {}), + }, + }); + + $.export("$summary", `Successfully changed status of lead ${this.leadId} to status ${this.statusId}`); + + return response; + }, +}; + diff --git a/components/adversus/actions/create-or-update-lead/create-or-update-lead.mjs b/components/adversus/actions/create-or-update-lead/create-or-update-lead.mjs new file mode 100644 index 0000000000000..9b9b2b02d6c79 --- /dev/null +++ b/components/adversus/actions/create-or-update-lead/create-or-update-lead.mjs @@ -0,0 +1,84 @@ +import adversus from "../../adversus.app.mjs"; + +export default { + key: "adversus-create-or-update-lead", + name: "Create or Update Lead", + description: "Create a new lead or update an existing lead in Adversus. [See the API documentation](https://solutions.adversus.io/api).", + version: "0.0.1", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + adversus, + firstName: { + type: "string", + label: "First Name", + description: "The first name of the lead", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "The last name of the lead", + optional: true, + }, + email: { + type: "string", + label: "Email", + description: "The email address of the lead", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "The phone number of the lead", + optional: true, + }, + leadId: { + propDefinition: [ + adversus, + "leadId", + ], + description: "The ID of the lead to update (leave empty to create a new lead)", + optional: true, + }, + additionalFields: { + type: "object", + label: "Additional Fields", + description: "Additional fields to include in the lead data", + optional: true, + }, + }, + /** + * Execute the action to create or update a lead + * @param {Object} $ - Pipedream context + * @returns {Promise} The created or updated lead response + */ + async run({ $ }) { + const data = { + ...(this.firstName && { firstName: this.firstName }), + ...(this.lastName && { lastName: this.lastName }), + ...(this.email && { email: this.email }), + ...(this.phone && { phone: this.phone }), + ...(this.additionalFields || {}), + }; + + if (!Object.keys(data).length) { + throw new Error("At least one field must be provided to create or update a lead. Please provide firstName, lastName, email, phone, or additionalFields."); + } + + const response = this.leadId + ? await this.adversus.updateLead(this.leadId, { data }) + : await this.adversus.createLead({ data }); + + $.export("$summary", this.leadId + ? `Successfully updated lead ${this.leadId}` + : "Successfully created new lead"); + + return response; + }, +}; + diff --git a/components/adversus/adversus.app.mjs b/components/adversus/adversus.app.mjs index a32a77c136432..3410b58ac02b2 100644 --- a/components/adversus/adversus.app.mjs +++ b/components/adversus/adversus.app.mjs @@ -1,11 +1,150 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "adversus", - propDefinitions: {}, + propDefinitions: { + leadId: { + type: "string", + label: "Lead ID", + description: "The ID of the lead", + }, + campaignId: { + type: "string", + label: "Campaign ID", + description: "The ID of the campaign", + }, + statusId: { + type: "string", + label: "Status ID", + description: "The ID of the lead status", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + /** + * Get authentication credentials for API requests + * @returns {Object} Authentication object with username and password + */ + _auth() { + return { + username: this.$auth.username, + password: this.$auth.password, + }; + }, + /** + * Get the base URL for Adversus API + * @returns {string} Base API URL + */ + _baseUrl() { + return "https://solutions.adversus.io/api"; + }, + /** + * Make an HTTP request to the Adversus API + * @param {Object} opts - Request options + * @param {Object} opts.$ - Pipedream context + * @param {string} opts.path - API endpoint path + * @param {string} [opts.method="GET"] - HTTP method + * @param {...Object} opts - Additional axios options + * @returns {Promise} API response + */ + async _makeRequest({ + $ = this, path, method = "GET", ...opts + }) { + return axios($, { + method, + url: this._baseUrl() + path, + auth: this._auth(), + ...opts, + }); + }, + /** + * Create a new lead in Adversus + * @param {Object} opts - Request options including data payload + * @returns {Promise} The created lead response + */ + async createLead(opts) { + return this._makeRequest({ + path: "/leads", + method: "POST", + ...opts, + }); + }, + /** + * Update an existing lead in Adversus + * @param {string} leadId - The ID of the lead to update + * @param {Object} opts - Request options including data payload + * @returns {Promise} The updated lead response + */ + async updateLead(leadId, opts) { + return this._makeRequest({ + path: `/leads/${leadId}`, + method: "PUT", + ...opts, + }); + }, + /** + * Add a note to a lead in Adversus + * @param {string} leadId - The ID of the lead + * @param {Object} opts - Request options including note data + * @returns {Promise} The response from adding the note + */ + async addNoteToLead(leadId, opts) { + return this._makeRequest({ + path: `/leads/${leadId}/notes`, + method: "POST", + ...opts, + }); + }, + /** + * Add an activity to a lead in Adversus + * @param {string} leadId - The ID of the lead + * @param {Object} opts - Request options including activity data + * @returns {Promise} The response from adding the activity + */ + async addActivityToLead(leadId, opts) { + return this._makeRequest({ + path: `/leads/${leadId}/activities`, + method: "POST", + ...opts, + }); + }, + /** + * Change the status of a lead in Adversus + * @param {string} leadId - The ID of the lead + * @param {string} statusId - The ID of the new status + * @param {Object} [opts={}] - Additional request options + * @returns {Promise} The response from changing the status + */ + async changeLeadStatus(leadId, statusId, opts = {}) { + const { data: optsData, ...restOpts } = opts; + return this._makeRequest({ + path: `/leads/${leadId}/status`, + method: "PUT", + data: { + statusId, + ...(optsData || {}), + }, + ...restOpts, + }); + }, + /** + * Assign a lead to a campaign in Adversus + * @param {string} leadId - The ID of the lead + * @param {string} campaignId - The ID of the campaign + * @param {Object} [opts={}] - Additional request options + * @returns {Promise} The response from assigning the lead + */ + async assignLeadToCampaign(leadId, campaignId, opts = {}) { + const { data: optsData, ...restOpts } = opts; + return this._makeRequest({ + path: `/leads/${leadId}/campaign`, + method: "PUT", + data: { + campaignId, + ...(optsData || {}), + }, + ...restOpts, + }); }, }, }; diff --git a/components/adversus/package.json b/components/adversus/package.json index 76c4aa42dc808..1a3c20d430dad 100644 --- a/components/adversus/package.json +++ b/components/adversus/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/adversus", - "version": "0.6.0", + "version": "0.7.0", "description": "Pipedream adversus Components", "main": "adversus.app.mjs", "keywords": [