-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (54 loc) · 2.25 KB
/
Program.cs
File metadata and controls
67 lines (54 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Microsoft.AspNet.WebHooks;
using Microsoft.AspNet.WebHooks.Diagnostics;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace WebHooksSender
{
class Program
{
private static IWebHookManager _whManager;
private static IWebHookStore _whStore;
static void Main(string[] args)
{
_whStore = new MemoryWebHookStore();
_whManager = new WebHookManager(_whStore, new TraceLogger());
//Alloy site URL
string receiverUrl = "http://localhost:51481";
//Subscribe alloy site in Memory of server
var wh = SubscribeNewUser(receiverUrl);
// Send Notification to all subscribers
SendWebhookAsync("alloy-plan", "Alloy Plan").Wait();
//verify the webhook
var verify = _whManager.VerifyWebHookAsync(wh);
Console.ReadLine();
}
private static WebHook SubscribeNewUser(string host)
{
var webhook = new WebHook();
//Alloy site will require this key in web.config to make the link
string secretKey = "12345678901234567890123456789012";
string webHookUrl = "/api/webhooks/incoming/custom";
//action name, Client will register to.
webhook.Filters.Add("entryupdating");
//A test paramameter
webhook.Properties.Add("StaticParamA", 10);
webhook.Secret = secretKey;
webhook.WebHookUri = host + webHookUrl;
//refister alloy site as user 1 in memory
_whStore.InsertWebHookAsync("user1", webhook);
return webhook;
}
/// <summary>
/// Send Notification to register clients
/// </summary>
/// <param name="product">product code</param>
/// <param name="productName"> New Product Name</param>
/// <returns></returns>
private static async Task SendWebhookAsync(string product, string productName)
{
var notifications = new List<NotificationDictionary> { new NotificationDictionary("entryupdating", new { id = product, name = productName }) };
var x = await _whManager.NotifyAsync("user1", notifications);
}
}
}