Exemple #1
0
        /// <summary>
        /// Patches a sms contact point with a subscription to a topic. Will create a new sms contact point if the sms contact point does not exist. Cannot be used to mark a sms contact point as inactive.
        /// </summary>
        /// <param name="phoneNumber">The phone number of the sms contact point eg. +1234567890</param>
        /// <param name="countryName">the country of the sms 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 PatchSmsContactPoint(string phoneNumber, string countryName, Guid topicId, ContactPointTopicSettingState state)
        {
            SmsContactPoint smsContactPoint = new SmsContactPoint()
            {
                Phone   = phoneNumber,
                Country = countryName
            };

            smsContactPoint.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/SmsContacts", smsContactPoint);

                if (response.IsSuccessStatusCode)
                {
                    SmsContactPoint patched = await response.Content.ReadAsAsync <SmsContactPoint>();

                    Console.WriteLine(JsonConvert.SerializeObject(patched, Formatting.Indented));
                }
                else
                {
                    Console.WriteLine(await response.Content.ReadAsStringAsync());
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Given an existing phone number, looks up the sms contact point and prints it out.
        /// </summary>
        /// <param name="phoneNumber">The phone number of the sms contact point eg. +1234567890</param>
        /// <returns></returns>
        private static async Task GetSmsContactPoint(string phoneNumber)
        {
            using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync())
            {
                HttpMethod         get     = new HttpMethod("GET");
                HttpRequestMessage request = new HttpRequestMessage(get, "api/SmsContacts");
                request.Headers.Add("x-ms-filter-phone-number", phoneNumber);
                HttpResponseMessage response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    SmsContactPoint smsContactPoint = await response.Content.ReadAsAsync <SmsContactPoint>();

                    Console.WriteLine(JsonConvert.SerializeObject(smsContactPoint, Formatting.Indented));
                }
                else
                {
                    Console.WriteLine(await response.Content.ReadAsStringAsync());
                }
            }
        }