Sales copilot custom actions are added

This commit is contained in:
Harshita Vinnakota 2023-10-16 14:04:35 -07:00
Родитель 7e30fd939f
Коммит 90c06017e4
2 изменённых файлов: 560 добавлений и 1 удалений

Просмотреть файл

@ -3,6 +3,7 @@
"info": {
"version": "1.0",
"title": "DocuSign Demo",
"x-ms-keywords": "DocuSign Demo",
"description": "DocuSign helps organizations connect and automate how they prepare, sign, act on, and manage agreements. The DocuSign Demo connector connects only to DocuSign Demo environments but offers the same functionality as the regular DocuSign connector. Any documents in a DocuSign Demo environment are not legally binding. For all non-demo uses, use the regular DocuSign connector.",
"x-ms-deployment-version": "1.0.0",
"x-ms-api-annotation": {
@ -948,6 +949,221 @@
"x-ms-visibility": "important"
}
},
"/accounts/salesCopilotAccount/envelopes/getRelatedActivities": {
"get": {
"tags": [
"DocuSign"
],
"summary": "Sales Copilot: Get Related Activities",
"description": "Sales Copilot: Get Related Activities.",
"operationId": "scp-get-related-activities",
"x-ms-no-generic-test": true,
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "recordType",
"in": "query",
"required": true,
"enum": [
"account",
"opportunity",
"lead"
],
"type": "string"
},
{
"name": "recordId",
"in": "query",
"required": true,
"type": "string"
},
{
"name": "startDateTime",
"description": "Enter start date-time in the format: 2017-05-02T01:44Z",
"in": "query",
"type": "string",
"required": false,
"format": "date-time"
},
{
"name": "endDateTime",
"description": "Enter end date-time in the format: 2017-05-02T01:44Z",
"in": "query",
"type": "string",
"format": "date-time"
},
{
"name": "top",
"description": "Top envelopes to be returned",
"in": "query",
"type": "integer",
"format": "int32"
},
{
"name": "skip",
"description": "Envelopes to be skipped",
"in": "query",
"type": "integer",
"format": "int32"
},
{
"name": "crmType",
"in": "query",
"enum": [
"Dynamics365"
],
"type": "string"
},
{
"name": "crmOrgUrl",
"in": "query",
"type": "string"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/ActivityListResponseEnvelope"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/ApiError"
}
},
"500": {
"description": "Server Error",
"schema": {
"$ref": "#/definitions/ApiError"
}
}
},
"x-ms-openai-data": {
"openai-enabled": true
}
}
},
"/accounts/salesCopilotAccount/envelopes/getRelatedRecords": {
"get": {
"tags": [
"DocuSign"
],
"summary": "Sales Copilot: Get Related Records",
"description": "Sales Copilot: Get Related Records.",
"operationId": "scp-get-related-records",
"x-ms-no-generic-test": true,
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "recordType",
"in": "query",
"required": true,
"enum": [
"account",
"opportunity",
"lead"
],
"type": "string"
},
{
"name": "recordId",
"in": "query",
"required": true,
"type": "string"
},
{
"name": "startDateTime",
"description": "Enter start date-time in the format: 2017-05-02T01:44Z",
"in": "query",
"type": "string",
"required": false,
"format": "date-time"
},
{
"name": "top",
"description": "Top envelopes to be returned",
"in": "query",
"type": "integer",
"format": "int32"
},
{
"name": "skip",
"description": "Envelopes to be skipped",
"in": "query",
"type": "integer",
"format": "int32"
},
{
"name": "crmType",
"in": "query",
"enum": [
"Dynamics365"
],
"type": "string"
},
{
"name": "crmOrgUrl",
"in": "query",
"type": "string"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/DocumentRecordListResponseEnvelope"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/ApiError"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/ApiError"
}
},
"500": {
"description": "Server Error",
"schema": {
"$ref": "#/definitions/ApiError"
}
}
},
"x-ms-openai-data": {
"openai-enabled": true
}
}
},
"/accounts/{accountId}/envelopes/createFromTemplate": {
"post": {
"tags": [
@ -2565,7 +2781,7 @@
"deprecated": false,
"x-ms-visibility": "important",
"x-ms-no-generic-test": true
},
}
},
"/login_information": {
"get": {
@ -4570,6 +4786,86 @@
}
}
},
"Activity": {
"required": [
"dateTime",
"description",
"title"
],
"type": "object",
"properties": {
"title": {
"minLength": 1,
"type": "string"
},
"description": {
"minLength": 1,
"type": "string"
},
"dateTime": {
"type": "string",
"format": "date-time"
},
"url": {
"type": "string"
},
"additionalProperties": {
"type": "object",
"properties": {
"additionalProperties": {
"type": "string"
}
},
"x-ms-summary": "Additional Properties"
}
},
"additionalProperties": false
},
"DocumentRecord": {
"required": [
"recordId",
"recordTitle",
"recordTypeDisplayName",
"recordTypePluralDisplayName",
"recordType"
],
"type": "object",
"properties": {
"recordId": {
"minLength": 1,
"type": "string"
},
"recordTypeDisplayName": {
"minLength": 1,
"type": "string"
},
"recordTypePluralDisplayName": {
"minLength": 1,
"type": "string"
},
"recordType": {
"minLength": 1,
"type": "string"
},
"recordTitle": {
"minLength": 1,
"type": "string"
},
"url": {
"type": "string"
},
"additionalProperties": {
"type": "object",
"properties": {
"additionalProperties": {
"type": "string"
}
},
"x-ms-summary": "Additional Properties"
}
},
"additionalProperties": false
},
"Envelope": {
"type": "object",
"properties": {
@ -4639,6 +4935,63 @@
}
}
},
"ActivityListResponseEnvelope": {
"type": "object",
"properties": {
"value": {
"description": "Related activies",
"type": "array",
"items": {
"$ref": "#/definitions/Activity"
},
"x-ms-summary": "Related activities"
},
"hasMoreResults": {
"type": "boolean"
}
},
"additionalProperties": false
},
"DocumentRecordListResponseEnvelope": {
"type": "object",
"properties": {
"value": {
"description": "Related records",
"type": "array",
"items": {
"$ref": "#/definitions/DocumentRecord"
},
"x-ms-summary": "Related records"
},
"hasMoreResults": {
"type": "boolean"
}
},
"additionalProperties": false
},
"ApiError": {
"required": [
"errorCode"
],
"type": "object",
"properties": {
"errorCode": {
"minLength": 1,
"type": "string"
},
"errorMessage": {
"type": "string"
},
"activityId": {
"type": "string"
},
"details": {
"type": "object",
"additionalProperties": { }
}
},
"additionalProperties": false
},
"CreateEnvelopeResponse": {
"type": "object",
"properties": {

Просмотреть файл

@ -1359,6 +1359,48 @@ public class Script : ScriptBase
return body;
}
private string GetDescriptionNLPForRelatedActivities(JToken envelope)
{
string descriptionNLP = null;
int recipientCount = envelope["recipients"]["recipientCount"].ToObject<int>();
var recipientCountInNaturalLanguage = (recipientCount > 1) ?
(" and " + (recipientCount - 1).ToString() + " others have ") : " ";
JArray documentArray = (envelope["envelopeDocuments"] as JArray) ?? new JArray();
var documentCountInNaturalLanguage = (documentArray.Count > 1) ?
(" and " + (documentArray.Count - 1).ToString() + " other documents ") : " ";
if (envelope["status"].Equals("sent"))
{
descriptionNLP = envelope["sender"]["userName"] + " " +
envelope["status"] + " " +
envelope["envelopeDocuments"][0]["name"] +
documentCountInNaturalLanguage + " on " +
envelope["statusChangedDateTime"];
}
else
{
descriptionNLP = envelope["recipients"]["signers"][0]["name"] +
recipientCountInNaturalLanguage +
envelope["status"] + " " +
envelope["envelopeDocuments"][0]["name"] +
documentCountInNaturalLanguage + " on " +
envelope["statusChangedDateTime"];
}
return descriptionNLP;
}
private string GetEnvelopeUrl(JToken envelope)
{
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
var envelopeUrl = uriBuilder.Uri.ToString().Contains("demo") ?
"https://apps-d.docusign.com/send/documents/details/" + envelope["envelopeId"] :
"https://app.docusign.com/documents/details/" + envelope["envelopeId"];
return envelopeUrl;
}
private void AddCoreRecipientParams(JArray signers, JObject body)
{
var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
@ -1604,6 +1646,7 @@ public class Script : ScriptBase
{
var jsonContent = JObject.Parse(content);
var baseUri = jsonContent["accounts"]?[0]?["base_uri"]?.ToString();
var accountId = (string)jsonContent["accounts"].Where(a => (bool)a["is_default"]).FirstOrDefault()["account_id"];
if (!string.IsNullOrEmpty(baseUri))
{
this.Context.Request.RequestUri = new Uri(new Uri(baseUri), this.Context.Request.RequestUri.PathAndQuery);
@ -1612,6 +1655,15 @@ public class Script : ScriptBase
{
throw new ConnectorException(HttpStatusCode.BadGateway, "Unable to get User's API endpoint from the response: " + content);
}
if (!string.IsNullOrEmpty(accountId))
{
this.Context.Request.Headers.Add("AccountId", accountId);
}
else
{
throw new ConnectorException(HttpStatusCode.BadGateway, "Unable to get User's API endpoint from the response: " + content);
}
}
else
{
@ -1778,6 +1830,50 @@ public class Script : ScriptBase
this.Context.Request.Content = CreateJsonContent(newBody.ToString());
}
if("scp-get-related-activities".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
uriBuilder.Path = uriBuilder.Path.Replace("/getRelatedActivities", "");
uriBuilder.Path = uriBuilder.Path.Replace("salesCopilotAccount", this.Context.Request.Headers.GetValues("AccountId").FirstOrDefault());
this.Context.Request.Headers.Add("x-ms-client-request-id", Guid.NewGuid().ToString());
this.Context.Request.Headers.Add("x-ms-user-agent", "sales-copilot");
query["custom_field"] = "entityLogicalName=" + query.Get("recordType");
query["from_date"] = string.IsNullOrEmpty(query.Get("startDateTime")) ?
DateTime.UtcNow.AddDays(-7).ToString() :
query.Get("startDateTime");
if (!string.IsNullOrEmpty(query.Get("endDateTime")))
{
query["to_date"] = query.Get("endDateTime");
}
query["include"] = "custom_fields,recipients,documents";
uriBuilder.Query = query.ToString();
this.Context.Request.RequestUri = uriBuilder.Uri;
}
if("scp-get-related-records".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
uriBuilder.Path = uriBuilder.Path.Replace("/getRelatedRecords", "");
uriBuilder.Path = uriBuilder.Path.Replace("salesCopilotAccount", this.Context.Request.Headers.GetValues("AccountId").FirstOrDefault());
this.Context.Request.Headers.Add("x-ms-client-request-id", Guid.NewGuid().ToString());
this.Context.Request.Headers.Add("x-ms-user-agent", "sales-copilot");
query["custom_field"] = "entityLogicalName=" + query.Get("recordType");
query["from_date"] = string.IsNullOrEmpty(query.Get("startDateTime")) ?
DateTime.UtcNow.AddDays(-7).ToString() :
query.Get("startDateTime");
query["include"] = "custom_fields, recipients, documents";
uriBuilder.Query = query.ToString();
this.Context.Request.RequestUri = uriBuilder.Uri;
}
if ("GetRecipientFields".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
@ -2135,6 +2231,116 @@ public class Script : ScriptBase
response.Content = new StringContent(newBody.ToString(), Encoding.UTF8, "application/json");
}
if ("scp-get-related-activities".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
var body = ParseContentAsJObject(await response.Content.ReadAsStringAsync().ConfigureAwait(false), false);
var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
JObject newBody = new JObject();
JArray Activity = (body["envelopes"] as JArray) ?? new JArray();
JArray filteredActivities = new JArray();
int top = string.IsNullOrEmpty(query.Get("top")) ? 3: int.Parse(query.Get("top"));
int skip = string.IsNullOrEmpty(query.Get("skip")) ? 0: int.Parse(query.Get("skip"));
var crmOrgUrl = query.Get("crmOrgUrl") ?? null;
var recordId = query.Get("recordId") ?? null;
var crmType = "CRMToken";
string[] filters = { crmType, crmOrgUrl, recordId };
foreach (var filter in filters.Where(filter => filter != null))
{
foreach (var envelope in Activity)
{
if (envelope.ToString().Contains(filter))
{
JObject additionalPropertiesForActivity = new JObject()
{
["Recipient"] = envelope["recipients"]["signers"][0]["name"],
["Owner"] = envelope["sender"]["userName"],
["Status"] = envelope["status"],
["EnvelopeId"] = envelope["envelopeId"],
["Date"] = envelope["statusChangedDateTime"]
};
filteredActivities.Add(new JObject()
{
["title"] = envelope["emailSubject"],
["description"] = GetDescriptionNLPForRelatedActivities(envelope),
["dateTime"] = envelope["statusChangedDateTime"],
["url"] = GetEnvelopeUrl(envelope),
["additionalProperties"] = additionalPropertiesForActivity
});
}
}
if (filteredActivities.Count > 0)
{
Activity = new JArray(filteredActivities);
filteredActivities.Clear();
}
}
newBody["value"] = (Activity.Count < top) ? Activity : new JArray(Activity.Skip(skip).Take(top).ToArray());
newBody["hasMoreResults"] = (skip + top < Activity.Count) ? true : false;
response.Content = new StringContent(newBody.ToString(), Encoding.UTF8, "application/json");
}
if ("scp-get-related-records".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
var body = ParseContentAsJObject(await response.Content.ReadAsStringAsync().ConfigureAwait(false), false);
var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
JObject newBody = new JObject();
JArray DocumentRecord = (body["envelopes"] as JArray) ?? new JArray();
JArray filteredRecords = new JArray();
int top = string.IsNullOrEmpty(query.Get("top")) ? 3: int.Parse(query.Get("top"));
int skip = string.IsNullOrEmpty(query.Get("skip")) ? 0: int.Parse(query.Get("skip"));
var crmOrgUrl = query.Get("crmOrgUrl") ?? null;
var recordId = query.Get("recordId") ?? null;
var crmType = "CRMToken";
string[] filters = { crmType, recordId, crmOrgUrl};
foreach (var filter in filters.Where(filter => filter != null))
{
foreach (var envelope in DocumentRecord)
{
if (envelope.ToString().Contains(filter))
{
JObject additionalPropertiesForDocumentRecords = new JObject()
{
["Recipient"] = envelope["recipients"]["signers"][0]["name"],
["Owner"] = envelope["sender"]["userName"],
["EnvelopeId"] = envelope["envelopeId"],
["Date"] = envelope["statusChangedDateTime"]
};
filteredRecords.Add(new JObject()
{
["recordId"] = envelope["envelopeId"],
["recordTypeDisplayName"] = "Agreement",
["recordTypePluralDisplayName"] = "Agreements",
["recordType"] = "Agreement",
["recordTitle"] = envelope["emailSubject"],
["url"] = GetEnvelopeUrl(envelope),
["additionalProperties"] = additionalPropertiesForDocumentRecords
});
}
}
if (filteredRecords.Count > 0)
{
DocumentRecord = new JArray(filteredRecords);
filteredRecords.Clear();
}
}
newBody["value"] = (DocumentRecord.Count < top) ? DocumentRecord : new JArray(DocumentRecord.Skip(skip).Take(top).ToArray());
newBody["hasMoreResults"] = (skip + top < DocumentRecord.Count) ? true : false;
response.Content = new StringContent(newBody.ToString(), Encoding.UTF8, "application/json");
}
if ("GetRecipientFields".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
var body = ParseContentAsJObject(await response.Content.ReadAsStringAsync().ConfigureAwait(false), false);