56 public Dictionary<string, object>
Context {
get;
set; }
66 public Dictionary<string, object>
CustomData {
get;
set; }
73 object Normalized = Normalize(Content);
81 if (Normalized is Dictionary<string, object> Dict && HasPayloadMarker(Dict))
83 Payload = FromDictionary(Dict);
101 Context = GetDict(Dict,
"context"),
102 CustomData = GetDict(Dict,
"data") ?? GetDict(Dict,
"customData") ?? GetDict(Dict,
"custom"),
109 private static Dictionary<ClientType, Dictionary<string, object>> ParsePlatformOverrides(Dictionary<string, object> Dict)
111 if (Dict is
null || Dict.Count == 0)
114 Dictionary<ClientType, Dictionary<string, object>> Result =
new Dictionary<ClientType, Dictionary<string, object>>();
116 foreach (KeyValuePair<string, object> P
in Dict)
121 if (Normalize(P.Value) is Dictionary<string, object> OverrideDict && OverrideDict.Count > 0)
125 return Result.Count == 0 ? null : Result;
128 private static bool HasPayloadMarker(Dictionary<string, object> Dict)
133 string PayloadKind = GetString(Dict,
"payloadKind") ?? GetString(Dict,
"PayloadKind");
137 private bool IsPayloadKind()
139 return !
string.IsNullOrEmpty(this.PayloadKind) &&
140 string.Equals(this.PayloadKind,
DefaultKind, StringComparison.OrdinalIgnoreCase);
143 private static object Normalize(
object Value)
148 if (Value is Dictionary<string, IElement> ScriptDict)
150 Dictionary<string, object> Converted =
new Dictionary<string, object>();
151 foreach (KeyValuePair<string, IElement> P
in ScriptDict)
152 Converted[P.Key] = Normalize(P.Value);
157 if (Value is Dictionary<string, object> Dict)
159 Dictionary<string, object> Converted =
new Dictionary<string, object>();
160 foreach (KeyValuePair<string, object> P
in Dict)
161 Converted[P.Key] = Normalize(P.Value);
166 if (Value is IEnumerable Enumerable && !(Value is
string))
168 List<object> Items =
new List<object>();
169 foreach (
object Item
in Enumerable)
170 Items.Add(Normalize(Item));
172 return Items.ToArray();
178 internal static Dictionary<string, object> GetDict(Dictionary<string, object> Parent,
string Key)
183 if (!Parent.TryGetValue(Key, out
object Value))
186 return Normalize(Value) as Dictionary<string, object>;
189 internal static string GetString(Dictionary<string, object> Dict,
string Key)
194 if (!Dict.TryGetValue(Key, out
object Value) || Value is
null)
197 return Value.ToString();
200 internal static int? GetInt(Dictionary<string, object> Dict,
string Key)
202 if (Dict is
null || !Dict.TryGetValue(Key, out
object Value) || Value is
null)
214 if (
int.
TryParse(Value.ToString(), out
int i2))
220 internal static bool? GetBool(Dictionary<string, object> Dict,
string Key)
222 if (Dict is
null || !Dict.TryGetValue(Key, out
object Value) || Value is
null)
230 if (
bool.
TryParse(Value.ToString(), out
bool b2))
247 public string Body {
get;
set; }
249 public string Icon {
get;
set; }
253 internal static PushVisual FromDictionary(Dictionary<string, object> Dict)
275 public string Type {
get;
set; }
283 internal static PushAction FromDictionary(Dictionary<string, object> Dict)
310 public string[]
Tags {
get;
set; }
312 internal static PushChannel FromDictionary(Dictionary<string, object> Dict)
317 object TagsValue =
null;
318 Dict?.TryGetValue(
"tags", out TagsValue);
320 string[]
Tags = TagsValue
switch
323 IEnumerable<object> Items =>
new List<string>(Array.ConvertAll(
new List<object>(Items).ToArray(), x => x.ToString())).ToArray(),
327 return new PushChannel
329 ChannelId = PushNotificationPayload.GetString(Dict,
"channelId") ?? PushNotificationPayload.GetString(Dict,
"channel_id"),
330 Category = PushNotificationPayload.GetString(Dict,
"category"),
331 Importance = PushNotificationPayload.GetString(Dict,
"importance"),
345 public int?
Ttl {
get;
set; }
351 internal static PushDelivery FromDictionary(Dictionary<string, object> Dict)
Action the client should perform.
string EntityId
Entity identifier to act upon.
string CorrelationId
Correlation identifier.
string Type
Action type identifier (e.g. OpenChat, OpenContract).
string NavigationTarget
Client navigation target.
Client channel/category metadata.
string ChannelId
Channel identifier.
string Importance
Importance level (client defined).
string Category
Category/notification category.
string[] Tags
Tags to help clients route notifications locally.
string Priority
Delivery priority.
int? Ttl
Time to live (seconds).
bool Silent
Flag for silent delivery.
string CollapseKey
Collapse key.
Transport-agnostic push notification payload describing notification intent.
PushVisual Visual
Visual presentation on the device.
PushChannel Channel
Client-side channel/category information.
Dictionary< string, object > Context
Arbitrary context metadata.
int PayloadVersion
Version of the payload contract.
string PayloadKind
Discriminator to identify payloads.
Dictionary< string, object > CustomData
Additional custom data to include in the notification payload.
const string DefaultKind
Default discriminator value.
static bool TryParse(object Content, out PushNotificationPayload Payload)
Attempts to parse a payload from a script or serialized object.
PushDelivery Delivery
Delivery characteristics (priority, TTL, collapse key, silent).
const int CurrentVersion
Current payload version.
PushAction Action
Action to execute when the notification is acted on.
Dictionary< ClientType, Dictionary< string, object > > PlatformOverrides
Platform-specific override fragments keyed by client type.
Visual description of the notification.
string Subtitle
Subtitle text.
string Icon
Icon reference.
Base class for all types of elements.
abstract object AssociatedObjectValue
Associated object value.
Basic interface for all types of elements.
ClientType
Type of client requesting notification.