Exemplo n.º 1
0
        internal static void TriggerAction(NativeActionContext context, IDictionary <string, object> messageConfig)
        {
            if (!ShouldPerformActions)
            {
                return;
            }

            ActionDefinition actionDefinition;

            if (!VarCache.actionDefinitions.TryGetValue(context.Name, out actionDefinition))
            {
                // If no matching action definition is found, use the Generic one if such is registered
                if (VarCache.actionDefinitions.TryGetValue(Constants.Args.GENERIC_DEFINITION_NAME, out actionDefinition))
                {
                    IDictionary <string, object> args = new Dictionary <string, object>();
                    args.Add(Constants.Args.GENERIC_DEFINITION_CONFIG, messageConfig);
                    var genericActionContext = new NativeActionContext(context.Id, Constants.Args.GENERIC_DEFINITION_NAME, args);
                    context = genericActionContext;
                }
            }

            if (actionDefinition != null)
            {
                if (!string.IsNullOrEmpty(context.Id))
                {
                    // The View event is tracked using the messageId only, without an event name
                    context.TrackMessageEvent(null, 0, null, null);
                }
                actionDefinition.Responder?.Invoke(context);
            }
        }
        public static void DefineGenericDefinition()
        {
            string     configVars = $"{Constants.Args.GENERIC_DEFINITION_CONFIG}.vars";
            ActionArgs args       = new ActionArgs()
                                    .With <IDictionary <string, object> >(Constants.Args.GENERIC_DEFINITION_CONFIG, null)
                                    .With <IDictionary <string, object> >(configVars, null);

            ActionContext.ActionResponder responder = new ActionContext.ActionResponder((context) =>
            {
                var messageConfig                 = context.GetObjectNamed <Dictionary <string, object> >(Constants.Args.GENERIC_DEFINITION_CONFIG);
                var messageVars                   = context.GetObjectNamed <Dictionary <string, object> >(configVars);
                StringBuilder builder             = new StringBuilder();
                NativeActionContext nativeContext = context as NativeActionContext;
                if (nativeContext != null && !string.IsNullOrEmpty(nativeContext.Id))
                {
                    builder.AppendLine($"Message Id: {nativeContext.Id}");
                }
                BuildString("message",
                            messageConfig, builder, 0);

                EditorUtility.DisplayDialog(context.Name, builder.ToString(), null);
            });

            Leanplum.DefineAction(Constants.Args.GENERIC_DEFINITION_NAME, Constants.ActionKind.MESSAGE, args, null, responder);
        }
Exemplo n.º 3
0
        internal void Open(Message message)
        {
            var messageVars = message.ActionContext;
            var openAction  = Util.GetValueOrDefault(messageVars, Constants.Args.OPEN_ACTION) as IDictionary <string, object>;

            if (openAction != null)
            {
                // The inbox message id is with format <messageId>##<instance>
                string id = message.Id.Split(new string[] { "##" }, StringSplitOptions.RemoveEmptyEntries)[0];

                string actionName = Util.GetValueOrDefault(messageVars, Constants.Args.ACTION_NAME, string.Empty)?.ToString();

                var actionContext = new NativeActionContext(id, actionName, messageVars);
                actionContext.RunTrackedActionNamed(Constants.Args.OPEN_ACTION);
            }
        }
Exemplo n.º 4
0
        internal static void TriggerAction(string id, IDictionary <string, object> message)
        {
            if (!ShouldPerformActions)
            {
                return;
            }

            string actionName = Util.GetValueOrDefault(message, Constants.Args.ACTION) as string;
            IDictionary <string, object> vars = Util.GetValueOrDefault(message, Constants.Args.VARS) as IDictionary <string, object>;

            if (!string.IsNullOrEmpty(actionName) && vars != null)
            {
                NativeActionContext actionContext = new NativeActionContext(id, actionName, vars);
                TriggerAction(actionContext, message);
            }
        }
Exemplo n.º 5
0
        internal static void TriggerPreview(IDictionary <string, object> packetData)
        {
            var actionData = Util.GetValueOrDefault(packetData, Constants.Args.ACTION) as IDictionary <string, object>;

            if (actionData != null)
            {
                string actionName = Util.GetValueOrDefault(actionData, Constants.Args.ACTION_NAME)?.ToString();
                string messageId  = Util.GetValueOrDefault(packetData, Constants.Args.MESSAGE_ID)?.ToString();
                LeanplumNative.CompatibilityLayer.Log($"Preview of {actionName} Message with Id: {messageId}");
                if (!string.IsNullOrWhiteSpace(actionName))
                {
                    var newVars            = VarCache.MergeMessage(actionData);
                    NativeActionContext ac = new NativeActionContext(messageId, actionName, newVars);
                    TriggerAction(ac, newVars);
                }
            }
        }