private async void ButtonLogin_OnClick(object sender, RoutedEventArgs e) { Apis apis = new Apis(); string account = TextBoxAccount.Text; string pass = Password.Password; ButtonLogin.Content = "登录中"; ButtonLogin.IsEnabled = false; ApiRespone <QueryDocLoginModel> model = null; await Task.Run(delegate { model = apis.QueryDocLogin(account, pass).Result; }); if (model != null && model.Code == "200") { Configs.QueryDocLoginModel = model; this.Dispatcher.Invoke(new Action(delegate { new MainWindow().Show(); // 显示主窗口; Close(); })); } else { this.Dispatcher.Invoke(new Action(delegate { ButtonLogin.Content = "登录"; ButtonLogin.IsEnabled = true; })); MessageBox.Show("登录失败"); } }
public override async Task Execute(Message message, TelegramBotClient client) { try { await client.SendChatActionAsync(message.Chat.Id, Telegram.Bot.Types.Enums.ChatAction.Typing); RestApiClient.Сonfigure(AppSettings.VenusAiUri); ApiRequest inputMessage = new ApiRequest() { Id = message.Chat.Id, Language = "rus", RequestType = "text", TextData = message.Text }; var jsonRequest = JsonConverter.ToJson(inputMessage); var jsonRespone = RestApiClient.Post(jsonRequest); ApiRespone outputMessage = JsonConverter.FromJson <ApiRespone>(jsonRespone); var keyboard = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup { Keyboard = new[] { new[] // row 1 { new Telegram.Bot.Types.KeyboardButton("📝 исправить ответ 📝") }, }, ResizeKeyboard = true }; await client.SendTextMessageAsync(outputMessage.Id, outputMessage.OuputText, replyMarkup : keyboard); /* * Replic inputR = new Replic() * { * Id = message.Chat.Id, * Text = message.Text, * Time = message.Date * }; * Replic outputR = new Replic() * { * Id = 0, * Text = outputMessage.OuputText, * Time = message.Date * }; * string[] lines = new string[] * { * JsonConvert.SerializeObject(inputR), * JsonConvert.SerializeObject(outputR) * }; * await System.IO.File.AppendAllLinesAsync($"{Environment.CurrentDirectory}\\{message.Chat.Id}.txt", lines); */ } catch (Exception ex) { Utils.Log.LogError(message.Chat.Id, ex.Message); await client.SendTextMessageAsync(message.Chat.Id, $"Произошла ошибка: `{ex.Message}`\nОбратитесь к @gosha20777", Telegram.Bot.Types.Enums.ParseMode.Markdown); } }
public async Task <IActionResult> PostAsync([FromBody] ApiRequest apiRequest) { try { var time = DateTime.Now; //ApiRequest apiRequest = JsonConvert.DeserializeObject<ApiRequest>(requestStr); //convert speech to text if (apiRequest.GetRequestType() == Enums.RequestType.Voice) { Log.LogInformation(apiRequest.Id.Value, 0, this.GetType().ToString(), "processing voice request"); _speechToTextService.Initialize(apiRequest.GetLanguage()); var textServiceRespone = await _speechToTextService.Invork(new VoiceRequest() { Id = apiRequest.Id, VoiceData = apiRequest.VoiceData }); //recognize text and make text answer _textProcessingService.Initialize(apiRequest.GetLanguage()); var textProcessingRespone = await _textProcessingService.Invork(new TextRequest() { Id = textServiceRespone.Id, TextData = textServiceRespone.TextData }); //convert text to speech _textToSpeechService.Initialize(apiRequest.GetLanguage()); var speechServiceRespone = await _textToSpeechService.Invork(new TextRequest() { Id = textProcessingRespone.Id, TextData = textProcessingRespone.TextData }); //make a respone ApiRespone apiRespone = new ApiRespone { Id = speechServiceRespone.Id, VoiceData = speechServiceRespone.VoiceData, InputText = textServiceRespone.TextData, OutputText = textProcessingRespone.TextData, IntentName = textProcessingRespone.IntentName, Entities = textProcessingRespone.Entities, WayPoint = textProcessingRespone.WayPoint }; textServiceRespone = null; textProcessingRespone = null; speechServiceRespone = null; Log.LogInformation(apiRequest.Id.Value, 0, this.GetType().ToString(), $"voice request processed in {(DateTime.Now - time).TotalMilliseconds} ms"); Console.WriteLine("WayPoint:" + apiRespone.WayPoint); return(Ok(apiRespone)); } else { Log.LogInformation(apiRequest.Id.Value, 0, this.GetType().ToString(), "processing text request"); //recognize text and make text answer _textProcessingService.Initialize(apiRequest.GetLanguage()); var textProcessingRespone = await _textProcessingService.Invork(new TextRequest() { Id = apiRequest.Id, TextData = apiRequest.TextData }); //make a respone ApiRespone apiRespone = new ApiRespone { Id = apiRequest.Id.Value, VoiceData = null, InputText = apiRequest.TextData, OutputText = textProcessingRespone.TextData, IntentName = textProcessingRespone.IntentName, Entities = textProcessingRespone.Entities, WayPoint = textProcessingRespone.WayPoint }; textProcessingRespone = null; Log.LogInformation(apiRequest.Id.Value, 0, this.GetType().ToString(), "text request processed"); return(Ok(apiRespone)); } } catch (Exception ex) { Log.LogError(apiRequest.Id.Value, 0, this.GetType().ToString(), ex.Message); Console.WriteLine(ex); string outputFailText = "Я не расслышала, что вы сказали. Пожалуйста, повторите ваш запрос"; if (apiRequest.GetLanguage() == Enums.Language.English) { outputFailText = "I did not hear what you said. Please repeat your request"; } _textToSpeechService.Initialize(apiRequest.GetLanguage()); var speechServiceRespone = await _textToSpeechService.Invork(new TextRequest() { Id = apiRequest.Id, TextData = outputFailText }); ApiRespone apiRespone = new ApiRespone { Id = speechServiceRespone.Id, VoiceData = speechServiceRespone.VoiceData, InputText = "", OutputText = outputFailText, IntentName = "none", Entities = null, WayPoint = null }; speechServiceRespone = null; return(Ok(apiRespone)); } }