Remove dead code linked to quick actions (#6587)
Removing dead code, we'll take another approach to build this
This commit is contained in:
@ -1,55 +0,0 @@
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { CompanyInteface } from 'src/engine/core-modules/quick-actions/interfaces/company.interface';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
|
||||
|
||||
@Injectable()
|
||||
export class IntelligenceService {
|
||||
constructor(
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly httpService: HttpService,
|
||||
) {}
|
||||
|
||||
async enrichCompany(domainName: string): Promise<CompanyInteface> {
|
||||
const enrichedCompany = await this.httpService.axiosRef.get(
|
||||
`https://companies.twenty.com/${domainName}`,
|
||||
{
|
||||
validateStatus: function () {
|
||||
// This ensures the promise is always resolved, preventing axios from throwing an error
|
||||
return true;
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (enrichedCompany.status !== 200) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
linkedinLinkPrimaryLinkUrl:
|
||||
`https://linkedin.com/` + enrichedCompany.data.handle,
|
||||
};
|
||||
}
|
||||
|
||||
async completeWithAi(content: string) {
|
||||
return this.httpService.axiosRef.post(
|
||||
'https://openrouter.ai/api/v1/chat/completions',
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.environmentService.get(
|
||||
'OPENROUTER_API_KEY',
|
||||
)}`,
|
||||
'HTTP-Referer': `https://twenty.com`,
|
||||
'X-Title': `Twenty CRM`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: 'mistralai/mixtral-8x7b-instruct',
|
||||
messages: [{ role: 'user', content: content }],
|
||||
}),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
export interface CompanyInteface {
|
||||
linkedinLinkPrimaryLinkUrl?: string;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
|
||||
import { IntelligenceService } from 'src/engine/core-modules/quick-actions/intelligence.service';
|
||||
import { QuickActionsService } from 'src/engine/core-modules/quick-actions/quick-actions.service';
|
||||
import { WorkspaceQueryRunnerModule } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-runner.module';
|
||||
|
||||
@Module({
|
||||
imports: [WorkspaceQueryRunnerModule, HttpModule],
|
||||
controllers: [],
|
||||
providers: [QuickActionsService, IntelligenceService],
|
||||
exports: [QuickActionsService, IntelligenceService],
|
||||
})
|
||||
export class QuickActionsModule {}
|
||||
@ -1,181 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { Record as IRecord } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface';
|
||||
import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface';
|
||||
|
||||
import { stringifyWithoutKeyQuote } from 'src/engine/api/graphql/workspace-query-builder/utils/stringify-without-key-quote.util';
|
||||
import { WorkspaceQueryRunnerService } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-runner.service';
|
||||
import { IntelligenceService } from 'src/engine/core-modules/quick-actions/intelligence.service';
|
||||
import { getCompanyNameFromDomainName } from 'src/modules/contact-creation-manager/utils/get-company-name-from-domain-name.util';
|
||||
import { capitalize } from 'src/utils/capitalize';
|
||||
import { getCompanyDomainName } from 'src/utils/getCompanyDomainName';
|
||||
import { isWorkEmail } from 'src/utils/is-work-email';
|
||||
|
||||
@Injectable()
|
||||
export class QuickActionsService {
|
||||
constructor(
|
||||
private readonly workspaceQueryRunnunerService: WorkspaceQueryRunnerService,
|
||||
private readonly intelligenceService: IntelligenceService,
|
||||
) {}
|
||||
|
||||
async createCompanyFromPerson(
|
||||
id: string,
|
||||
workspaceId: string,
|
||||
objectMetadataItemCollection: ObjectMetadataInterface[],
|
||||
) {
|
||||
const personObjectMetadata = objectMetadataItemCollection.find(
|
||||
(item) => item.nameSingular === 'person',
|
||||
);
|
||||
|
||||
if (!personObjectMetadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
const personRequest =
|
||||
await this.workspaceQueryRunnunerService.executeAndParse<IRecord>(
|
||||
`query {
|
||||
personCollection(filter: {id: {eq: "${id}"}}) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
email
|
||||
companyId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
personObjectMetadata,
|
||||
'',
|
||||
workspaceId,
|
||||
);
|
||||
const person = personRequest.edges?.[0]?.node;
|
||||
|
||||
if (!person) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!person.companyId && person.email && isWorkEmail(person.email)) {
|
||||
const companyDomainName = person.email.split('@')?.[1].toLowerCase();
|
||||
const companyName = capitalize(companyDomainName.split('.')[0]);
|
||||
let relatedCompanyId = uuidv4();
|
||||
|
||||
const companyObjectMetadata = objectMetadataItemCollection.find(
|
||||
(item) => item.nameSingular === 'company',
|
||||
);
|
||||
|
||||
if (!companyObjectMetadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
const existingCompany =
|
||||
await this.workspaceQueryRunnunerService.executeAndParse<IRecord>(
|
||||
`query {companyCollection(filter: {domainName: {eq: "${companyDomainName}"}}) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
companyObjectMetadata,
|
||||
'',
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (existingCompany.edges?.length) {
|
||||
relatedCompanyId = existingCompany.edges[0].node.id;
|
||||
}
|
||||
|
||||
await this.workspaceQueryRunnunerService.execute(
|
||||
`mutation {
|
||||
insertIntocompanyCollection(objects: ${stringifyWithoutKeyQuote([
|
||||
{
|
||||
id: relatedCompanyId,
|
||||
name: companyName,
|
||||
domainName: companyDomainName,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
])}) {
|
||||
affectedCount
|
||||
records {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.workspaceQueryRunnunerService.execute(
|
||||
`mutation {
|
||||
updatepersonCollection(set: ${stringifyWithoutKeyQuote({
|
||||
companyId: relatedCompanyId,
|
||||
})}, filter: { id: { eq: "${person.id}" } }) {
|
||||
affectedCount
|
||||
records {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async executeQuickActionOnCompany(
|
||||
id: string,
|
||||
workspaceId: string,
|
||||
objectMetadataItem: ObjectMetadataInterface,
|
||||
) {
|
||||
const companyQuery = `query {
|
||||
companyCollection(filter: {id: {eq: "${id}"}}) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
domainName
|
||||
createdAt
|
||||
linkedinLinkPrimaryLinkUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const companyRequest =
|
||||
await this.workspaceQueryRunnunerService.executeAndParse<IRecord>(
|
||||
companyQuery,
|
||||
objectMetadataItem,
|
||||
'',
|
||||
workspaceId,
|
||||
);
|
||||
const company = companyRequest.edges?.[0]?.node;
|
||||
|
||||
if (!company) {
|
||||
return;
|
||||
}
|
||||
|
||||
const enrichedData = await this.intelligenceService.enrichCompany(
|
||||
getCompanyNameFromDomainName(getCompanyDomainName(company)),
|
||||
);
|
||||
|
||||
await this.workspaceQueryRunnunerService.execute(
|
||||
`mutation {
|
||||
updatecompanyCollection(set: ${stringifyWithoutKeyQuote(
|
||||
enrichedData,
|
||||
)}, filter: { id: { eq: "${id}" } }) {
|
||||
affectedCount
|
||||
records {
|
||||
id
|
||||
}
|
||||
}
|
||||
}`,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user