-
Notifications
You must be signed in to change notification settings - Fork 7
/
demo-flow.json
173 lines (173 loc) · 5.38 KB
/
demo-flow.json
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
[
{
"id": "186ee9b7.78e426",
"type": "tab",
"label": "Web Push Demo",
"disabled": false,
"info": ""
},
{
"id": "1d41b598.c12dba",
"type": "vapid-configuration",
"z": "",
"subject": "mailto:[email protected]",
"publicKey": "BM88mSlUg4mvjcPK5QrzRfQzow91F47iEazCnoTBQ8Hv_AVrJviLcnrNumTK319qWOt43sgOzBJs6UrdOW5IxHg",
"privateKey": "81iA43m6lKOtT0p8FYEh_WXfcNZW2X6Hs3S_FfBxKY4",
"gcmApiKey": "",
"name": ""
},
{
"id": "c0a453e0.3b0b",
"type": "web-push",
"z": "186ee9b7.78e426",
"name": "",
"vapidConfiguration": "1d41b598.c12dba",
"x": 740,
"y": 280,
"wires": [["dacfb716.62dd98"]]
},
{
"id": "55f7d1e7.59fe4",
"type": "web-push-notification",
"z": "186ee9b7.78e426",
"name": "web push notification",
"title": "This is default notification",
"body": "It makes sense to have a call to action in the content",
"sound": "",
"payload": "",
"x": 420,
"y": 200,
"wires": [["9b93fae9.81c4d8"]]
},
{
"id": "772803c2.55b3cc",
"type": "inject",
"z": "186ee9b7.78e426",
"name": "Send predefined notification",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 160,
"y": 200,
"wires": [["55f7d1e7.59fe4"]]
},
{
"id": "dacfb716.62dd98",
"type": "debug",
"z": "186ee9b7.78e426",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"x": 750,
"y": 340,
"wires": []
},
{
"id": "1512b37d.10daed",
"type": "http in",
"z": "186ee9b7.78e426",
"name": "Demo Web Push Manager REST API",
"url": "webpush",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 180,
"y": 60,
"wires": [["c1013cfe.39645"]]
},
{
"id": "c1013cfe.39645",
"type": "function",
"z": "186ee9b7.78e426",
"name": "Demo Web Push Manager",
"func": "let pushSubscriptions = flow.get('pushSubscriptions')||[]\n \nlet action = msg.payload.action\nlet subscription = msg.payload.subscription\n \nlet result = ''\n\nlet foundSubscriptionItems = pushSubscriptions.filter( subscriptionItem => {\n return subscriptionItem.endpoint == subscription.endpoint\n})\n \nif (action === 'subscribe') {\n \n if (foundSubscriptionItems.length === 0) {\n pushSubscriptions.push(subscription)\n result = 'Subscription registered: ' + subscription.endpoint\n } else {\n result = 'Subscription was already registered: ' + subscription.endpoint\n }\n\n msg.statusCode = 200\n \n } else if (action === 'unsubscribe') {\n \n if(foundSubscriptionItems.length === 0) {\n result = 'Subscription was not found: ' + subscription.endpoint\n } else {\n pushSubscriptions = pushSubscriptions.filter(subscriptionItem => {\n return subscriptionItem.endpoint !== subscription.endpoint\n })\n result = 'Subscription unregistered: ' + subscription.endpoint\n }\n \n msg.statusCode = 200\n\n } else {\n \n result = 'Unsupported action'\n \n msg.statusCode = 400\n \n }\n \nmsg.payload = {\n result: result\n}\n\nnode.log(`Number of active subscriptions: ${pushSubscriptions.length}`)\n \nflow.set('pushSubscriptions', pushSubscriptions)\n \nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 480,
"y": 60,
"wires": [["af876fe8.30ed6", "f0b8d2a9.8a765"]]
},
{
"id": "af876fe8.30ed6",
"type": "http response",
"z": "186ee9b7.78e426",
"name": "API Response",
"statusCode": "",
"headers": {},
"x": 760,
"y": 60,
"wires": []
},
{
"id": "f0b8d2a9.8a765",
"type": "debug",
"z": "186ee9b7.78e426",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"x": 750,
"y": 120,
"wires": []
},
{
"id": "cdb680f9.fdbe5",
"type": "inject",
"z": "186ee9b7.78e426",
"name": "Send custom notifcation",
"topic": "",
"payload": "{\"notification\":{\"title\":\"This is custom notification\",\"body\":\"It makes sense to have a call to action in the content\"}}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 380,
"wires": [["71ee5e9.d465ea"]]
},
{
"id": "71ee5e9.d465ea",
"type": "change",
"z": "186ee9b7.78e426",
"name": "Set msg.notification",
"rules": [
{
"t": "set",
"p": "notification",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 420,
"y": 380,
"wires": [["9b93fae9.81c4d8"]]
},
{
"id": "9b93fae9.81c4d8",
"type": "function",
"z": "186ee9b7.78e426",
"name": "List subscriptions",
"func": "// Using Flow variable we set in Demo Web Push Manager API\nmsg.subscriptions = flow.get('pushSubscriptions')||[]\n\n/*\nor list your subscription objects manually:\nmsg.subscriptions = [{\n endpoint: \"https://fcm.googleapis.com/fcm/send/SOME_LONG_TOKEN\",\n keys:\n {\n p256dh: P256DH_KEY\",\n auth: \"AUTH_KEY\"\n }\n}]\n*/\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 530,
"y": 280,
"wires": [["c0a453e0.3b0b"]]
}
]