Example #1
0
        public async Task <bool> SendViberMessageAsync(string number, string text, string image_url, string btnUrl, string btnTitle)
        {
            var phoneNumber = int.Parse(PhoneNumberNormalize(number));

            using (var client = new HttpClient())
            {
                var smsUrl = "https://bsms.voicecom.bg/multichannel-api/sendmulti/";
                var uri    = new Uri(smsUrl);

                var smsRequest            = new SmsRequests(phoneNumber, text, "VIBER");
                var smsObject             = new SmsObject(smsRequest.RequestId, phoneNumber, text, image_url, btnUrl, btnTitle);
                var smsObjectAsJsonString = JsonConvert.SerializeObject(smsObject);
                var content  = new StringContent(smsObjectAsJsonString, Encoding.UTF8, "application/json");
                var response = await client.PostAsync(uri, content);

                //Save result from the sms send request
                string textResult = await response.Content.ReadAsStringAsync();

                var smsRequestResult = JsonConvert.DeserializeObject <dynamic>(textResult);
                dbContext.SmsRequests.Attach(smsRequest);
                smsRequest.ReturnCode    = smsRequestResult.return_code;
                smsRequest.ReturnMessage = smsRequestResult.return_message;
                await dbContext.SaveChangesAsync();

                return(smsRequestResult.return_code == 0 && smsRequestResult.return_message == "Message accepted");
            }
        }
Example #2
0
        public async Task <bool> SendSmsAsync(string number, string text, string encoding = "gsm-03-38")
        {
            var phoneNumber = long.Parse(PhoneNumberNormalize(number));

            using (var client = new HttpClient())
            {
                var smsUrl = "https://bsms.voicecom.bg/multichannel-api/sendmulti/";
                var uri    = new Uri(smsUrl);

                //Create SmsRequestObject
                var smsRequest = new SmsRequests(phoneNumber, text, "SMS");
                dbContext.SmsRequests.Add(smsRequest);
                await dbContext.SaveChangesAsync();


                var smsObject             = new SmsObject(smsRequest.RequestId, phoneNumber, text, encoding);
                var smsObjectAsJsonString = JsonConvert.SerializeObject(smsObject);
                var content  = new StringContent(smsObjectAsJsonString, Encoding.UTF8, "application/json");
                var response = await client.PostAsync(uri, content);


                //Save result from the sms send request
                string textResult = await response.Content.ReadAsStringAsync();

                var smsRequestResult = JsonConvert.DeserializeObject <dynamic>(textResult);
                dbContext.SmsRequests.Attach(smsRequest);
                smsRequest.ReturnCode    = smsRequestResult.return_code;
                smsRequest.ReturnMessage = smsRequestResult.return_message;
                smsRequest.SmsParts      = smsRequestResult.channels.sms.message_parts;
                await dbContext.SaveChangesAsync();

                return(smsRequestResult.return_code == 0);
            }
        }