/// <summary> /// Add Interaction /// </summary> /// <param name="identifier">Email</param> /// <param name="googleApiFacetInfo"></param> public void RegisterInteraction(string identifier, GoogleApiFacetInfo googleApiFacetInfo) { using (XConnectClient client = GetClient()) { var contactReference = new IdentifiedContactReference(Constans.xConnectApiSource, identifier); var contact = client.Get <Contact>(contactReference, new ContactExpandOptions(new string[] { PersonalInformation.DefaultFacetKey })); if (contact == null) { return; } Interaction interaction = new Interaction(contactReference, InteractionInitiator.Contact, channelId: new Guid(Constans.Offline_OtherEventChannelId), userAgent: Constans.UserAgent); // Add Custom GoogleApiFacet GoogleApiFacet googleApiFacet = contact.GetFacet <GoogleApiFacet>(GoogleApiFacet.FacetName); if (googleApiFacet == null) { googleApiFacet = new GoogleApiFacet(); googleApiFacet.GoogleApiFacetInfoList.Add(new GoogleApiFacetInfo { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } else { googleApiFacet.GoogleApiFacetInfoList.Add(new GoogleApiFacetInfo { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } client.SetFacet <GoogleApiFacet>(new FacetReference(contact, GoogleApiFacet.FacetName), googleApiFacet); //// Adding some face information //IpInfo ipInfo = new IpInfo("127.0.0.1"); //ipInfo.BusinessName = "Home"; //client.SetFacet<IpInfo>(interaction, IpInfo.DefaultFacetKey, ipInfo); //WebVisit webVisit = new WebVisit(); //webVisit.SiteName = "Offline"; //client.SetFacet<WebVisit>(interaction, WebVisit.DefaultFacetKey, webVisit); Outcome outcome = new Outcome(new Guid(Constans.Offline_OtherEventChannelId), DateTime.UtcNow, "USD", 0) { EngagementValue = 10, Text = "Google Api Interaction" }; interaction.Events.Add(outcome); client.AddInteraction(interaction); client.Submit(); } }
public HttpResponseMessage AddGoogleInteraction(GoogleInteractionRequestModel googleInteractionRequestModel) { HttpResponseMessage response; try { if (googleInteractionRequestModel == null || !IsValidEmail(googleInteractionRequestModel.Email)) { response = Request.CreateResponse(HttpStatusCode.BadRequest, InvalidInputParametersMessage); return(response); } bool isContactIdentified = _xConnectService.IdentifyContact(googleInteractionRequestModel.Email); if (!isContactIdentified) { response = Request.CreateResponse(HttpStatusCode.BadRequest, InvalidContactIdentifiedMessage); return(response); } GoogleApiFacetInfo googleApiFacetInfo = new GoogleApiFacetInfo { ZipCode = googleInteractionRequestModel.ZipCode, RestaurantType = googleInteractionRequestModel.RestaurantType }; _xConnectService.RegisterInteraction(googleInteractionRequestModel.Email, googleApiFacetInfo); response = Request.CreateResponse(HttpStatusCode.Created); return(response); } catch (Exception ex) { Log.Error($"Error in XConnectApiController.AddGoogleInteraction(): while adding interaction for contact with email: {googleInteractionRequestModel?.Email}", ex, this); response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, InternalServerErrorMessage); return(response); } }