<commit_before>﻿using HRMBot.Extensions;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using HRMBot.Repository;
using HRMBot.Services;

namespace HRMBot.Dialogs
{
    public partial class RootLuisDialog
    {

        [LuisIntent("RegisterUser")]
        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.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);
            }


        }

        private async Task PhoneNumberDialogResumeAfter(IDialogContext context, IAwaitable<int> result)
        {
            try
            {
                var mobileNumber = await result;
                // await context.PostAsync($"Your mobile number is {mobileNumber}");

                // generate otp and sent it to mobile
                var repo = new UserRegisterRepository();
                var otp = await repo.GenerateOtpCodeAsync(context.Activity.From.Id, mobileNumber.ToString("D11"), context.Activity.From.Name);
                // send varification message
                // await context.PostAsync($"Your generated otp code is {otp}");
                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.");
            }
            catch (OperationCanceledException)
            {

            }
            catch (Exception e)
            {
                await context.PostAsync(e.Message);
            }
            
        }

        private async Task ConfirmMobileNumberResumeAfter(IDialogContext context, IAwaitable<bool> result)
        {
            try
            {
                var success = await result;
                if (success)
                {
                    await context.PostAsync("You have successfully verified your mobile number with this account");
                }
                else
                {
                    await context.PostAsync("I'm sorry, I can not confirm your mobile number now. Try again later?");
                }

            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("I'm sorry, I can not confirm your mobile number now. Try again later.");
            }
            catch (OperationCanceledException)
            {

            }
            catch (Exception e)
            {
                await context.PostAsync(e.Message);
            }
            finally
            {
                context.Wait(this.MessageReceived);
            }
            
        }
    }
}<commit_msg>Possible fix of calling context.wait function<commit_after>﻿using HRMBot.Extensions;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using HRMBot.Repository;
using HRMBot.Services;

namespace HRMBot.Dialogs
{
    public partial class RootLuisDialog
    {

        [LuisIntent("RegisterUser")]
        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.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);
            }


        }

        private async Task PhoneNumberDialogResumeAfter(IDialogContext context, IAwaitable<int> result)
        {
            try
            {
                var mobileNumber = await result;
                // await context.PostAsync($"Your mobile number is {mobileNumber}");

                // generate otp and sent it to mobile
                var repo = new UserRegisterRepository();
                var otp = await repo.GenerateOtpCodeAsync(context.Activity.From.Id, mobileNumber.ToString("D11"), context.Activity.From.Name);
                // send varification message
                // await context.PostAsync($"Your generated otp code is {otp}");
                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 (Exception e)
            {
                await context.PostAsync(e.Message);
            }
            
        }

        private async Task ConfirmMobileNumberResumeAfter(IDialogContext context, IAwaitable<bool> result)
        {
            try
            {
                var success = await result;
                if (success)
                {
                    await context.PostAsync("You have successfully verified your mobile number with this account");
                }
                else
                {
                    await context.PostAsync("I'm sorry, I can not confirm your mobile number now. Try again later?");
                }
                context.Wait(MessageReceived);

            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("I'm sorry, I can not confirm your mobile number now. Try again later.");
                context.Wait(MessageReceived);
            }
            catch (OperationCanceledException)
            {
                await context.PostAsync("You have canceled the mobile verification process");
                context.Wait(MessageReceived);
            }
            catch (Exception e)
            {
                await context.PostAsync(e.Message);
                context.Wait(MessageReceived);
            }
            
        }
    }
}
{'fraction_non_alphanumeric': 0.07729703451628585, 'fraction_numerical': 0.0009722897423432182, 'mean_word_length': 1.5659494855004676, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6065569', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1840, 'n_words': 491}