Skip to content

Commit

Permalink
✨ Salesforce crm
Browse files Browse the repository at this point in the history
```
  • Loading branch information
naelob committed Sep 14, 2024
1 parent 8465881 commit c387394
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 28 deletions.
Binary file removed apps/webapp/public/rag/openai.jpg
Binary file not shown.
Binary file modified apps/webapp/public/rag/openai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ CREATE TABLE connector_sets
fs_googledrive boolean NULL,
fs_sharepoint boolean NULL,
fs_onedrive boolean NULL,
crm_salesforce boolean NULL,
CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set )
);

Expand Down
8 changes: 4 additions & 4 deletions packages/api/scripts/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ INSERT INTO users (id_user, identification_strategy, email, password_hash, first
('0ce39030-2901-4c56-8db0-5e326182ec6b', 'b2c','[email protected]', '$2b$10$Y7Q8TWGyGuc5ecdIASbBsuXMo3q/Rs3/cnY.mLZP4tUgfGUOCUBlG', 'local', 'Panora');


INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab, fs_box, tcg_github, hris_deel, hris_sage, ats_ashby, crm_microsoftdynamicssales, ecom_webflow, tcg_linear, ecom_shopify, ecom_woocommerce, ecom_amazon, ecom_squarespace, hris_gusto, fs_googledrive, fs_dropbox, fs_sharepoint, fs_onedrive) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab, fs_box, tcg_github, hris_deel, hris_sage, ats_ashby, crm_microsoftdynamicssales, ecom_webflow, tcg_linear, ecom_shopify, ecom_woocommerce, ecom_amazon, ecom_squarespace, hris_gusto, fs_googledrive, fs_dropbox, fs_sharepoint, fs_onedrive, crm_salesforce) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

INSERT INTO projects (id_project, name, sync_mode, id_user, id_connector_set) VALUES
('1e468c15-aa57-4448-aa2b-7fed640d1e3d', 'Project 1', 'pull', '0ce39030-2901-4c56-8db0-5e326182ec6b', '1709da40-17f7-4d3a-93a0-96dc5da6ddd7'),
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/@core/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export class CoreSyncService {
? lastSyncEvent.timestamp
: new Date(0);

const hoursSinceLastSync =
(now.getTime() - lastSyncTime.getTime()) / (1000 * 60 * 60);
if (interval && hoursSinceLastSync >= interval) {
const secondsSinceLastSync =
Number(now.getTime() - lastSyncTime.getTime()) / 1000;

if (interval && secondsSinceLastSync >= interval) {
await this.prisma.events.create({
data: {
id_project: project.id_project,
Expand Down
30 changes: 19 additions & 11 deletions packages/api/src/crm/contact/services/salesforce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { IContactService } from '@crm/contact/types';
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import {
SalesforceContactInput,
SalesforceContactOutput,
} from './types';
import { SalesforceContactInput, SalesforceContactOutput } from './types';

@Injectable()
export class SalesforceService implements IContactService {
Expand Down Expand Up @@ -77,18 +74,28 @@ export class SalesforceService implements IContactService {
});

const instanceUrl = connection.account_url;
let pagingString = `${pageSize ? `ORDER BY Id DESC LIMIT ${pageSize} ` : ''}${
cursor ? `OFFSET ${cursor}` : ''
}`;
let pagingString = '';
if (pageSize) {
pagingString += `LIMIT ${pageSize} `;
}
if (cursor) {
pagingString += `OFFSET ${cursor}`;
}
if (!pageSize && !cursor) {
pagingString = 'LIMIT 200';
}

const fields = custom_properties ? custom_properties.join(',') : 'Id,FirstName,LastName,Email,Phone';
const query = `SELECT ${fields} FROM Contact ${pagingString}`;
const fields =
custom_properties?.length > 0
? custom_properties.join(',')
: 'Id,FirstName,LastName,Email,Phone';

const query = `SELECT ${fields} FROM Contact ${pagingString}`.trim();

const resp = await axios.get(
`${instanceUrl}/services/data/v56.0/query/?q=${encodeURIComponent(query)}`,
`${instanceUrl}/services/data/v56.0/query/?q=${encodeURIComponent(
query,
)}`,
{
headers: {
Authorization: `Bearer ${this.cryptoService.decrypt(
Expand All @@ -106,7 +113,8 @@ export class SalesforceService implements IContactService {
statusCode: 200,
};
} catch (error) {
this.logger.log(`Error syncing Salesforce contacts: ${error.message}`);
throw error;
}
}
}
}
26 changes: 17 additions & 9 deletions packages/api/src/crm/note/services/salesforce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,28 @@ export class SalesforceService implements INoteService {
});

const instanceUrl = connection.account_url;
let pagingString = `${pageSize ? `ORDER BY Id DESC LIMIT ${pageSize} ` : ''}${
cursor ? `OFFSET ${cursor}` : ''
}`;
let pagingString = '';
if (pageSize) {
pagingString += `LIMIT ${pageSize} `;
}
if (cursor) {
pagingString += `OFFSET ${cursor}`;
}
if (!pageSize && !cursor) {
pagingString = 'LIMIT 200';
}

const commonPropertyNames = Object.keys(commonNoteSalesforceProperties);
const allProperties = [...commonPropertyNames, ...custom_properties];
const fields = allProperties.join(',');
const fields =
custom_properties?.length > 0
? custom_properties.join(',')
: 'Id,Title,Body,OwnerId,ParentId,CreatedDate,LastModifiedDate';

const query = `SELECT ${fields} FROM Note ${pagingString}`;
const query = `SELECT ${fields} FROM Note ${pagingString}`.trim();

const resp = await axios.get(
`${instanceUrl}/services/data/v56.0/query/?q=${encodeURIComponent(query)}`,
`${instanceUrl}/services/data/v56.0/query/?q=${encodeURIComponent(
query,
)}`,
{
headers: {
Authorization: `Bearer ${this.cryptoService.decrypt(
Expand All @@ -124,7 +131,8 @@ export class SalesforceService implements INoteService {
statusCode: 200,
};
} catch (error) {
this.logger.log(`Error syncing Salesforce notes: ${error.message}`);
throw error;
}
}
}
}
2 changes: 1 addition & 1 deletion packages/shared/src/connectors/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const CONNECTORS_METADATA: ProvidersConfig = {
},
logoPath: 'https://logos-world.net/wp-content/uploads/2020/10/Salesforce-Logo.png',
description: 'Sync & Create contacts, deals, companies, notes, engagements, stages, tasks and users',
active: false,
active: true,
authStrategy: {
strategy: AuthStrategy.oauth2,
properties: ['domain']
Expand Down

0 comments on commit c387394

Please sign in to comment.