Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PushRuleDefinition.cs
2using System.Text;
3using EDaler;
5using NeuroFeatures;
11using Waher.Content;
12
14{
18 public sealed class PushRuleDefinition
19 {
23 public PushRuleDefinition(MessageType messageType, string localName, string @namespace, string channel, string messageVariable, string patternScript, string contentScript)
24 {
25 this.MessageType = messageType;
26 this.LocalName = localName;
27 this.Namespace = @namespace;
28 this.Channel = channel;
29 this.MessageVariable = messageVariable;
30 this.PatternScript = patternScript;
31 this.ContentScript = contentScript;
32 }
33
37 public MessageType MessageType { get; }
38
42 public string LocalName { get; }
43
47 public string Namespace { get; }
48
52 public string Channel { get; }
53
57 public string MessageVariable { get; }
58
62 public string PatternScript { get; }
63
67 public string ContentScript { get; }
68 }
69
73 public static class PushRuleDefinitions
74 {
78 public static IReadOnlyList<PushRuleDefinition> All { get; } = Build();
79
83 public static string RuleSetHash { get; } = ComputeHash(All);
84
85 private static IReadOnlyList<PushRuleDefinition> Build()
86 {
87 List<PushRuleDefinition> Definitions = new();
88
89 string NotificationChatTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationChatTitle)]);
90 string NotificationChatBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationChatBody)]);
91 string NotificationPetitionIdentityTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPetitionIdentityTitle)]);
92 string NotificationPetitionIdentityBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPetitionIdentityBody)]);
93 string NotificationPetitionContractTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPetitionContractTitle)]);
94 string NotificationPetitionContractBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPetitionContractBody)]);
95 string NotificationPetitionSignatureTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPetitionSignatureTitle)]);
96 string NotificationPetitionSignatureBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPetitionSignatureBody)]);
97 string NotificationIdentityApprovedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityApprovedTitle)]);
98 string NotificationIdentityApprovedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityApprovedBody)]);
99 string NotificationIdentityObsoletedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityObsoletedTitle)]);
100 string NotificationIdentityObsoletedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityObsoletedBody)]);
101 string NotificationIdentityRejectedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityRejectedTitle)]);
102 string NotificationIdentityRejectedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityRejectedBody)]);
103 string NotificationIdentityCompromisedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityCompromisedTitle)]);
104 string NotificationIdentityCompromisedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationIdentityCompromisedBody)]);
105 string NotificationContractCreatedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractCreatedTitle)]);
106 string NotificationContractCreatedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractCreatedBody)]);
107 string NotificationContractSignedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractSignedTitle)]);
108 string NotificationContractSignedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractSignedBody)]);
109 string NotificationContractUpdatedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractUpdatedTitle)]);
110 string NotificationContractUpdatedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractUpdatedBody)]);
111 string NotificationContractDeletedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractDeletedTitle)]);
112 string NotificationContractDeletedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractDeletedBody)]);
113 string NotificationContractProposalTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractProposalTitle)]);
114 string NotificationContractProposalBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationContractProposalBody)]);
115 string NotificationBalanceUpdatedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationBalanceUpdatedTitle)]);
116 string NotificationBalanceUpdatedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationBalanceUpdatedBody)]);
117 string NotificationTokenAddedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationTokenAddedTitle)]);
118 string NotificationTokenAddedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationTokenAddedBody)]);
119 string NotificationTokenRemovedTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationTokenRemovedTitle)]);
120 string NotificationTokenRemovedBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationTokenRemovedBody)]);
121 string NotificationPresenceAccessTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPresenceAccessTitle)]);
122 string NotificationPresenceAccessBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationPresenceAccessBody)]);
123 string NotificationReadAccessTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationReadAccessTitle)]);
124 string NotificationReadAccessBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationReadAccessBody)]);
125 string NotificationControlAccessTitle = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationControlAccessTitle)]);
126 string NotificationControlAccessBody = JSON.Encode(ServiceRef.Localizer[nameof(AppResources.NotificationControlAccessBody)]);
127
128 Definitions.Add(new PushRuleDefinition(
129 MessageType.Chat,
130 string.Empty,
131 string.Empty,
133 "Stanza",
134 string.Empty,
135 Script(
136 "FromJid:=GetAttribute(Stanza,'from');",
137 "ToJid:=GetAttribute(Stanza,'to');",
138 "FriendlyName:=RosterName(ToJid,FromJid);",
139 "Content:=GetElement(Stanza,'content');",
140 $"TitleText:='{NotificationChatTitle}';",
141 $"BodyText:='{NotificationChatBody}';",
142 "{",
143 "'payloadKind': 'PushNotificationPayload',",
144 "'payloadVersion': 1,",
145 "'visual': { 'title': Replace(TitleText,'{0}',FriendlyName), 'body': BodyText },",
146 $"'action': {{ 'type': '{NotificationAction.OpenChat}', 'entityId': FromJid, 'correlationId': FromJid }},",
147 $"'channel': {{ 'channelId': '{Constants.PushChannels.Messages}' }},",
148 "'delivery': { 'priority': 'High', 'silent': false },",
149 "'context': { 'fromJid': FromJid, 'toJid': ToJid, 'rosterName': FriendlyName },",
150 "'data': { 'isObject': exists(Content) and !empty(Markdown:= InnerText(Content)) and (Left(Markdown,2)='![' or (Left(Markdown,3)='```' and Right(Markdown,3)='```')) }",
151 "}")));
152
153 Definitions.Add(new PushRuleDefinition(
154 MessageType.Normal,
155 "petitionIdentityMsg",
158 "Stanza",
159 string.Empty,
160 Script(
161 "E:=GetElement(Stanza,'petitionIdentityMsg');",
162 "ToJid:=GetAttribute(Stanza,'to');",
163 "FromJid:=GetAttribute(E,'from');",
164 "FriendlyName:=RosterName(ToJid,FromJid);",
165 $"TitleText:='{NotificationPetitionIdentityTitle}';",
166 $"BodyText:='{NotificationPetitionIdentityBody}';",
167 "{",
168 "'payloadKind': 'PushNotificationPayload',",
169 "'payloadVersion': 1,",
170 "'visual': { 'title': Replace(TitleText,'{0}',FriendlyName), 'body': BodyText },",
171 $"'action': {{ 'type': '{NotificationAction.OpenProfile}', 'entityId': FromJid, 'correlationId': GetAttribute(E,'petitionId') }},",
172 $"'channel': {{ 'channelId': '{Constants.PushChannels.Petitions}' }},",
173 "'delivery': { 'priority': 'High' },",
174 "'context': { 'fromJid': FromJid, 'toJid': ToJid, 'rosterName': FriendlyName },",
175 "'data': { 'petitionId': GetAttribute(E,'petitionId') }",
176 "}")));
177
178 Definitions.Add(new PushRuleDefinition(
179 MessageType.Normal,
180 "petitionContractMsg",
183 "Stanza",
184 string.Empty,
185 Script(
186 "E:=GetElement(Stanza,'petitionContractMsg');",
187 "ToJid:=GetAttribute(Stanza,'to');",
188 "FromJid:=GetAttribute(E,'from');",
189 "FriendlyName:=RosterName(ToJid,FromJid);",
190 $"TitleText:='{NotificationPetitionContractTitle}';",
191 $"BodyText:='{NotificationPetitionContractBody}';",
192 "{",
193 "'payloadKind': 'PushNotificationPayload',",
194 "'payloadVersion': 1,",
195 "'visual': { 'title': Replace(TitleText,'{0}',FriendlyName), 'body': BodyText },",
196 $"'action': {{ 'type': '{NotificationAction.OpenProfile}', 'entityId': FromJid, 'correlationId': GetAttribute(E,'petitionId') }},",
197 $"'channel': {{ 'channelId': '{Constants.PushChannels.Petitions}' }},",
198 "'delivery': { 'priority': 'High' },",
199 "'context': { 'fromJid': FromJid, 'toJid': ToJid, 'rosterName': FriendlyName },",
200 "'data': { 'petitionId': GetAttribute(E,'petitionId') }",
201 "}")));
202
203 Definitions.Add(new PushRuleDefinition(
204 MessageType.Normal,
205 "petitionSignatureMsg",
208 "Stanza",
209 string.Empty,
210 Script(
211 "E:=GetElement(Stanza,'petitionSignatureMsg');",
212 "ToJid:=GetAttribute(Stanza,'to');",
213 "FromJid:=GetAttribute(E,'from');",
214 "FriendlyName:=RosterName(ToJid,FromJid);",
215 $"TitleText:='{NotificationPetitionSignatureTitle}';",
216 $"BodyText:='{NotificationPetitionSignatureBody}';",
217 "{",
218 "'payloadKind': 'PushNotificationPayload',",
219 "'payloadVersion': 1,",
220 "'visual': { 'title': Replace(TitleText,'{0}',FriendlyName), 'body': BodyText },",
221 $"'action': {{ 'type': '{NotificationAction.OpenProfile}', 'entityId': FromJid, 'correlationId': GetAttribute(E,'petitionId') }},",
222 $"'channel': {{ 'channelId': '{Constants.PushChannels.Petitions}' }},",
223 "'delivery': { 'priority': 'High' },",
224 "'context': { 'fromJid': FromJid, 'toJid': ToJid, 'rosterName': FriendlyName },",
225 "'data': { 'petitionId': GetAttribute(E,'petitionId') }",
226 "}")));
227
228 Definitions.Add(new PushRuleDefinition(
229 MessageType.Normal,
230 "identity",
233 "Stanza",
234 string.Empty,
235 Script(
236 "E:=GetElement(Stanza,'identity');",
237 "Status:=GetElement(E,'status');",
238 "State:=GetAttribute(Status,'state');",
239 "if (State='Approved') then",
240 "{",
241 "'payloadKind': 'PushNotificationPayload',",
242 "'payloadVersion': 1,",
243 $"'visual': {{ 'title': '{NotificationIdentityApprovedTitle}', 'body': '{NotificationIdentityApprovedBody}' }},",
244 $"'action': {{ 'type': '{NotificationAction.OpenIdentity}', navigationTarget: '{NotificationAction.OpenIdentity}', 'entityId': GetAttribute(E,'id'), 'correlationId': GetAttribute(E,'id') }},",
245 $"'channel': {{ 'channelId': '{Constants.PushChannels.Identities}' }},",
246 "'delivery': { 'priority': 'High' },",
247 "'context': { 'provider': GetAttribute(Status,'provider') },",
248 "'data': { 'legalId': GetAttribute(E,'id'), 'state': State, 'validFrom': GetAttribute(Status,'from'), 'validTo': GetAttribute(Status,'to') }",
249 "}",
250 "else if (State='Obsoleted') then",
251 "{",
252 "'payloadKind': 'PushNotificationPayload',",
253 "'payloadVersion': 1,",
254 $"'visual': {{ 'title': '{NotificationIdentityObsoletedTitle}', 'body': '{NotificationIdentityObsoletedBody}' }},",
255 $"'action': {{ 'type': '{NotificationAction.OpenIdentity}', navigationTarget: '{NotificationAction.OpenIdentity}', 'entityId': GetAttribute(E,'id'), 'correlationId': GetAttribute(E,'id') }},",
256 $"'channel': {{ 'channelId': '{Constants.PushChannels.Identities}' }},",
257 "'delivery': { 'priority': 'High' },",
258 "'context': { 'provider': GetAttribute(Status,'provider') },",
259 "'data': { 'legalId': GetAttribute(E,'id'), 'state': State, 'validFrom': GetAttribute(Status,'from'), 'validTo': GetAttribute(Status,'to') }",
260 "}",
261 "else if (State='Rejected') then",
262 "{",
263 "'payloadKind': 'PushNotificationPayload',",
264 "'payloadVersion': 1,",
265 $"'visual': {{ 'title': '{NotificationIdentityRejectedTitle}', 'body': '{NotificationIdentityRejectedBody}' }},",
266 $"'action': {{ 'type': '{NotificationAction.OpenIdentity}', navigationTarget: '{NotificationAction.OpenIdentity}', 'entityId': GetAttribute(E,'id'), 'correlationId': GetAttribute(E,'id') }},",
267 $"'channel': {{ 'channelId': '{Constants.PushChannels.Identities}' }},",
268 "'delivery': { 'priority': 'High' },",
269 "'context': { 'provider': GetAttribute(Status,'provider') },",
270 "'data': { 'legalId': GetAttribute(E,'id'), 'state': State, 'validFrom': GetAttribute(Status,'from'), 'validTo': GetAttribute(Status,'to') }",
271 "}",
272 "else if (State='Compromised') then",
273 "{",
274 "'payloadKind': 'PushNotificationPayload',",
275 "'payloadVersion': 1,",
276 $"'visual': {{ 'title': '{NotificationIdentityCompromisedTitle}', 'body': '{NotificationIdentityCompromisedBody}' }},",
277 $"'action': {{ 'type': '{NotificationAction.OpenIdentity}', navigationTarget: '{NotificationAction.OpenIdentity}', 'entityId': GetAttribute(E,'id'), 'correlationId': GetAttribute(E,'id') }},",
278 $"'channel': {{ 'channelId': '{Constants.PushChannels.Identities}' }},",
279 "'delivery': { 'priority': 'High' },",
280 "'context': { 'provider': GetAttribute(Status,'provider') },",
281 "'data': { 'legalId': GetAttribute(E,'id'), 'state': State, 'validFrom': GetAttribute(Status,'from'), 'validTo': GetAttribute(Status,'to') }",
282 "}",
283 "else",
284 "null")));
285
286 Definitions.Add(new PushRuleDefinition(
287 MessageType.Normal,
288 "contractCreated",
291 "Stanza",
292 string.Empty,
293 Script(
294 "E:=GetElement(Stanza,'contractCreated');",
295 "{",
296 "'payloadKind': 'PushNotificationPayload',",
297 "'payloadVersion': 1,",
298 $"'visual': {{ 'title': '{NotificationContractCreatedTitle}', 'body': '{NotificationContractCreatedBody}' }},",
299 $"'action': {{ 'type': '{NotificationAction.OpenContract}', 'entityId': GetAttribute(E,'contractId'), 'correlationId': GetAttribute(E,'contractId') }},",
300 $"'channel': {{ 'channelId': '{Constants.PushChannels.Contracts}' }},",
301 "'delivery': { 'priority': 'High' },",
302 "'data': { 'contractId': GetAttribute(E,'contractId') }",
303 "}")));
304
305 Definitions.Add(new PushRuleDefinition(
306 MessageType.Normal,
307 "contractSigned",
310 "Stanza",
311 string.Empty,
312 Script(
313 "E:=GetElement(Stanza,'contractSigned');",
314 "{",
315 "'payloadKind': 'PushNotificationPayload',",
316 "'payloadVersion': 1,",
317 $"'visual': {{ 'title': '{NotificationContractSignedTitle}', 'body': '{NotificationContractSignedBody}' }},",
318 $"'action': {{ 'type': '{NotificationAction.OpenContract}', 'entityId': GetAttribute(E,'contractId'), 'correlationId': GetAttribute(E,'contractId') }},",
319 $"'channel': {{ 'channelId': '{Constants.PushChannels.Contracts}' }},",
320 "'delivery': { 'priority': 'High' },",
321 "'data': { 'contractId': GetAttribute(E,'contractId'), 'legalId': GetAttribute(E,'legalId') }",
322 "}")));
323
324 Definitions.Add(new PushRuleDefinition(
325 MessageType.Normal,
326 "contractUpdated",
329 "Stanza",
330 string.Empty,
331 Script(
332 "E:=GetElement(Stanza,'contractUpdated');",
333 "{",
334 "'payloadKind': 'PushNotificationPayload',",
335 "'payloadVersion': 1,",
336 $"'visual': {{ 'title': '{NotificationContractUpdatedTitle}', 'body': '{NotificationContractUpdatedBody}' }},",
337 $"'action': {{ 'type': '{NotificationAction.OpenContract}', 'entityId': GetAttribute(E,'contractId'), 'correlationId': GetAttribute(E,'contractId') }},",
338 $"'channel': {{ 'channelId': '{Constants.PushChannels.Contracts}' }},",
339 "'delivery': { 'priority': 'High' },",
340 "'data': { 'contractId': GetAttribute(E,'contractId') }",
341 "}")));
342
343 Definitions.Add(new PushRuleDefinition(
344 MessageType.Normal,
345 "contractDeleted",
348 "Stanza",
349 string.Empty,
350 Script(
351 "E:=GetElement(Stanza,'contractDeleted');",
352 "{",
353 "'payloadKind': 'PushNotificationPayload',",
354 "'payloadVersion': 1,",
355 $"'visual': {{ 'title': '{NotificationContractDeletedTitle}', 'body': '{NotificationContractDeletedBody}' }},",
356 $"'action': {{ 'type': '{NotificationAction.OpenContract}', 'entityId': GetAttribute(E,'contractId'), 'correlationId': GetAttribute(E,'contractId') }},",
357 $"'channel': {{ 'channelId': '{Constants.PushChannels.Contracts}' }},",
358 "'delivery': { 'priority': 'High' },",
359 "'data': { 'contractId': GetAttribute(E,'contractId') }",
360 "}")));
361
362 Definitions.Add(new PushRuleDefinition(
363 MessageType.Normal,
364 "contractProposal",
367 "Stanza",
368 string.Empty,
369 Script(
370 "E:=GetElement(Stanza,'contractProposal');",
371 $"TitleText:='{NotificationContractProposalTitle}';",
372 $"BodyText:='{NotificationContractProposalBody}';",
373 "{",
374 "'payloadKind': 'PushNotificationPayload',",
375 "'payloadVersion': 1,",
376 "'visual': { 'title': TitleText, 'body': BodyText },",
377 $"'action': {{ 'type': '{NotificationAction.OpenContract}', 'entityId': GetAttribute(E,'contractId'), 'correlationId': GetAttribute(E,'contractId') }},",
378 $"'channel': {{ 'channelId': '{Constants.PushChannels.Contracts}' }},",
379 "'delivery': { 'priority': 'High' },",
380 "'data': { 'contractId': Num(GetAttribute(E,'contractId')), 'role': Num(GetAttribute(E,'role')) }",
381 "}")));
382
383 Definitions.Add(new PushRuleDefinition(
384 MessageType.Normal,
385 "balance",
388 "Stanza",
389 string.Empty,
390 Script(
391 "E:=GetElement(Stanza,'balance');",
392 $"TitleText:='{NotificationBalanceUpdatedTitle}';",
393 $"BodyText:='{NotificationBalanceUpdatedBody}';",
394 "{",
395 "'payloadKind': 'PushNotificationPayload',",
396 "'payloadVersion': 1,",
397 "'visual': { 'title': TitleText, 'body': BodyText },",
398 $"'action': {{ 'type': '{NotificationAction.OpenBalance}', 'entityId': GetAttribute(E,'currency'), 'correlationId': GetAttribute(E,'currency') }},",
399 $"'channel': {{ 'channelId': '{Constants.PushChannels.EDaler}' }},",
400 "'delivery': { 'priority': 'High' },",
401 "'data': { 'amount': Num(GetAttribute(E,'amount')), 'currency': GetAttribute(E,'currency'), 'timestamp': DateTime(GetAttribute(E,'timestamp')) }",
402 "}")));
403
404 Definitions.Add(new PushRuleDefinition(
405 MessageType.Normal,
406 "tokenAdded",
409 "Stanza",
410 string.Empty,
411 Script(
412 "E:=GetElement(Stanza,'tokenAdded');",
413 "E2:=GetElement(E,'token');",
414 $"TitleText:='{NotificationTokenAddedTitle}';",
415 $"BodyText:='{NotificationTokenAddedBody}';",
416 "{",
417 "'payloadKind': 'PushNotificationPayload',",
418 "'payloadVersion': 1,",
419 "'visual': { 'title': TitleText, 'body': BodyText },",
420 $"'action': {{ 'type': '{NotificationAction.OpenToken}', 'entityId': GetAttribute(E2,'tokenId'), 'correlationId': GetAttribute(E2,'tokenId') }},",
421 $"'channel': {{ 'channelId': '{Constants.PushChannels.Tokens}' }},",
422 "'delivery': { 'priority': 'High' },",
423 "'data': { 'tokenId': GetAttribute(E2,'tokenId'), 'value': Num(GetAttribute(E2,'value')), 'currency': GetAttribute(E2,'currency') }",
424 "}")));
425
426 Definitions.Add(new PushRuleDefinition(
427 MessageType.Normal,
428 "tokenRemoved",
431 "Stanza",
432 string.Empty,
433 Script(
434 "E:=GetElement(Stanza,'tokenRemoved');",
435 "E2:=GetElement(E,'token');",
436 $"TitleText:='{NotificationTokenRemovedTitle}';",
437 $"BodyText:='{NotificationTokenRemovedBody}';",
438 "{",
439 "'payloadKind': 'PushNotificationPayload',",
440 "'payloadVersion': 1,",
441 "'visual': { 'title': TitleText, 'body': BodyText },",
442 $"'action': {{ 'type': '{NotificationAction.OpenToken}', 'entityId': GetAttribute(E2,'tokenId'), 'correlationId': GetAttribute(E2,'tokenId') }},",
443 $"'channel': {{ 'channelId': '{Constants.PushChannels.Tokens}' }},",
444 "'delivery': { 'priority': 'High' },",
445 "'data': { 'tokenId': GetAttribute(E2,'tokenId'), 'value': Num(GetAttribute(E2,'value')), 'currency': GetAttribute(E2,'currency') }",
446 "}")));
447
448 Definitions.Add(new PushRuleDefinition(
449 MessageType.Normal,
450 "isFriend",
453 "Stanza",
454 string.Empty,
455 Script(
456 "ToJid:=GetAttribute(Stanza,'to');",
457 "E:=GetElement(Stanza,'isFriend');",
458 "RemoteJid:=GetAttribute(E,'remoteJid');",
459 "FriendlyName:=RosterName(ToJid,RemoteJid);",
460 $"TitleText:='{NotificationPresenceAccessTitle}';",
461 $"BodyText:='{NotificationPresenceAccessBody}';",
462 "{",
463 "'payloadKind': 'PushNotificationPayload',",
464 "'payloadVersion': 1,",
465 "'visual': { 'title': Replace(TitleText,'{0}',FriendlyName), 'body': BodyText },",
466 $"'action': {{ 'type': '{NotificationAction.OpenPresenceRequest}', 'entityId': RemoteJid }},",
467 $"'channel': {{ 'channelId': '{Constants.PushChannels.Provisioning}' }},",
468 "'delivery': { 'priority': 'High' },",
469 "'context': { 'toJid': ToJid, 'remoteJid': RemoteJid },",
470 "'data': { 'remoteJid': RemoteJid, 'jid': GetAttribute(E,'jid'), 'key': GetAttribute(E,'key'), 'q': 'isFriend' }",
471 "}")));
472
473 Definitions.Add(new PushRuleDefinition(
474 MessageType.Normal,
475 "canRead",
478 "Stanza",
479 string.Empty,
480 Script(
481 "ToJid:=GetAttribute(Stanza,'to');",
482 "E:=GetElement(Stanza,'canRead');",
483 "RemoteJid:=GetAttribute(E,'remoteJid');",
484 "FriendlyName:=RosterName(ToJid,RemoteJid);",
485 $"TitleText:='{NotificationReadAccessTitle}';",
486 $"BodyText:='{NotificationReadAccessBody}';",
487 "{",
488 "'payloadKind': 'PushNotificationPayload',",
489 "'payloadVersion': 1,",
490 "'visual': { 'title': Replace(TitleText,'{0}',FriendlyName), 'body': BodyText },",
491 $"'action': {{ 'type': '{NotificationAction.OpenPresenceRequest}', 'entityId': RemoteJid }},",
492 $"'channel': {{ 'channelId': '{Constants.PushChannels.Provisioning}' }},",
493 "'delivery': { 'priority': 'High' },",
494 "'context': { 'toJid': ToJid, 'remoteJid': RemoteJid },",
495 "'data': { 'remoteJid': RemoteJid, 'jid': GetAttribute(E,'jid'), 'key': GetAttribute(E,'key'), 'q': 'canRead' }",
496 "}")));
497
498 Definitions.Add(new PushRuleDefinition(
499 MessageType.Normal,
500 "canControl",
503 "Stanza",
504 string.Empty,
505 Script(
506 "ToJid:=GetAttribute(Stanza,'to');",
507 "E:=GetElement(Stanza,'canControl');",
508 "RemoteJid:=GetAttribute(E,'remoteJid');",
509 "FriendlyName:=RosterName(ToJid,RemoteJid);",
510 $"TitleText:='{NotificationControlAccessTitle}';",
511 $"BodyText:='{NotificationControlAccessBody}';",
512 "{",
513 "'payloadKind': 'PushNotificationPayload',",
514 "'payloadVersion': 1,",
515 "'visual': { 'title': Replace(TitleText,'{0}',FriendlyName), 'body': BodyText },",
516 $"'action': {{ 'type': '{NotificationAction.OpenPresenceRequest}', 'entityId': RemoteJid }},",
517 $"'channel': {{ 'channelId': '{Constants.PushChannels.Provisioning}' }},",
518 "'delivery': { 'priority': 'High' },",
519 "'context': { 'toJid': ToJid, 'remoteJid': RemoteJid },",
520 "'data': { 'remoteJid': RemoteJid, 'jid': GetAttribute(E,'jid'), 'key': GetAttribute(E,'key'), 'q': 'canControl' }",
521 "}")));
522
523 return Definitions;
524 }
525
526 private static string ComputeHash(IEnumerable<PushRuleDefinition> rules)
527 {
528 StringBuilder builder = new();
529
530 foreach (PushRuleDefinition rule in rules)
531 {
532 builder.Append(rule.MessageType.ToString());
533 builder.Append('|');
534 builder.Append(rule.LocalName);
535 builder.Append('|');
536 builder.Append(rule.Namespace);
537 builder.Append('|');
538 builder.Append(rule.Channel);
539 builder.Append('|');
540 builder.Append(rule.MessageVariable);
541 builder.Append('|');
542 builder.Append(rule.PatternScript);
543 builder.Append('|');
544 builder.Append(rule.ContentScript);
545 builder.AppendLine();
546 }
547
548 byte[] bytes = Encoding.UTF8.GetBytes(builder.ToString());
549 byte[] hash = SHA256.HashData(bytes);
550 return Convert.ToHexString(hash);
551 }
552
553 private static string Script(params string[] lines) => string.Join('\n', lines);
554 }
555}
eDaler XMPP client.
Definition: EDalerClient.cs:23
const string NamespaceEDaler
Namespace of eDaler component.
Definition: EDalerClient.cs:27
const string Provisioning
Provisioning channel
Definition: Constants.cs:769
const string Petitions
Petitions channel
Definition: Constants.cs:744
const string Identities
Identities channel
Definition: Constants.cs:749
const string Messages
Messages channel
Definition: Constants.cs:739
const string EDaler
eDaler channel
Definition: Constants.cs:759
const string Tokens
Tokens channel
Definition: Constants.cs:764
const string Contracts
Contracts channel
Definition: Constants.cs:754
A set of never changing property constants and helpful values.
Definition: Constants.cs:24
A strongly-typed resource class, for looking up localized strings, etc.
static string NotificationPetitionContractTitle
Looks up a localized string similar to Contract request from {0}.
static string NotificationIdentityRejectedBody
Looks up a localized string similar to Your identity was rejected..
static string NotificationPetitionSignatureBody
Looks up a localized string similar to A new signature request is waiting..
static string NotificationReadAccessBody
Looks up a localized string similar to Requested read access..
static string NotificationContractProposalTitle
Looks up a localized string similar to Contract proposal.
static string NotificationTokenRemovedBody
Looks up a localized string similar to Your wallet was updated..
static string NotificationReadAccessTitle
Looks up a localized string similar to Read access request from {0}.
static string NotificationIdentityRejectedTitle
Looks up a localized string similar to Identity status updated.
static string NotificationContractProposalBody
Looks up a localized string similar to A contract proposal is available..
static string NotificationIdentityCompromisedBody
Looks up a localized string similar to Your identity may be compromised..
static string NotificationTokenRemovedTitle
Looks up a localized string similar to Token removed.
static string NotificationIdentityObsoletedBody
Looks up a localized string similar to Your identity has been obsoleted..
static string NotificationBalanceUpdatedTitle
Looks up a localized string similar to Balance updated.
static string NotificationPetitionIdentityBody
Looks up a localized string similar to A new identity request is waiting..
static string NotificationIdentityApprovedBody
Looks up a localized string similar to Your identity was approved..
static string NotificationControlAccessBody
Looks up a localized string similar to Requested control access..
static string NotificationContractUpdatedTitle
Looks up a localized string similar to Contract updated.
static string NotificationPetitionIdentityTitle
Looks up a localized string similar to Identity request from {0}.
static string NotificationContractUpdatedBody
Looks up a localized string similar to A contract was updated..
static string NotificationContractSignedTitle
Looks up a localized string similar to Contract signed.
static string NotificationTokenAddedBody
Looks up a localized string similar to Your wallet was updated..
static string NotificationBalanceUpdatedBody
Looks up a localized string similar to Your balance was updated..
static string NotificationContractCreatedBody
Looks up a localized string similar to A new contract was created..
static string NotificationControlAccessTitle
Looks up a localized string similar to Control request from {0}.
static string NotificationIdentityApprovedTitle
Looks up a localized string similar to Identity status updated.
static string NotificationChatTitle
Looks up a localized string similar to {0}.
static string NotificationIdentityCompromisedTitle
Looks up a localized string similar to Identity status updated.
static string NotificationTokenAddedTitle
Looks up a localized string similar to Token added.
static string NotificationContractCreatedTitle
Looks up a localized string similar to Contract created.
static string NotificationChatBody
Looks up a localized string similar to Has sent you a message..
static string NotificationPresenceAccessBody
Looks up a localized string similar to Requested access to your identity..
static string NotificationPetitionSignatureTitle
Looks up a localized string similar to Signature request from {0}.
static string NotificationContractDeletedTitle
Looks up a localized string similar to Contract removed.
static string NotificationPetitionContractBody
Looks up a localized string similar to A new contract request is waiting..
static string NotificationPresenceAccessTitle
Looks up a localized string similar to Access request from {0}.
static string NotificationIdentityObsoletedTitle
Looks up a localized string similar to Identity status updated.
static string NotificationContractDeletedBody
Looks up a localized string similar to A contract was removed..
static string NotificationContractSignedBody
Looks up a localized string similar to A contract was signed..
Describes a push notification rule to provision in the XMPP broker.
string PatternScript
Optional pattern script to filter matching stanzas.
PushRuleDefinition(MessageType messageType, string localName, string @namespace, string channel, string messageVariable, string patternScript, string contentScript)
Initializes a new instance of the PushRuleDefinition class.
string Namespace
Namespace of the stanza element.
string LocalName
Local name of the stanza element.
string ContentScript
Script that produces the transport-agnostic push payload forwarded to the broker.
string MessageVariable
Variable name for the stanza passed into the rule.
Provides the set of push rules to provision.
static string RuleSetHash
Gets a hash representing the current rule set.
static IReadOnlyList< PushRuleDefinition > All
Gets all rule Definitions.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
const string NamespaceNeuroFeatures
Namespace for Neuro-Features.
Helps with common JSON-related tasks.
Definition: JSON.cs:16
static string Encode(string s)
Encodes a string for inclusion in JSON.
Definition: JSON.cs:537
Adds support for legal identities, smart contracts and signatures to an XMPP client.
const string NamespaceSmartContractsCurrent
Current namespce for smart contracts.
const string NamespaceLegalIdentitiesCurrent
Current namespace for legal identities.
Implements an XMPP provisioning client interface.
const string NamespaceProvisioningOwnerCurrent
Current namespace for provisioning by owners.
MessageType
Type of message received.
Definition: MessageType.cs:7