private ProfileScores GetProfileScores(IContactProcessingContext context)
        {
            //ContactBehaviorProfile contactFacet = this.GetContactFacet<ContactBehaviorProfile>(context.Contact);

            XConnectClient client = XConnectClientReference.GetClient();

            Contact existingContact = client.Get <Contact>(
                (IEntityReference <Contact>)context.Contact,
                new ContactExpandOptions(ContactBehaviorProfile.DefaultFacetKey));

            ContactBehaviorProfile contactFacet = existingContact.GetFacet <ContactBehaviorProfile>(ContactBehaviorProfile.DefaultFacetKey);

            if (contactFacet == null)
            {
                contactFacet = new ContactBehaviorProfile();
            }

            ChangeContactBehaviorProfileValue.UpdateContactBehaviorProfile(contactFacet.Scores, (IEnumerable <BehaviorProfileValue>) this.BehaviorProfileValues);
            ProfileScores profileScores = new ProfileScores();

            foreach (KeyValuePair <Guid, ProfileScore> keyValuePair in contactFacet.Scores)
            {
                profileScores.Scores.Add(keyValuePair.Key, keyValuePair.Value);
            }

            foreach (var profileScore in profileScores.Scores)
            {
                Log.Debug("profileScore kv Key = " + profileScore.Key);
                Log.Debug("profileScore kv Value = " + profileScore.Value);
            }

            return(profileScores);
        }
Пример #2
0
        public override ActivityResult Invoke(IContactProcessingContext context)
        {
            EmailAddressList facet = context.Contact.GetFacet <EmailAddressList>();

            if (facet == null)
            {
                return((ActivityResult) new Failure(Resources.TheEmailAddressListFacetHasNotBeenSetSuccessfully));
            }

            string email = facet.PreferredEmail.SmtpAddress;

            LoggerExtensions.LogInformation(this.Logger, "processing agenda email for: " + email);

            //Get agenda url
            string urlformat = ConfigurationManager.AppSettings["agendaurlformat"];

            //add contact id as parameter
            Guid?contactID = context.Contact.Id;

            string url = string.Format(urlformat, contactID);

            LoggerExtensions.LogInformation(this.Logger, "processing agenda for url: " + url);

            //make request, get body, send email
            var emailService = new EmailService();
            var sended       = emailService.SendSmtpEmail(email, url);

            if (!sended)
            {
                LoggerExtensions.LogInformation(this.Logger, "Message was not sent");
            }

            LoggerExtensions.LogDebug((ILogger)this.Logger, string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.TheFacetHasBeenSetAndSubmittedSuccessfullyPattern, (object)"EmailAddressList"), Array.Empty <object>());
            return((ActivityResult) new SuccessMove());
        }
Пример #3
0
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            Condition.Requires(context.Contact).IsNotNull();
            Condition.Requires(NotificationService).IsNotNull();

            var tokens     = new List <string>();
            var tokenFacet = context.Contact.GetFacet <StringValueListFacet>(FacetIDs.SubscriptionTokens);

            if (tokenFacet != null)
            {
                var token = tokenFacet.Values.FirstOrDefault();

                try
                {
                    NotificationService.SendInitialEventNotification(context.Contact, Title, Body, token);
                    return(new SuccessMove());
                }
                catch (Exception ex)
                {
                    return(new Failure($"SendPushNotification failed with '{ex.Message}'"));
                }
            }

            return(new Failure($"SendPushNotification failed. No subscription token was resolved for contact {context.Contact.Id}."));
        }
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            var contact = context.Contact;

            if (!contact.IsKnown)
            {
                return((ActivityResult) new SuccessMove());
            }

            if (!contact.ExpandOptions.FacetKeys.Contains(PersonalInformation.DefaultFacetKey))
            {
                var expandOptions = new ContactExpandOptions(PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey);
                contact = Services.Collection.GetContactAsync(contact, expandOptions).ConfigureAwait(false).GetAwaiter().GetResult();
            }

            var emailFacets  = contact.GetFacet <EmailAddressList>();
            var personalInfo = contact.GetFacet <PersonalInformation>();
            var fields       = "{" +
                               "\"Email\": \"" + emailFacets.PreferredEmail?.SmtpAddress + "\", " +
                               "\"FirstName\": \"" + personalInfo.FirstName + "\", " +
                               "\"MiddleName\": \"" + personalInfo.MiddleName + "\", " +
                               "\"LastName\": \"" + personalInfo.LastName + "\", " +
                               "\"PreferredLanguage\": \"" + personalInfo.PreferredLanguage + "\", " +
                               "\"Title\": \"" + personalInfo.Title + "\", " +
                               "\"JobTitle\": \"" + personalInfo.JobTitle + "\" " +
                               "}";

            Task.Run(() => PostRequest(triggerAddress, fields));

            return((ActivityResult) new SuccessMove());
        }
        private Interaction CreateInteraction(IContactProcessingContext context)
        {
            Interaction interaction = new Interaction((IEntityReference <Contact>)context.Contact, InteractionInitiator.Brand, Constants.SystemChannelId, Constants.UserAgent);
            Event       @event      = new Event(Constants.ProfileScoreChangeEventDefinitionId, DateTime.UtcNow);

            interaction.Events.Add(@event);
            XdbContextOperationExtensions.AddInteraction(this.Services.Collection, interaction);
            return(interaction);
        }
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            //   Log.Info("IftttActivity - TADA !!!!!!!", this);
            // Actually, can't call logging from xConnect

            // TODO: Pull inputs from Marketing Automation Instance (because we can't call sitecore databases from xConnect
            Ifttt.Trigger("nV4IGcOUNyGb8RG83PZz4ZclSfydE_eai5sg0golPZ9", "sitecore_event", "Hard Coded Marketing Automation Value");

            return(new SuccessMove("true"));
        }
 public ActivityResult Invoke(IContactProcessingContext context)
 {
     if (!string.IsNullOrEmpty(this.message))
     {
         Guid    planDefinitionId = context.ActivityEnrollment.EnrollmentKey.PlanDefinitionId;
         Contact contact          = context.Contact;
         if (contact != null)
         {
             message = GetPersonalizedMessage(message, contact);
             _AzureQueueSendingService.SendAzureQueueAsync(message);
         }
     }
     return(new SuccessMove());
 }
Пример #8
0
        public override ActivityResult Invoke(IContactProcessingContext context)
        {
            Condition.Requires <IContactProcessingContext>(context, nameof(context)).IsNotNull <IContactProcessingContext>();

            if (context.Interaction == null)
            {
                Logger.LogDebug("context interaction is null, processing as success to the next action");
                return((ActivityResult) new SuccessMove());
            }

            Logger.LogDebug("Debug context interaction id: " + context.Interaction.Id);

            return((ActivityResult) new SuccessMove());
        }
Пример #9
0
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            try
            {
                Services.Collection.ExecuteRightToBeForgotten(context.Contact);
                Services.Collection.Submit();

                return(new SuccessMove());
            }
            catch (Exception ex)
            {
                // in case of error, report failure; note that the contact will not move past the current step of the automation plan
                return(new Failure($"Error anonymizing contact: {ex.Message}"));
            }
        }
Пример #10
0
        /// <summary>
        /// Invokes the activity.
        /// </summary>
        /// <param name="context">The context for the activity invocation.</param>
        /// <returns>The result of the invocation.</returns>
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            var facet = context.Contact.GetFacet <SurakFacet>(SurakFacet.DefaultFacetName);

            if (facet == null)
            {
                facet = new SurakFacet();
            }

            facet.Rigel = Rigel;

            Services.Collection.SetFacet(context.Contact, facet);
            Services.Collection.Submit();

            return(new SuccessMove());
        }
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            Condition.Requires(context, nameof(context)).IsNotNull();

            try
            {
                _xdbContext.ExecuteRightToBeForgotten(context.Contact);
                _xdbContext.Submit();

                return(new SuccessExitPlan());
            }
            catch (Exception e)
            {
                _logger.LogError(0, e, "ExecuteRightToBeForgottenActivity failed");
                return(new Failure("ExecuteRightToBeForgottenActivity failed", TimeSpan.FromMinutes(5)));
            }
        }
Пример #12
0
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            Condition.Requires(context.Contact).IsNotNull();
            Condition.Requires(NotificationService).IsNotNull();

            var subscriptionFacet  = context.Contact.GetFacet <StringValueListFacet>(FacetIDs.Subscriptions);
            var eventSubscriptions = new List <string>();

            if (subscriptionFacet != null)
            {
                foreach (var subscription in subscriptionFacet.Values)
                {
                    eventSubscriptions.Add(subscription);
                }
            }

            var tokenFacet = context.Contact.GetFacet <StringValueListFacet>(FacetIDs.SubscriptionTokens);
            var tokens     = new List <string>();

            if (tokenFacet != null)
            {
                foreach (var tokenId in tokenFacet.Values)
                {
                    tokens.Add(tokenId);
                }
            }

            var token = tokens.FirstOrDefault();

            try
            {
                foreach (var eventSubscription in eventSubscriptions)
                {
                    NotificationService.SendInitialEventNotification(context.Contact, token);
                }

                return(new SuccessMove());
            }
            catch (Exception ex)
            {
                return(new Failure($"SendPushNotification failed with '{ex.Message}'"));
            }
        }
Пример #13
0
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            try
            {
                var subscriptions = context.Contact.GetFacet <PushSubscriptions>();
                if (subscriptions == null)
                {
                    return(new SuccessMove("default"));
                }

                var notification = new Notification()
                {
                    Title = this.Title,
                    Body  = this.Body,
                    Image = this.Image,
                    Icon  = this.Icon,
                    CTA   = this.CTA
                };

                var message = JsonConvert.SerializeObject(notification);

                //Dictionary using device, we just want all, so take the value in the KVP
                foreach (var subscription in subscriptions.Subscriptions)
                {
                    try
                    {
                        //Let's send them.
                        PushNotificationService.SendNotification(subscription.Value, message, subscription.Value.VapidPublicKey, subscription.Value.VapidPrivateKey);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(ex, "Failed to send Push Notification");
                    }
                }

                return(new SuccessMove("default"));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Failed sending Message");
                return(new Failure("failed"));
            }
        }
Пример #14
0
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            try
            {
                // get the tracker id to match up with the form entry bc xconnect and tracker id are not the same
                const string source     = SaveDataWithContact.TrackerIdFieldName;
                var          identifier = context.Contact.Identifiers.FirstOrDefault(i => i.Source.Equals(source))?.Identifier;

                if (identifier != null)
                {
                    var trackerId = new Guid(identifier);
                    DataManagementService.DeleteFormEntries(trackerId);
                }

                return(new SuccessMove());
            }
            catch (Exception ex)
            {
                // in case of error, report failure; note that the contact will not move past the current step of the automation plan
                return(new Failure($"Error erasing form submissions: {ex.Message}"));
            }
        }
Пример #15
0
        public ActivityResult Invoke(IContactProcessingContext context)
        {
            //get email facet from context contact
            EmailAddressList facet = context.Contact.GetFacet <EmailAddressList>();

            //exiting activity with failure
            if (facet == null || facet.PreferredEmail == null)
            {
                return((ActivityResult) new Failure(Resources.TheEmailAddressListFacetHasNotBeenSetSuccessfully));
            }

            string email = facet.PreferredEmail.SmtpAddress;

            //instantiating email service without DI for simplicity
            var emailService = new EmailService();

            if (!emailService.SendPromoEmail(email))
            {
                return((ActivityResult) new Failure("Failed to send promo email"));
            }

            return((ActivityResult) new SuccessMove());
        }
 public override ActivityResult Invoke(IContactProcessingContext context)
 {
     if (this.BehaviorProfileValues != null)
     {
         if (Enumerable.Any <BehaviorProfileValue>((IEnumerable <BehaviorProfileValue>) this.BehaviorProfileValues))
         {
             try
             {
                 CollectionModel.SetProfileScores(this.Services.Collection, this.CreateInteraction(context), this.GetProfileScores(context));
                 XConnectSynchronousExtensions.Submit(this.Services.Collection);
                 //LoggerExtensions.LogDebug((ILogger)this.Logger, string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.TheFacetHasBeenSetAndSubmittedSuccessfullyPattern, (object)"ContactBehaviorProfile"), Array.Empty<object>());
                 return((ActivityResult) new SuccessMove());
             }
             catch (Exception ex) when(ex is FacetOperationException || ex is ArgumentNullException || ex is InvalidOperationException)
             {
                 //LoggerExtensions.LogError((ILogger)this.Logger, (EventId)0, ex, string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.TheFacetHasNotBeenSetAndSubmittedSuccessfullyPattern, (object)"ContactBehaviorProfile"), Array.Empty<object>());
                 return((ActivityResult) new Failure(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.TheFacetHasNotBeenSetAndSubmittedSuccessfullyPattern, (object)"ContactBehaviorProfile")));
             }
         }
     }
     Log.Debug(string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.TheActivityPropertyHasNotBeenSetPattern, (object)"BehaviorProfileValues"), Array.Empty <object>());
     return((ActivityResult) new Failure(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.TheActivityPropertyHasNotBeenSetPattern, (object)"BehaviorProfileValues")));
 }
 public ActivityResult Invoke(IContactProcessingContext context)
 {
     _airService.UpdateAirQualityForContact(context.Contact);
     return(new SuccessMove());
 }