Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 122 additions & 14 deletions certified-connectors/DocuSignDemo/apiDefinition.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"/accounts/{accountId}/connectV2": {
"post": {
"summary": "When an envelope status changes (Connect) (V2)",
"summary": "DEPRECATED: When an envelope status changes (Connect) (V2)",
"description": "Triggers a new flow when an envelope status changes.",
"operationId": "CreateHookEnvelopeV2",
"parameters": [
Expand Down Expand Up @@ -121,6 +121,57 @@
}
}
},
"/accounts/{accountId}/connectV3": {
"post": {
"summary": "When an envelope status changes (Connect) (V3)",
"description": "Triggers a new flow when an envelope status changes.",
"operationId": "CreateHookEnvelopeV3",
"parameters": [
{
"name": "accountId",
"in": "path",
"description": "Account id",
"required": true,
"x-ms-summary": "Account",
"x-ms-test-value": "insert account id",
"x-ms-dynamic-values": {
"operationId": "GetLoginAccounts",
"value-collection": "loginAccounts",
"value-path": "accountIdGuid",
"value-title": "name"
},
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/WebhookRequestV3"
}
}
],
"responses": {
"201": {
"description": "default",
"schema": {
"type": "object"
}
}
},
"deprecated": false,
"x-ms-trigger": "single",
"x-ms-trigger-hint": "To see it work now, send an envelope.",
"x-ms-visibility": "important",
"x-ms-no-generic-test": true
},
"x-ms-notification-content": {
"description": "Details for Webhook",
"schema": {
"$ref": "#/definitions/WebhookEnvelopeResponseV2"
}
}
},
"/accounts/{accountId}/connect/{connectId}": {
"delete": {
"summary": "Delete hook",
Expand Down Expand Up @@ -2291,19 +2342,7 @@
"Delivered",
"Completed",
"Declined",
"Voided",
"envelope-sent",
"envelope-delivered",
"envelope-completed",
"envelope-declined",
"envelope-voided",
"envelope-resent",
"envelope-corrected",
"envelope-purge",
"envelope-deleted",
"envelope-discard",
"click-agreed",
"click-declined"
"Voided"
],
"type": "string",
"x-ms-summary": "Envelope event",
Expand Down Expand Up @@ -2457,6 +2496,75 @@
}
}
},
"WebhookRequestV3": {
"required": [
"allUsers",
"allowEnvelopePublish",
"includeDocumentFields",
"requiresAcknowledgement",
"urlToPublishTo",
"name",
"envelopeEvents"
],
"type": "object",
"properties": {
"allUsers": {
"default": "true",
"type": "string",
"x-ms-summary": "allUsers",
"x-ms-visibility": "internal"
},
"allowEnvelopePublish": {
"default": "true",
"type": "string",
"x-ms-summary": "allowEnvelopePublish",
"x-ms-visibility": "internal"
},
"includeDocumentFields": {
"default": "true",
"type": "string",
"x-ms-summary": "includeDocumentFields",
"x-ms-visibility": "internal"
},
"requiresAcknowledgement": {
"default": "true",
"type": "string",
"x-ms-summary": "requiresAcknowledgement",
"x-ms-visibility": "internal"
},
"urlToPublishTo": {
"type": "string",
"x-ms-summary": "urlToPublishTo",
"x-ms-visibility": "internal",
"x-ms-notification-url": true
},
"name": {
"type": "string",
"x-ms-summary": "Connect name",
"x-ms-visibility": "important"
},
"envelopeEvents": {
"enum": [
"envelope-sent",
"envelope-delivered",
"envelope-completed",
"envelope-declined",
"envelope-voided",
"envelope-resent",
"envelope-corrected",
"envelope-purge",
"envelope-deleted",
"envelope-discard",
"click-agreed",
"click-declined"
],
"type": "string",
"x-ms-summary": "Envelope event",
"x-ms-visibility": "important"
}
}
},

"WebhookRequest": {
"type": "object",
"required": [
Expand Down
63 changes: 50 additions & 13 deletions certified-connectors/DocuSignDemo/script.csx
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,48 @@ public class Script : ScriptBase
var uriLogicAppsBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(uriLogicApps ?? string.Empty));
var notificationProxyUri = this.Context.CreateNotificationUri($"/webhook_response?logicAppsUri={uriLogicAppsBase64}");

// TODO: This map is added for backward compatibility. This will be removed once old events are deprecated
var envelopeEventMap = new Dictionary<string, string>() {
{"Sent", "envelope-sent"},
{"Delivered", "envelope-delivered"},
{"Completed", "envelope-completed"},
{"Declined", "envelope-declined"},
{"Voided", "envelope-voided"}
body["allUsers"] = "true";
body["allowEnvelopePublish"] = "true";
body["includeDocumentFields"] = "true";
body["requiresAcknowledgement"] = "true";
body["urlToPublishTo"] = notificationProxyUri.AbsoluteUri;
body["name"] = original["name"]?.ToString();

var envelopeEvent = original["envelopeEvents"]?.ToString();
var envelopeEventsArray = new JArray();
envelopeEventsArray.Add(envelopeEvent);
body["envelopeEvents"] = envelopeEventsArray;
body["configurationType"] = "custom";
body["deliveryMode"] = "sim";

string eventData = @"[
'tabs',
'custom_fields',
'recipients'
]";

JArray includeData = JArray.Parse(eventData);
body["eventData"] = new JObject
{
["version"] = "restv2.1",
["format"] = "json",
["includeData"] = includeData
};

var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
uriBuilder.Path = uriBuilder.Path.Replace("connectV2", "connect");
this.Context.Request.RequestUri = uriBuilder.Uri;

return body;
}

private JObject CreateHookEnvelopeV3BodyTransformation(JObject original)
{
var body = new JObject();

var uriLogicApps = original["urlToPublishTo"]?.ToString();
var uriLogicAppsBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(uriLogicApps ?? string.Empty));
var notificationProxyUri = this.Context.CreateNotificationUri($"/webhook_response?logicAppsUri={uriLogicAppsBase64}");

body["allUsers"] = "true";
body["allowEnvelopePublish"] = "true";
Expand All @@ -729,11 +763,9 @@ public class Script : ScriptBase
body["name"] = original["name"]?.ToString();

var envelopeEvent = original["envelopeEvents"]?.ToString();
var webhookEvent = envelopeEventMap.ContainsKey(envelopeEvent) ? envelopeEventMap[envelopeEvent] : envelopeEvent;

var webhookEventsArray = new JArray();
webhookEventsArray.Add(webhookEvent);
body["events"] = webhookEventsArray;
var envelopeEventsArray = new JArray();
envelopeEventsArray.Add(envelopeEvent);
body["events"] = envelopeEventsArray;
body["configurationType"] = "custom";
body["deliveryMode"] = "sim";

Expand All @@ -752,7 +784,7 @@ public class Script : ScriptBase
};

var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
uriBuilder.Path = uriBuilder.Path.Replace("connectV2", "connect");
uriBuilder.Path = uriBuilder.Path.Replace("connectV3", "connect");
this.Context.Request.RequestUri = uriBuilder.Uri;
return body;
}
Expand Down Expand Up @@ -1315,6 +1347,11 @@ public class Script : ScriptBase
{
await this.TransformRequestJsonBody(this.CreateHookEnvelopeV2BodyTransformation).ConfigureAwait(false);
}

if ("CreateHookEnvelopeV3".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
await this.TransformRequestJsonBody(this.CreateHookEnvelopeV3BodyTransformation).ConfigureAwait(false);
}

if ("CreateBlankEnvelope".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
{
Expand Down