Skip to content

Commit

Permalink
feat: pipedrive support - lead, company, contact, deal (#168)
Browse files Browse the repository at this point in the history
* feat: pipedrive support - lead, company, contect, deal

* add breaks

* pipedrive event / note / task

* update sdk ui

* update sdk func for redirection logic

* scope selectedIntegrationId better

* api minor fixes

* pipedrive user apis

* pipedrive event and task

* add coming soon integrations; and sdk ui fixes

* add css coming soon title

* Resolve conflicts

* 🐞 Error handling

* revert error handling
  • Loading branch information
hvinder authored Aug 5, 2023
1 parent 869850d commit 2b93669
Show file tree
Hide file tree
Showing 19 changed files with 2,886 additions and 1,839 deletions.
12 changes: 7 additions & 5 deletions fern/api/definition/common/unified.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ types:
docs: Name of the company in a CRM.
industry:
type: string
docs: Industry associated with this company.
docs: Industry associated with this company. (not supported by pipedrive)
description:
type: string
docs: Description of the company.
annualRevenue: integer
docs: Description of the company. (not supported by pipedrive)
annualRevenue:
type: integer
docs: Annual revenue of the company. (not supported by pipedrive)
size:
type: integer
docs: Number of employees or size of the company.
phone:
type: string
docs: Phone number of the company.
docs: Phone number of the company. (not supported by pipedrive)
address:
type: CompanyAddress
docs: Company address.
Expand Down Expand Up @@ -142,7 +144,7 @@ types:
docs: Body of the task description.
priority:
type: string
docs: The priority of the task in hand.
docs: The priority of the task in hand. (not supported by pipedrive)
status:
type: string
docs: Completion status of the task.
Expand Down
227 changes: 225 additions & 2 deletions packages/backend/constants/pipedrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface PipedriveContact {
cc_email: string;
}

export interface PipedriveOrganization {
export interface PipedriveCompany {
id: string;
company_id: number;
owner_id: {
Expand Down Expand Up @@ -181,5 +181,228 @@ export interface PipedriveLead {
visible_to: string;
cc_email: string;
person: Partial<PipedriveContact>;
organization: Partial<PipedriveOrganization>;
organization: Partial<PipedriveCompany>;
}

export interface PipedriveDeal {
id: string;
creator_user_id: {
id: string;
name: string;
email: string;
has_pic: boolean;
active_flag: boolean;
value: number;
};
user_id: {
id: string;
name: string;
email: string;
has_pic: boolean;
active_flag: boolean;
value: string;
};
person_id: {
active_flag: boolean;
name: string;
email: { label: string; value: string; primary: boolean }[];
phone: { label: string; value: string; primary: boolean }[];
value: string;
};
org_id: {
name: string;
people_count: number;
owner_id: string;
address: string;
active_flag: boolean;
cc_email: string;
value: string;
};
stage_id: string;
title: string;
value: number;
currency: string;
add_time: Date;
update_time: Date;
stage_change_time: Date;
active: boolean;
deleted: boolean;
status: string;
probability: number;
next_activity_date: string;
next_activity_time: string;
next_activity_id: string;
last_activity_id: string;
last_activity_date: string;
lost_reason: string;
visible_to: string;
close_time: Date;
pipeline_id: string;
won_time: Date;
first_won_time: Date;
lost_time: string;
products_count: number;
files_count: number;
notes_count: number;
followers_count: number;
email_messages_count: number;
activities_count: number;
done_activities_count: number;
undone_activities_count: number;
participants_count: number;
expected_close_date: string;
last_incoming_mail_time: string;
last_outgoing_mail_time: string;
label: string;
stage_order_nr: number;
person_name: string;
org_name: string;
next_activity_subject: string;
next_activity_type: string;
next_activity_duration: string;
next_activity_note: string;
formatted_value: string;
weighted_value: string;
formatted_weighted_value: string;
weighted_value_currency: string;
rotten_time: string;
owner_name: string;
cc_email: string;
org_hidden: boolean;
person_hidden: boolean;
// average_time_to_won: { y: 0; m: 0; d: 0; h: 0; i: 20; s: 49; total_seconds: 1249 };
// average_stage_progress: 4.99;
// age: { y: 0; m: 6; d: 14; h: 8; i: 57; s: 26; total_seconds: 17139446 };
// stay_in_pipeline_stages: {
// times_in_stages: { '1': 15721267; '2': 1288449; '3': 4368; '4': 3315; '5': 26460 };
// order_of_stages: [1, 2, 3, 4, 5];
// };
last_activity: any;
next_activity: any;
}

export interface PipedriveEvent {
id: string;
company_id: string;
user_id: string;
done: boolean;
type: string;
reference_type: string;
reference_id: string;
conference_meeting_client: string;
conference_meeting_url: string;
conference_meeting_id: string;
due_date: string;
due_time: string;
duration: string;
busy_flag: boolean;
add_time: string;
marked_as_done_time: string;
last_notification_time: Date;
last_notification_user_id: string;
notification_language_id: string;
subject: string;
public_description: string;
calendar_sync_include_context: string;
location: string;
org_id: string;
person_id: string;
deal_id: string;
lead_id: string;
project_id: string;
active_flag: boolean;
update_time: Date;
update_user_id: string;
gcal_event_id: string;
google_calendar_id: string;
google_calendar_etag: string;
source_timezone: string;
rec_rule: string;
rec_rule_extension: string;
rec_master_activity_id: string;
series: any[];
note: string;
created_by_user_id: string;
location_subpremise: string;
location_street_number: string;
location_route: string;
location_sublocality: string;
location_locality: string;
location_admin_area_level_1: string;
location_admin_area_level_2: string;
location_country: string;
location_postal_code: string;
location_formatted_address: string;
attendees: {
email_address: string;
is_organizer: any;
name: string;
person_id: string;
status: string;
user_id: string;
}[];
participants: { person_id: string; primary_flag: boolean }[];
org_name: string;
person_name: string;
deal_title: string;
owner_name: string;
person_dropbox_bcc: string;
deal_dropbox_bcc: string;
assigned_to_user_id: string;
file: {
id: string;
clean_name: string;
url: string;
};
}

export interface PipedriveNote {
id: string;
active_flag: boolean;
add_time: Date;
content: string;
deal: { title: string };
lead_id: string;
deal_id: string;
last_update_user_id: string;
org_id: string;
organization: { name: string };
person: { name: string };
person_id: string;
pinned_to_lead_flag: boolean;
pinned_to_deal_flag: boolean;
pinned_to_organization_flag: boolean;
pinned_to_person_flag: boolean;
update_time: Date;
user: {
email: string;
icon_url: string;
is_you: boolean;
name: string;
};
user_id: string;
}

export interface PipedriveTask extends PipedriveEvent {}

export interface PipedriveUser {
id: string;
name: string;
default_currency: string;
locale: string;
lang: string;
email: string;
phone: string;
activated: boolean;
last_login: Date;
created: Date;
modified: Date;
has_created_company: boolean;
access: { app: string; admin: boolean; permission_set_id: string }[];
active_flag: boolean;
timezone_name: string;
timezone_offset: string;
role_id: string;
icon_url: string;
is_you: boolean;
}
82 changes: 68 additions & 14 deletions packages/backend/models/unified/company.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { TP_ID } from '@prisma/client';
import { PipedriveCompany } from '../../constants/pipedrive';

export interface UnifiedCompany {
name: string;
industry: string;
description: string;
annualRevenue: number;
industry: string; // not supported by pipedrive
description: string; // not supported by pipedrive
annualRevenue: number; // not supported by pipedrive
size: number;
phone: string;
phone: string; // not supported by pipedrive
address: {
street: string; // Note: No street field in Hubspot.
city: string;
Expand Down Expand Up @@ -32,8 +35,18 @@ export function unifyCompany(company: any): UnifiedCompany {
phone: company.phone || company.Phone || company.phone,
address: {
street:
company.street || company.BillingAddress?.street || company.address?.street || company.Billing_Street,
city: company.city || company.City || company.city || company.BillingAddress?.city || company.Billing_City,
company.street ||
company.BillingAddress?.street ||
company.address?.street ||
company.Billing_Street ||
company.address_street_number,
city:
company.city ||
company.City ||
company.city ||
company.BillingAddress?.city ||
company.Billing_City ||
company.address_locality,
state:
company.state ||
company.State ||
Expand All @@ -45,9 +58,20 @@ export function unifyCompany(company: any): UnifiedCompany {
company.Country ||
company.country ||
company.BillingAddress?.country ||
company.Billing_Country,
zip: company.zip || company.Zip || company.zip || company.BillingAddress?.zipCode || company.Billing_Code,
postalCode: company.postalCode || company.BillingAddress?.postalCode || company.Billing_Code,
company.Billing_Country ||
company.address_country,
zip:
company.zip ||
company.Zip ||
company.zip ||
company.BillingAddress?.zipCode ||
company.Billing_Code ||
company.address_postal_code,
postalCode:
company.postalCode ||
company.BillingAddress?.postalCode ||
company.Billing_Code ||
company.address_postal_code,
},
industry: company.industry || company.Industry || company.industry,
size:
Expand All @@ -62,13 +86,15 @@ export function unifyCompany(company: any): UnifiedCompany {
company.Created_Time ||
company.created_date ||
company.createdate ||
company.CreatedDate,
company.CreatedDate ||
company.add_time,
updatedTimestamp:
company.modifiedDate ||
company.Modified_Time ||
company.modified_date ||
company.hs_lastmodifieddate ||
company.LastModifiedDate,
company.LastModifiedDate ||
company.update_time,
additional: {},
};

Expand Down Expand Up @@ -555,12 +581,40 @@ export function toHubspotCompany(unifiedCompany: UnifiedCompany): Partial<Hubspo
return hubspotCompany;
}

export function toPipedriveCompany(unifiedCompany: UnifiedCompany): Partial<PipedriveCompany> {
const pipedriveCompany: any = {
id: unifiedCompany.remoteId,
name: unifiedCompany.name,
// industry: unifiedCompany.industry,
// description: unifiedCompany.description,
// annualRevenue: unifiedCompany.annualRevenue,
people_count: unifiedCompany.size,
// phone: unifiedCompany.phone,
address_street_number: unifiedCompany.address?.street,
address_locality: unifiedCompany.address?.city,
// state: unifiedCompany.address?.state,
address_country: unifiedCompany.address?.country,
address_postal_code: unifiedCompany.address?.postalCode || unifiedCompany.address?.zip,
};

// Map custom fields
if (unifiedCompany.additional) {
Object.keys(unifiedCompany.additional).forEach((key) => {
pipedriveCompany[key] = unifiedCompany.additional?.[key];
});
}

return pipedriveCompany;
}

export function disunifyCompany(company: UnifiedCompany, integrationId: string): any {
if (integrationId === 'sfdc') {
if (integrationId === TP_ID.sfdc) {
return toSalesforceCompany(company);
} else if (integrationId === 'hubspot') {
} else if (integrationId === TP_ID.hubspot) {
return toHubspotCompany(company);
} else if (integrationId === 'zohocrm') {
} else if (integrationId === TP_ID.zohocrm) {
return toZohoCompany(company);
} else if (integrationId === TP_ID.pipedrive) {
return toPipedriveCompany(company);
}
}
Loading

1 comment on commit 2b93669

@vercel
Copy link

@vercel vercel bot commented on 2b93669 Aug 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.