通过 Dataverse Web API(Azure AD OAuth 2.0 认证)在 Microsoft Dynamics 365 中创建和更新 CRM 记录,包括机会、线索、联系人、账户和任务。
Activate this skill when the user mentions Microsoft Dynamics 365, D365, Dynamics CRM, or any of the following actions directed at a Dynamics 365 CRM:
VariableDescriptionDYNAMICS365_CLIENT_IDAzure AD Application (client) IDDYNAMICS365_CLIENT_SECRETAzure AD client secretDYNAMICS365_TENANT_IDAzure AD Tenant ID — use common for multi-tenantDYNAMICS365_INSTANCE_URLDynamics 365 instance URL, e.g. https://contoso.crm.dynamics.com
Determine from the user's message which entity to create or update:
User saysEntityAction"create deal", "new opportunity", "deal com X"Opportunityupsert"new lead", "criar lead", "prospect X"Leadupsert"add contact", "criar contacto", "cliente X no CRM"Contactupsert"new account", "empresa Y no CRM", "criar conta"Accountupsert"create task", "follow-up", "lembrete para X"Taskcreate
Opportunity fields:
name — deal / opportunity name (required)estimatedvalue — numeric value in local currencystepname — pipeline stage: "Qualify" / "Develop" / "Propose" / "Close"actualclosedate — expected close date (ISO: YYYY-MM-DD)Lead fields:
fullname — full name (required)emailaddress1 — email addresscompanyname — company nametelephone1 — phone numberjobtitle — job titleContact fields:
fullname — full name (required)emailaddress1 — email addresstelephone1 — phone numberjobtitle — job titleAccount fields:
name — company / account name (required)emailaddress1 — email addresstelephone1 — phone numberwebsiteurl — websiteTask fields:
subject — task title (required)description — details / notesscheduledend — due date-time (ISO 8601)prioritycode — 0 = Low, 1 = Normal, 2 = HighUse the Dynamics365Client from the openclaw-dynamics-365 npm package:
typescript
import { Dynamics365Client } from "openclaw-dynamics-365";
const client = new Dynamics365Client(
process.env.DYNAMICS365_INSTANCE_URL,
accessToken, // obtained via OAuth flow
);
// Opportunity
const result = await client.upsertOpportunity({ name: "Deal Contoso", estimatedvalue: 50000 });
// Lead
const result = await client.upsertLead({ fullname: "João Silva", companyname: "TechNova" });
// Contact
const result = await client.upsertContact({ fullname: "Maria Santos", emailaddress1: "maria@techno.com" });
// Account
const result = await client.upsertAccount({ name: "TechNova Ltda" });
// Task
const taskId = await client.createTask({ subject: "Follow-up call", prioritycode: 2 });
On success:
text
✅ [Entity] "[name]" [created/updated] in Dynamics 365.
🔗 [record URL]
On error:
text
❌ Could not [create/update] [entity] in Dynamics 365: [error message]
For initial authorization, use getAuthorizationUrl() to redirect the user to
Microsoft's consent screen, then exchangeCodeForTokens() in the callback:
typescript
import { getAuthorizationUrl, exchangeCodeForTokens } from "openclaw-dynamics-365";
// 1. Redirect user
const url = getAuthorizationUrl(config, redirectUri, state);
// 2. In callback
const tokens = await exchangeCodeForTokens(config, code, redirectUri);
// 3. Refresh when expired (~1h)
if (isTokenExpired(tokens)) {
tokens = await refreshAccessToken(config, tokens.refreshToken);
}
$filter, $select, $top"parentcustomerid_account@odata.bind": "/accounts({accountId})"refreshAccessToken()