Skip to content

Commit 42200e2

Browse files
committed
Description text, additional validations and webhook trigger.
1 parent 9c4ba66 commit 42200e2

File tree

6 files changed

+89
-18
lines changed

6 files changed

+89
-18
lines changed

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/dashboard.html

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
<div ng-controller="Umbraco.Cms.Integrations.Automation.Zapier.ZapConfigController as vm">
22
<umb-box>
3-
<umb-box-header title="Configuration"></umb-box-header>
4-
<umb-content>
5-
<div class="mt2 ml2">
6-
<input id="inWebHookUrl" type="text" ng-model="vm.webHookUrl" class="w-20 mb0" placeholder="WebHook URL" />
7-
<select id="selContentTypes" ng-model="vm.selectedContentType" class="mb0">
3+
<umb-box-header title="Content Properties"></umb-box-header>
4+
<umb-box-content>
5+
<div>
6+
<p>
7+
<a href="https://zapier.com/">Zapier</a> is an online platform that helps you automate workflows by connecting your apps and services you use.
8+
This allows you to automate tasks without having to build this integration yourself.
9+
When an event happens in one app, Zapier can tell another app to perform (or do) a particular action - no code necessary.
10+
</p>
11+
<p>
12+
Automation is simply setting something up to run automatically. Automation is all around you, even if you don't realize it.
13+
Take your smartphone, for example. You receive alerts whenever you receive a text message, a voice mail, or an email.
14+
</p>
15+
<p>
16+
The heart of any automation boils down to this simple command: <b>WHEN</b> <span>this happens</span> <b>THEN</b> <span>do that</span>.
17+
</p>
18+
<p>
19+
A Zap is an automated workflow that tells your apps to follow this simple command: "When this happens, do that."
20+
Every Zap has a trigger and one or more actions. A trigger is an event that starts a Zap, and an action is what your Zap does for you.
21+
</p>
22+
<p>
23+
When a Zap runs, each action it completes counts as one task.
24+
Zap triggers use webhooks to intercept the client's request and to execute the actions. Webhooks are automated messages sent from apps when something happens.
25+
Read Zapier Webhooks guide <a href="https://zapier.com/blog/what-are-webhooks/">here</a>.
26+
</p>
27+
<p>
28+
Using the filters below, you can map content items with Zap triggers Webhooks, and you will be able to: <br/>
29+
&nbsp; - Enable Zap trigger invoke when a specific content is published <br/>
30+
&nbsp; - Trigger a sample request using the Webhook URL and then reviewing the request data while creating the Zap trigger
31+
</p>
32+
</div>
33+
<div class="mt3">
34+
<input id="inWebHookUrl" type="text" ng-model="vm.webHookUrl" class="w-20 mb0" placeholder="WebHook URL" no-dirty-check />
35+
<select id="selContentTypes" ng-model="vm.selectedContentType" class="mb0" no-dirty-check>
836
<option value="">Please select a content type</option>
937
<option ng-repeat="item in vm.contentTypes" value="{{ item.name }}">{{ item.name }}</option>
1038
</select>
@@ -14,7 +42,15 @@
1442
label="Add">
1543
</umb-button>
1644
</div>
45+
</umb-box-content>
46+
</umb-box>
47+
<umb-box>
48+
<umb-box-header title="Results"></umb-box-header>
49+
<umb-content>
1750
<div class="mt2">
51+
52+
<umb-load-indicator ng-show="vm.loading"></umb-load-indicator>
53+
1854
<div class="umb-table" ng-if="vm.contentConfigs">
1955
<!-- Listviews head section -->
2056
<div class="umb-table-head">
@@ -47,6 +83,9 @@
4783
<span ng-bind="row.webHookUrl"></span>
4884
</div>
4985
<div class="mr7" style="position: relative;">
86+
<a href="javascript:void(0)" ng-click="vm.onTrigger(row.contentTypeName, row.webHookUrl)" title="trigger webHook">
87+
<i class="icon-play"></i>
88+
</a>
5089
<a href="javascript:void(0)" ng-click="row.showDeletePrompt = true">
5190
<i class="icon-trash"></i>
5291
</a>

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/js/zapier.controller.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var vm = this;
44

5+
vm.loading = false;
56
vm.contentTypes = [];
67
vm.contentConfigs = [];
78

@@ -19,7 +20,12 @@
1920
return;
2021
}
2122

22-
umbracoCmsIntegrationsAutomationZapierResource.addConfig(vm.webHookUrl, vm.selectedContentType).then(function (r) {
23+
umbracoCmsIntegrationsAutomationZapierResource.addConfig(vm.webHookUrl, vm.selectedContentType).then(function (response) {
24+
25+
if (response.length > 0) {
26+
notificationsService.warning("Zapier Content Config", response);
27+
return;
28+
}
2329

2430
getContentTypes();
2531

@@ -29,6 +35,21 @@
2935
});
3036
}
3137

38+
vm.onTrigger = function (contentTypeName, webHookUrl) {
39+
40+
vm.loading = true;
41+
42+
umbracoCmsIntegrationsAutomationZapierResource.triggerWebHook(webHookUrl, contentTypeName).then(function(response) {
43+
44+
vm.loading = false;
45+
46+
if (response.length > 0)
47+
notificationsService.warning("WebHook Trigger", response);
48+
else
49+
notificationsService.success("WebHook Trigger", "WebHook triggered successfully. Please check your Zap trigger for the newly submitted request.");
50+
});
51+
}
52+
3253
vm.onDelete = function(id) {
3354
umbracoCmsIntegrationsAutomationZapierResource.deleteConfig(id).then(function () {
3455
getContentTypes();

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/js/zapier.resource.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
return umbRequestHelper.resourcePromise(
1818
$http.get(`${apiEndpoint}/GetAll`), "Failed to get resource");
1919
},
20+
triggerWebHook: function(webHookUrl, contentTypeName) {
21+
return umbRequestHelper.resourcePromise(
22+
$http.post(`${apiEndpoint}/TriggerAsync`, { contentTypeName: contentTypeName, webHookUrl: webHookUrl }), "Failed to get resource");
23+
},
2024
deleteConfig: function(id) {
2125
return umbRequestHelper.resourcePromise(
2226
$http.delete(`${apiEndpoint}/Delete?id=${id}`), "Failed to get resource");

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/NewContentPublishedComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
4949
{
5050
foreach (var node in e.PublishedEntities)
5151
{
52-
var zapContentConfig = _zapConfigService.GetByAlias(node.ContentType.Alias);
52+
var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name);
5353
if (zapContentConfig == null) continue;
5454

5555
var content = new Dictionary<string, string>
5656
{
57-
{ Constants.Content.Name, node.ContentType.Name },
57+
{ Constants.Content.Name, node.Name },
5858
{ Constants.Content.PublishDate, DateTime.UtcNow.ToString() }
5959
};
6060

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/ZapConfigController.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
43
using System.Threading.Tasks;
54
using System.Web.Http;
@@ -45,19 +44,27 @@ public IEnumerable<ContentTypeDto> GetContentTypes()
4544
}
4645

4746
[HttpPost]
48-
public async Task<string> Add([FromBody] ContentConfigDto dto)
47+
public string Add([FromBody] ContentConfigDto dto)
4948
{
50-
var result = _zapConfigService.Add(dto);
51-
if (!string.IsNullOrEmpty(result)) return result;
49+
var getByNameResult = _zapConfigService.GetByName(dto.ContentTypeName);
50+
if (getByNameResult != null) return "A record for this content type already exists.";
5251

53-
return await _zapierService.TriggerAsync(dto.WebHookUrl,
54-
new Dictionary<string, string> { { Constants.Content.Name, dto.ContentTypeName } });
52+
var result = _zapConfigService.Add(dto);
53+
54+
return result;
5555
}
5656

5757
[HttpGet]
5858
public IEnumerable<ContentConfigDto> GetAll() => _zapConfigService.GetAll();
5959

6060
[HttpDelete]
6161
public string Delete(int id) => _zapConfigService.Delete(id);
62+
63+
[HttpPost]
64+
public async Task<string> TriggerAsync([FromBody] ContentConfigDto dto)
65+
{
66+
return await _zapierService.TriggerAsync(dto.WebHookUrl,
67+
new Dictionary<string, string> { { Constants.Content.Name, dto.ContentTypeName } });
68+
}
6269
}
6370
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Services/ZapConfigService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public string Delete(int id)
9292
}
9393
}
9494

95-
public ContentConfigDto GetByAlias(string contentAlias)
95+
public ContentConfigDto GetByName(string contentName)
9696
{
9797
using (var scope = _scopeProvider.CreateScope())
9898
{
9999
var entity =
100-
scope.Database.FirstOrDefault<ZapContentConfigTable.ZapContentConfig>("where ContentTypeAlias = @0",
101-
contentAlias);
100+
scope.Database.FirstOrDefault<ZapContentConfigTable.ZapContentConfig>("where ContentTypeName = @0",
101+
contentName);
102102

103103
return entity != null ? new ContentConfigDto(entity.WebHookUrl) : null;
104104
}

0 commit comments

Comments
 (0)