/// <summary> /// Patches a phone contact point with a subscription to a topic. Will create a new phone contact point if the phone contact point does not exist. Cannot be used to mark a phone contact point as inactive. /// </summary> private static void PatchPhoneContactPoint() { ContactName name = new ContactName() { FirstName = "John", LastName = "Doe" }; PhoneContactIdentity identity = new PhoneContactIdentity() { PhoneNumber = "+14256668888", //The phone number should follow the E.164 standard Name = name }; PhoneContactPoint phoneContactPoint = new PhoneContactPoint() { Identity = identity, Country = "US" //Use only ISO 2 char country codes. Any other string will result in HTTP 400 }; phoneContactPoint.TopicSettings.Add(new ContactPointTopicSetting { TopicId = testTopicId, //Topic ID for which this permission was collected CultureName = CultureInfo.CurrentCulture.ToString(), //Specify a culture supported by the topic. E.g en-US, fr-FR, fr-CA etc. Communication with the user will be based on this culture; LastSourceSetDate = DateTime.UtcNow, //The actual time at which this permission was collected. Could be in the past.. OriginalSource = "SampleCPMProject", //Name of this application that collected the consent. Saved for auditing purposes. State = ContactPointTopicSettingState.OptInExplicit //The permission }); cpmClient.PatchPhoneContactPoint(phoneContactPoint).Wait(); Console.WriteLine("Phone contact patch successfull"); }
public async Task <IEnumerable <PhoneContactPoint> > GetPhoneContactPoint(PhoneContactIdentity identity, bool useFuzzyMatch) { var matchingAlgo = useFuzzyMatch ? PhoneContactMatchStrategyType.PrioritizedNameElementFuzzyMatch : PhoneContactMatchStrategyType.ExactMatch; var reqMessage = new HttpRequestMessage(HttpMethod.Get, "api/PhoneContacts"); reqMessage = AddNameToReqHeaders(identity.Name, reqMessage); reqMessage.Headers.Add(HttpHeaders.PhoneNumberFilter, identity.PhoneNumber); reqMessage.Headers.Add(HttpHeaders.MatchingAlgorithmFilter, matchingAlgo.ToString()); return(await MakeRequestAndParseResponse <IEnumerable <PhoneContactPoint> >(reqMessage)); }
/// <summary> /// Patches a phone contact point with a subscription to a topic. Will create a new phone contact point if the phone contact point does not exist. Cannot be used to mark a phone contact point as inactive. /// </summary> /// <param name="phoneNumber">The phone number of the phone contact point eg. +1234567890</param> /// <param name="firstName">Optional, First Name. </param> /// <param name="middleName">Optional, Middle Name".</param> /// <param name="lastName">Optional, Last Name".</param> /// <param name="generationalSuffix">Optional, suffix eg. Sr".</param> /// <param name="countryName">the country of the phone contact point</param> /// <param name="topicId">the identifier of the topic</param> /// <param name="state">The state the subscription should be in eg. OptInExplicit</param> /// <returns></returns> private static async Task PatchPhoneContactPoint(string phoneNumber, string firstName, string middleName, string lastName, string generationalSuffix, string countryName, Guid topicId, ContactPointTopicSettingState state) { ContactName name = new ContactName() { FirstName = firstName, MiddleName = middleName, LastName = lastName, GenerationalSuffix = generationalSuffix }; PhoneContactIdentity identity = new PhoneContactIdentity() { PhoneNumber = phoneNumber, Name = name }; PhoneContactPoint phoneContactPoint = new PhoneContactPoint() { Identity = identity, Country = countryName }; phoneContactPoint.TopicSettings.Add(new ContactPointTopicSetting { TopicId = topicId, CultureName = CultureInfo.CurrentCulture.ToString(), LastSourceSetDate = DateTime.UtcNow, OriginalSource = "SampleCPMProject", State = state }); using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync()) { HttpResponseMessage response = await client.PatchAsync("api/PhoneContacts", phoneContactPoint); if (response.IsSuccessStatusCode) { // By design, we do not return the request body after a successful phone contact point patch } else { Console.WriteLine(await response.Content.ReadAsStringAsync()); } } }
/// <summary> /// Given an existing phone contact point type and contact point value, looks up the phone contact point and prints it out. /// </summary> private static void GetPhoneContactPoint() { ContactName name = new ContactName() { FirstName = "testfnone", MiddleName = "second", LastName = "testlnone" }; PhoneContactIdentity identity = new PhoneContactIdentity() { PhoneNumber = "+1234567890", //The phone number should follow the E.164 standard Name = name }; IEnumerable <PhoneContactPoint> result = cpmClient.GetPhoneContactPoint(identity, useFuzzyMatch: false).Result; Console.WriteLine(JsonConvert.SerializeObject(result)); }
/// <summary> /// Given a phone number, some optional name fields and a particular topic id, check if those contact values /// can be contacted by the topic id. /// This end point is pessimistic, in that if CPM does not know about the contact value or if the contact value does not know about the topic, /// the "CanContact" value will always return false. /// </summary> /// <param name="phoneNumber">The phone number to check. </param> /// <param name="firstName">Optional, First Name. </param> /// <param name="lastName">Optional, Last Name".</param> /// <param name="topicId">The topic id".</param> /// <returns></returns> private static async Task GetPhoneContactabilities(string phoneNumber, string firstName, string lastName, Guid topicId) { ContactName name = new ContactName() { FirstName = firstName, LastName = lastName }; PhoneContactIdentity identity = new PhoneContactIdentity() { PhoneNumber = phoneNumber, Name = name }; PhoneContactabilitiesRequest request = new PhoneContactabilitiesRequest() { Identity = identity, TargetedTopicId = topicId }; using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync()) { HttpResponseMessage response = await client.PostAsJsonAsync("/api/PhoneContactabilities", request); if (response.IsSuccessStatusCode) { PhoneContactabilitiesResponse result = await response.Content.ReadAsAsync <PhoneContactabilitiesResponse>(); Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); } else { Console.WriteLine(await response.Content.ReadAsStringAsync()); } } }
/// <summary> /// Given a phone number, some optional name fields and a particular topic id, check if those contact values /// can be contacted by the topic id. /// This end point is pessimistic, in that if CPM does not know about the contact value or if the contact value does not know about the topic, /// the "CanContact" value will always return false. /// </summary> private static void GetPhoneContactabilities() { ContactName name = new ContactName() { FirstName = "John", LastName = "Doe" }; PhoneContactIdentity identity = new PhoneContactIdentity() { PhoneNumber = "+14256668888", //The phone number should follow the E.164 standard Name = name }; PhoneContactabilitiesRequest request = new PhoneContactabilitiesRequest() { Identity = identity, TargetedTopicId = testTopicId }; PhoneContactabilitiesResponse result = cpmClient.GetPhoneContactability(request).Result; Console.WriteLine(JsonConvert.SerializeObject(result)); }