Blog

Filter posts by the Tags of Blog section!

Sinch Wrapper for sending SMS Tuesday, 14 August 2018

I was recently looking for a verification system and came across with Sinch. It's been satisfactory until now. After installing the library by nuget I created a wrapper for SMS, hope it be useful!

 

 public class SinchWrapper
    {
        public static async Task<SinchWrapperResult> SendSms(string countryCode, string number, string message)
        {
            try
            {
                number = number.Replace(" ", "").Replace("-", "");
                if (string.IsNullOrEmpty(message))
                    return new SinchWrapperResult { Faild = true, Message = "Message was empty" };
                var destinationNumber = countryCode + number;
                var smsApi = SinchFactory.CreateApiFactory("Your Key", "YourSecret).CreateSmsApi()");
                var sendSmsResponse = await smsApi.Sms(destinationNumber, message).Send();
                return new SinchWrapperResult { Faild = false, Message = message };
            }
            catch (Exception ex)
            {
                return new SinchWrapperResult { Faild = true, Message = ex.Message };
            }
        }
        public static async Task<SinchWrapperResult> SendVerificationSms(string countryCode, string number, string code)
        {
            var result = await SendSms(countryCode, number, $"your verification code is: {code}");
            result.Data = code;
            return result;
        }
    }
    public class SinchWrapperResult
    {
        public bool Faild { get; set; }
        public string Message { get; set; }
        public string Data { get; set; }
    }

 

Rather than above which is available almost in every SMS panels, there is another cool option that verifies by a Missed Call! Instead of entering the receiving and entering the verification code via SMS, you enter the number that you been called with! For using that feature you simply change the configuration:

 


            var api = SinchFactory.CreateApiFactory("key", "secret").CreateVerificationApi();
            var initiate = await api.Verification(number).WithReference("A Reference number").WithCustom("A Custom number").Initiate(VerificationMethod.FlashCall);
            var report = await api.Verification(number).WithCli(initiate.FlashCall.CliFilter).Report(VerificationMethod.FlashCall);
   

 

comments powered by Disqus