Пример #1
0
        public bool getInteractionFacets(Guid contactId, string chatId, string questionId, string answerId)
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    //Contact reference from ID
                    var reference = new Sitecore.XConnect.ContactReference(contactId);
                    // Retrieve contact
                    var results = client.Get <Contact>(reference, new Sitecore.XConnect.ContactExpandOptions()
                    {
                        Interactions = new Sitecore.XConnect.RelatedInteractionsExpandOptions(ChatBotAnalytics.DefaultFacetKey)
                        {
                        }
                    });

                    var interactionFacet = results?.Interactions.Where(x => x.GetFacet <ChatBotAnalytics>()?.ChatId == chatId && x.GetFacet <ChatBotAnalytics>()?.Question == questionId && x.GetFacet <ChatBotAnalytics>()?.Answer == answerId);

                    if (interactionFacet != null && interactionFacet.Count() > 0)
                    {
                        return(true);
                    }
                }
                catch (XdbExecutionException ex)
                {
                    // Manage exceptions
                }
            }

            return(false);
        }
Пример #2
0
        public Sitecore.XConnect.Contact GetContact(string email)
        {
            try
            {
                using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
                {
                    try
                    {
                        if (IsContactInSession(email))
                        {
                            var reference = new Sitecore.XConnect.ContactReference(Tracker.Current.Session.Contact.ContactId);

                            var contact = client.Get(reference, new Sitecore.XConnect.ContactExpandOptions()
                            {
                            });

                            return(contact);
                        }

                        // Retrieve contact
                        Sitecore.XConnect.Contact existingContact = client.Get(new IdentifiedContactReference("hubspotFormUser", email), new Sitecore.XConnect.ContactExpandOptions(ScoreFacet.DefaultFacetKey, ScoreNameFacet.DefaultFacetKey, PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey));

                        if (existingContact != null)
                        {
                            return(existingContact);
                        }

                        return(null);
                    }
                    catch (XdbExecutionException)
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Error updating contact score facet with the email:" + email, ex, this);
                return(null);
            }
        }
Пример #3
0
        private static async Task UpdateContactFacet(XConnectClientConfiguration xConfig, string contactId, string firstName, string lastName, string email, string countryCode, string mobileNumber, string customerStatus)
        {
            // Initialize a client using the validated configuration
            using (var client = new XConnectClient(xConfig))
            {
                try
                {
                    Contact contact;
                    //IdentifiedContactReference reference;
                    //ContactReference reference;
                    if (!string.IsNullOrEmpty(contactId))
                    {
                        var reference = new Sitecore.XConnect.ContactReference(Guid.Parse(contactId));
                        contact = client.Get <Contact>(reference, new ContactExpandOptions(new string[] {
                            PersonalInformation.DefaultFacetKey,
                            EmailAddressList.DefaultFacetKey,
                            PhoneNumberList.DefaultFacetKey,
                            CustomerFacets.DefaultFacetKey
                        }));
                    }
                    else
                    {
                        IdentifiedContactReference reference = new IdentifiedContactReference("CustomerRef", email);
                        contact = client.Get <Contact>(reference, new ContactExpandOptions(new string[] {
                            PersonalInformation.DefaultFacetKey,
                            EmailAddressList.DefaultFacetKey,
                            PhoneNumberList.DefaultFacetKey,
                            CustomerFacets.DefaultFacetKey
                        }));
                    }

                    if (contact != null)
                    {
                        var customerFacet = contact.GetFacet <CustomerFacets>(CustomerFacets.DefaultFacetKey);

                        if (customerFacet != null)
                        {
                            // Change facet properties
                            customerFacet.CustomerStatus = customerStatus;
                            //Update facet in contact
                            client.SetFacet(contact, customerFacet);
                        }
                        else
                        {
                            // Facet is new
                            CustomerFacets newCustomerFacet = new CustomerFacets()
                            {
                                CustomerStatus = customerStatus
                            };
                            client.SetFacet(contact, newCustomerFacet);
                        }

                        PersonalInformation existingContactPersonalFacet = contact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey);
                        if (existingContactPersonalFacet != null)
                        {
                            existingContactPersonalFacet.FirstName = firstName;
                            existingContactPersonalFacet.LastName  = lastName;
                            client.SetFacet(contact, PersonalInformation.DefaultFacetKey, existingContactPersonalFacet);
                        }
                        else
                        {
                            PersonalInformation newPersonalFacet = new PersonalInformation()
                            {
                                FirstName = firstName,
                                LastName  = lastName
                            };
                            client.SetFacet(contact, PersonalInformation.DefaultFacetKey, newPersonalFacet);
                        }

                        PhoneNumberList existingContactPhonFacet = contact.GetFacet <PhoneNumberList>(PhoneNumberList.DefaultFacetKey);
                        if (existingContactPhonFacet != null)
                        {
                            existingContactPhonFacet.PreferredPhoneNumber = new PhoneNumber(countryCode, mobileNumber);
                            existingContactPhonFacet.PreferredKey         = "Mobile";
                            client.SetFacet(contact, PhoneNumberList.DefaultFacetKey, existingContactPhonFacet);
                        }
                        else
                        {
                            PhoneNumberList newContactPhonFacet = new PhoneNumberList(new PhoneNumber(countryCode, mobileNumber), "Mobile");
                            client.SetFacet(contact, PhoneNumberList.DefaultFacetKey, newContactPhonFacet);
                        }

                        await client.SubmitAsync();
                    }

                    Console.ReadLine();
                }
                catch (XdbExecutionException ex)
                {
                    // Deal with exception
                }
            }
        }
        /// Executes the specified rule context.
        /// <param name="ruleContext">The rule context.</param>
        /// <returns>
        ///   <c>True</c>, if the condition succeeds, otherwise <c>false</c>.
        /// </returns>
        protected override bool Execute(T ruleContext)
        {
            Assert.ArgumentNotNull((object)ruleContext, nameof(ruleContext));
            Assert.IsNotNull((object)Tracker.Current, "Tracker.Current is not initialized");
            Assert.IsNotNull((object)Tracker.Current.Session, "Tracker.Current.Session is not initialized");
            Assert.IsNotNull((object)Tracker.Current.Session.Interaction, "Tracker.Current.Session.Interaction is not initialized");
            try
            {
                this.GoalGuid = new Guid(this.GoalId);
            }
            catch
            {
                Log.Warn(string.Format("Could not convert value to guid: {0}", (object)this.GoalId), (object)this.GetType());
                return(false);
            }

            try
            {
                this.PageGuid = new Guid(this.PageId);
            }
            catch
            {
                Log.Warn(string.Format("Could not convert value to guid: {0}", (object)this.PageId), (object)this.GetType());
                return(false);
            }

            HttpCookie globalCookie = HttpContext.Current.Request.Cookies["sc_analytics_global_cookie"];



            if (globalCookie != null)
            {
                // Find the Cookie Value

                string cookieValue = globalCookie.Value.Substring(0, 32);

                // Convert the Cookie value to Guid

                Guid contactid = Guid.Parse(cookieValue);



                using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
                {
                    var reference = new Sitecore.XConnect.ContactReference(contactid);

                    Contact contact = client.Get <Contact>(reference, new Sitecore.XConnect.ContactExpandOptions()
                    {
                    });

                    if (contact != null)
                    {
                        // Identify the the Known contact

                        if (contact.IsKnown)
                        {
                            DateTime currentDateTime = DateTime.Now;
                            DateTime pastDateTime    = currentDateTime.AddYears(-10);

                            //Find out if there are any interaction from past date

                            var results = client.Get <Sitecore.XConnect.Contact>(reference, new Sitecore.XConnect.ContactExpandOptions()
                            {
                                Interactions = new Sitecore.XConnect.RelatedInteractionsExpandOptions()
                                {
                                    StartDateTime = pastDateTime,
                                    EndDateTime   = currentDateTime,
                                }
                            });

                            if (results == null)
                            {
                                return(false);
                            }
                            else
                            {
                                List <Goal> goals = new List <Goal>();
                                foreach (var intercation in results.Interactions)
                                {
                                    goals.AddRange(intercation.Events.OfType <Goal>().Where(c => c.ItemId == this.PageGuid && c.DefinitionId == this.GoalGuid));
                                }
                                return(goals.Any());
                            }
                        }
                    }
                }
            }

            return(false);
        }
Пример #5
0
        /// Executes the specified rule context.
        /// <param name="ruleContext">The rule context.</param>
        /// <returns>
        ///   <c>True</c>, if the condition succeeds, otherwise <c>false</c>.
        /// </returns>
        protected override bool Execute(T ruleContext)
        {
            // Get the Global Cookie

            HttpCookie globalCookie = HttpContext.Current.Request.Cookies["sc_analytics_global_cookie"];


            // Number of days which user has not logged in

            int value;

            if (!int.TryParse(this.Value, out value))
            {
                Log.Debug(string.Format("Specified number [{0}] was not a valid Number", this.Value));
                return(false);
            }
            if (globalCookie != null)
            {
                // Find the Cookie Value

                string cookieValue = globalCookie.Value.Substring(0, 32);

                // Convert the Cookie value to Guid

                Guid contactid = Guid.Parse(cookieValue);


                // Get the Contact using Golable Cookie

                using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
                {
                    var reference = new Sitecore.XConnect.ContactReference(contactid);

                    Contact contact = client.Get <Contact>(reference, new Sitecore.XConnect.ContactExpandOptions()
                    {
                    });

                    if (contact != null)
                    {
                        // Identify the the Known contact

                        if (contact.IsKnown)
                        {
                            DateTime currentDateTime = DateTime.Now;
                            DateTime pastDateTime    = currentDateTime.AddDays(-value);

                            //Find out if there are any interaction from past date

                            var results = client.Get <Sitecore.XConnect.Contact>(reference, new Sitecore.XConnect.ContactExpandOptions()
                            {
                                Interactions = new Sitecore.XConnect.RelatedInteractionsExpandOptions()
                                {
                                    StartDateTime = pastDateTime,
                                    EndDateTime   = currentDateTime,
                                }
                            });

                            if (results == null)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }