protected override async Task CustomHandle(Message message) { var textForDocument = string.Empty; if (message.Text != null) { textForDocument = message.Text; } else if (message.Photo != null) { foreach (var photo in message.Photo) { MemoryStream photoStream = new MemoryStream(); var file = await BotClient.GetInfoAndDownloadFileAsync(photo.FileId, photoStream); textForDocument += await _imagesRecognitionService.RecognizeFromFile(photoStream.ToArray()); } } else if (message.Voice != null) { MemoryStream voiceStream = new MemoryStream(); var file = await BotClient.GetInfoAndDownloadFileAsync(message.Voice.FileId, voiceStream); textForDocument = await _voiceRecognitionService.RecognizeFromFile(voiceStream.ToArray()); } var documentStream = _documentGenerator.GenerateFromText(textForDocument); var bytes = documentStream.ToArray(); var document = new InputOnlineFile(new MemoryStream(bytes), "Your document" + _documentGenerator.Extension); await BotClient.SendTextMessageAsync(message.Chat.Id, "Your file:"); await BotClient.SendDocumentAsync(message.Chat.Id, document); }
protected override async Task CustomHandle(Message message) { var recognizedText = string.Empty; foreach (var photo in message.Photo) { MemoryStream stream = new MemoryStream(); var file = await BotClient.GetInfoAndDownloadFileAsync(photo.FileId, stream); recognizedText += await _imagesRecognitionService.RecognizeFromFile(stream.ToArray()); } if (!string.IsNullOrEmpty(recognizedText)) { await BotClient.SendTextMessageAsync(message.Chat.Id, "Recognized text: \n" + recognizedText); } else { await BotClient.SendTextMessageAsync(message.Chat.Id, "Text on an image was not recognized"); } }