opportunities.js•3.68 kB
export const opportunityTools = [
{
name: "list_opportunities",
description: "List opportunities with optional filtering and pagination",
inputSchema: {
type: "object",
properties: {
filter: { type: "string", description: "Filter query (JSON string)" },
orderBy: { type: "string", description: "Order by field" },
limit: { type: "number", description: "Number of results (max 100)" },
depth: { type: "number", description: "Query depth for relations" },
startingAfter: { type: "string", description: "Cursor for pagination" },
endingBefore: { type: "string", description: "Cursor for pagination" }
}
}
},
{
name: "create_opportunity",
description: "Create a new opportunity in Twenty CRM",
inputSchema: {
type: "object",
properties: {
name: { type: "string", description: "Opportunity name" },
amount: {
type: "object",
properties: {
amountMicros: { type: "number" },
currencyCode: { type: "string" }
},
description: "Opportunity amount"
},
closeDate: { type: "string", format: "date-time", description: "Close date" },
stage: { type: "string", description: "Opportunity stage" },
companyId: { type: "string", format: "uuid", description: "Company ID" },
pointOfContactId: { type: "string", format: "uuid", description: "Point of contact person ID" },
position: { type: "number", description: "Position" }
},
required: ["name"]
}
},
{
name: "get_opportunity",
description: "Get details of a specific opportunity by ID",
inputSchema: {
type: "object",
properties: {
id: { type: "string", format: "uuid", description: "Opportunity ID" },
depth: { type: "number", description: "Query depth for relations" }
},
required: ["id"]
}
},
{
name: "update_opportunity",
description: "Update an existing opportunity's information",
inputSchema: {
type: "object",
properties: {
id: { type: "string", format: "uuid", description: "Opportunity ID" },
name: { type: "string" },
amount: { type: "object" },
closeDate: { type: "string", format: "date-time" },
stage: { type: "string" },
companyId: { type: "string", format: "uuid" },
pointOfContactId: { type: "string", format: "uuid" },
position: { type: "number" }
},
required: ["id"]
}
},
{
name: "delete_opportunity",
description: "Delete an opportunity from Twenty CRM",
inputSchema: {
type: "object",
properties: {
id: { type: "string", format: "uuid", description: "Opportunity ID" }
},
required: ["id"]
}
}
];
export async function executeOpportunityTool(toolName, params, apiClient) {
switch (toolName) {
case "list_opportunities":
return await apiClient.makeRequest("/opportunities", "GET", null, params);
case "create_opportunity":
return await apiClient.makeRequest("/opportunities", "POST", params);
case "get_opportunity":
return await apiClient.makeRequest(`/opportunities/${params.id}`, "GET", null, { depth: params.depth });
case "update_opportunity":
const { id: opportunityId, ...opportunityData } = params;
return await apiClient.makeRequest(`/opportunities/${opportunityId}`, "PUT", opportunityData);
case "delete_opportunity":
return await apiClient.makeRequest(`/opportunities/${params.id}`, "DELETE");
default:
throw new Error(`Unknown opportunity tool: ${toolName}`);
}
}