Evgen
✅ Telegram Bot Mindee integration
using Mindee;
using Mindee.Http;
using Mindee.Input;
using Mindee.Parsing;
using System.IO;
using System.Threading.Tasks;
using Mindee.Product.InternationalId;
using TelegramBotTZ.Interfaces;
namespace TelegramBotTZ.Services
{
public class MindeeService : IMindeeService
{
private readonly string _apiKey;
public MindeeService(string apiKey)
{
_apiKey = apiKey;
}
public async Task<string> ProcessPhotoAsync(Stream photoStream, string filePath)
{
var mindeeClient = new MindeeClient(_apiKey);
string tempFilePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.jpg");
using (var fileStream = new FileStream(tempFilePath, FileMode.Create, FileAccess.Write))
{
await photoStream.CopyToAsync(fileStream);
}
var inputSource = new LocalInputSource(tempFilePath);
var response = await mindeeClient
.EnqueueAndParseAsync<InternationalIdV2>(inputSource);
File.Delete(tempFilePath);
return response.Document.ToString();
}
}
}
15 replies