Пример #1
0
        public static void SendTwoWaySms(string[] args)
        {
            CheckArgument.ArrayLengthAtLeast(args, 1, "args");

            string phoneNumber = args[0];
            string message = string.Empty;

            if (args.Length >= 2)
            {
                message = args[1];
            }

            try
            {
                VerifyService verify = new VerifyService(GetConfiguration());
                VerifyResponse verifyResponse = null;
                verifyResponse = verify.SendTwoWaySms(phoneNumber, message);
                Console.WriteLine("Sent two way sms");
            }
            catch (Exception x)
            {
                Console.WriteLine("Error: " + x.ToString());
            }
        }
Пример #2
0
        private static void PerformVerify(string[] args, VerificationMethod method)
        {
            CheckArgument.ArrayLengthAtLeast(args, 1, "args");

            string phoneNumber = args[0];

            string code = null;
            if (args.Length >= 2)
            {
                code = args[1];
            }

            string language = "en";
            if (args.Length >= 3)
            {
                language = args[2];
            }

            VerifyService verify = new VerifyService(GetConfiguration());
            VerifyResponse verifyResponse = null;

            if (method == VerificationMethod.Sms)
            {
                verifyResponse = verify.SendSms(phoneNumber, code, string.Empty, language);
            }
            else if (method == VerificationMethod.Call)
            {
                verifyResponse = verify.InitiateCall(phoneNumber, code, language);
            }
            else if (method == VerificationMethod.Push)
            {
                verifyResponse = verify.InitiatePush(phoneNumber, code);
            }
            else if (method == VerificationMethod.TwoWaySms)
            {
                verifyResponse = verify.SendTwoWaySms(phoneNumber);
            }
            else
            {
                throw new NotImplementedException("Invalid verification method");
            }

            foreach (TeleSignApiError e in verifyResponse.Errors)
            {
                Console.WriteLine(
                            "ERROR: [{0}] - {1}", 
                            e.Code, 
                            e.Description);
            }

            while (true)
            {
                Console.Write("Enter the code sent to phone [Just <enter> checks status. 'quit' to exit]: ");
                string enteredCode = Console.ReadLine();

                if (enteredCode.Equals("quit", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }

                Console.WriteLine(string.IsNullOrEmpty(enteredCode) ? "Checking status..." : "Validating code...");

                VerifyResponse statusResponse = verify.ValidateCode(
                            verifyResponse.ReferenceId,
                            enteredCode);

                Console.WriteLine(
                            "Transaction Status: {0} -- {1}\r\nCode State: {2}",
                            statusResponse.Status.Code,
                            statusResponse.Status.Description,
                            (statusResponse.VerifyInfo != null) 
                                        ? statusResponse.VerifyInfo.CodeState.ToString()
                                        : "Not Sent");

                if ((statusResponse.VerifyInfo != null) && (statusResponse.VerifyInfo.CodeState == CodeState.Valid))
                {
                    Console.WriteLine("Code was valid. Exiting.");
                    break;
                }
            }
        }
Пример #3
0
        public static void SendSms(string[] args)
        {
            CheckArgument.ArrayLengthAtLeast(args, 1, "args");

            string phoneNumber = args[0];

            string code = null;
            if (args.Length >= 2)
            {
                code = args[1];
            }

            string language = "en";
            if (args.Length >= 3)
            {
                language = args[2];
            }

            try
            {
                VerifyService verify = new VerifyService(GetConfiguration());
                VerifyResponse verifyResponse = null;
                verifyResponse = verify.SendSms(phoneNumber, code, string.Empty, language);
                Console.WriteLine("Sent sms");
            }
            catch (Exception x)
            {
                Console.WriteLine("Error: " + x.ToString());
            }
        }