private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; await activity.StartTypingAndWaitAsync(); var registrationComplete = await EnsureUserRegistrationCompleted(context); if (registrationComplete) { await context.PostAsync($"Olá, {context.GetUserName()}! Alguma novidade?"); context.Done(RootDialog.Ok); } else { var id = context.GetUserId(); if (id.HasValue) { await context.PostAsync($"Olá, {context.GetUserName()}!"); await RegisterUserWalletAsync(context, activity); } else { await WelcomeNewMemberAsync(context, activity); } } }
private async Task CreateUserWalletAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; await activity.StartTypingAndWaitAsync(); var recognizes = new PromptRecognizer().RecognizeDouble(activity); var recognize = recognizes.FirstOrDefault(); if (recognize != null) { var userId = context.GetUserId(); var walletId = await FinancialApi.Dispatcher.CreateWalletAsync(userId.Value, recognize.Entity); context.SetUserWalletId(walletId); await context.PostAsync("Bacana! Temos tudo configurado agora! Podemos começar a registrar suas transações!"); context.Done(RootDialog.Ok); } else { await context.PostAsync("Por favor, escreva um valor válido!"); context.Wait(CreateUserWalletAsync); } }
private async Task <bool> EnsureUserRegistrationCompleted(IDialogContext context) { var id = context.GetUserId(); if (id.HasValue) { var user = await FinancialApi.Dispatcher.GetUserAsync(id.Value); if (user != null) { context.SetUserName(user.Name); var walletId = context.GetUserWalletId(); if (walletId.HasValue) { var wallet = await FinancialApi.Dispatcher.GetWalletAsync(walletId.Value); if (wallet != null) { return(true); } context.RemoveUserWalletId(); } var userWallets = await FinancialApi.Dispatcher.GetUserWalletsAsync(user.Id); var userWallet = userWallets.FirstOrDefault(); if (userWallet != null) { context.SetUserWalletId(userWallet.Id); return(true); } } } context.RemoveUserId(); context.RemoveUserName(); context.RemoveUserWalletId(); return(false); }