Пример #1
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var confirmCode = await result;

            var repo    = new UserRegisterRepository();
            var success = await repo.VarifyOtpAsync(context.Activity.ChannelId, context.Activity.From.Id, confirmCode.Text);

            if (success)
            {
                context.Done(true);
            }
            else
            {
                --_attempts;
                if (confirmCode.Text.ToLower().Equals("cancel") || confirmCode.Text.ToLower().Equals("exit"))
                {
                    context.Fail(new OperationCanceledException(""));
                }
                else if (_attempts > 0)
                {
                    await context.PostAsync("Sorry I can not verify your OTP code. What is the OTP code you received in SMS?");

                    context.Wait(this.MessageReceivedAsync);
                }
                else
                {
                    context.Fail(new TooManyAttemptsException("Message was not a valid OTP."));
                }
            }
        }
Пример #2
0
        private async Task PhoneNumberDialogResumeAfter(IDialogContext context, IAwaitable <int> result)
        {
            try
            {
                var mobileNumber = await result;

                // generate otp and sent it to mobile
                var repo = new UserRegisterRepository();
                var otp  = await repo.GenerateOtpCodeAsync(context.Activity.ChannelId, context.Activity.From.Id,
                                                           mobileNumber.ToString("D11"), context.Activity.From.Name);

                // send varification message
                string           message  = $"Your verification code for the HRMBot is {otp}";
                IMessageProvider provider = new Sms();
                var success = await provider.SendAsync(mobileNumber.ToString("D11"), message);

                if (!success)
                {
                    await context.PostAsync("Sorry we are having trouble sending OTP. Please try again later");

                    context.Wait(MessageReceived);
                }
                else
                {
                    // start varify dialog
                    context.Call(new ConfirmMobileNumberDialog(), ConfirmMobileNumberResumeAfter);
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("I'm sorry, I'm having issues understanding you. Try again later.");

                context.Wait(MessageReceived);
            }
            catch (OperationCanceledException)
            {
                await context.PostAsync("You have canceled the mobile verification process");

                context.Wait(MessageReceived);
            }
            catch (ObjectNotFoundException)
            {
                await context.PostAsync("Your mobile number is not in the database. Please contact admin");

                context.Wait(MessageReceived);
            }
            catch (PlatformNotSupportedException)
            {
                await context.PostAsync("Sorry, This chat channel is not supported for varification yet.");

                context.Wait(MessageReceived);
            }
            catch (Exception e)
            {
                await context.PostAsync(e.Message);
            }
        }
Пример #3
0
        public async Task RegisterUser(IDialogContext context, LuisResult result)
        {
            //await context.PostAsync("Hello");
            //context.Wait(this.MessageReceived

            var repo            = new UserRegisterRepository();
            var registerdMobile = await repo.IsAlreadyVerifiedAsync(context.Activity.ChannelId, context.Activity.From.Id);

            if (registerdMobile != null)
            {
                await context.PostAsync($"You have already verified your mobile number {registerdMobile}");

                context.Wait(this.MessageReceived);
            }
            else
            {
                context.Call(new MobileNumberDialog(), PhoneNumberDialogResumeAfter);
            }
        }