/// <summary>
        /// Send SMS service.
        /// </summary>
        /// <param name="request">The request object</param>
        /// <returns></returns>
        public async Task <bool> SendSMS(RequestSMS request)
        {
            try
            {
                var uri     = baseurl + "Messages";
                var content = JsonConvert.SerializeObject(request, Formatting.None, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                var buffer      = Encoding.UTF8.GetBytes(content);
                var byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await _httpClient.PostAsync(uri, byteContent);

                var result = response.Content.ReadAsStringAsync().Result;
                resp = JsonConvert.DeserializeObject <Response>(result);
                if (resp.status == "ok")
                {
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString() + $"Error code returned: {resp.error_code} with reason {resp.error_reason}");
            }
            return(false);
        }
Пример #2
0
        static void Main(string[] args)
        {
            #region Recipient Numbers
            List <string> num = new List <string>();
            num.Add("< Add number with country code>");
            num.Add("< Add number with country code>");

            #endregion
            #region Credentials
            string accountId = "< Account id from kirusa dashboard >";
            string authkey   = "< Auth key from kirusa dashboard >";
            #endregion

            #region Send SMS
            RequestSMS sms = new RequestSMS();
            sms.Id   = Guid.NewGuid().ToString();
            sms.To   = num;
            sms.Body = "< Compose message to send as sms>";
            KonnectAPI konnect = new KonnectAPI(authkey, accountId);
            konnect.SendSMS(sms).Wait();
            #endregion



            #region SEND VOICE
            RequestVoice voice = new RequestVoice();
            voice.id        = Guid.NewGuid().ToString();
            voice.recipient = num;
            voice.caller_id = "< OBD number from kirusa dashboard >";
            voice.media_url = "< link to recording eg https://myapp.com/recordings.mp3>";
            voice.direction = "outbound";


            KonnectAPI kon = new KonnectAPI(authkey, accountId);
            kon.SendVoice(voice).Wait();
            Console.WriteLine("Operation completed");
            Console.ReadLine();
            #endregion
        }