Webmania.AI.Validation.DFe 1.0.0

dotnet add package Webmania.AI.Validation.DFe --version 1.0.0
                    
NuGet\Install-Package Webmania.AI.Validation.DFe -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Webmania.AI.Validation.DFe" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Webmania.AI.Validation.DFe" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Webmania.AI.Validation.DFe" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Webmania.AI.Validation.DFe --version 1.0.0
                    
#r "nuget: Webmania.AI.Validation.DFe, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Webmania.AI.Validation.DFe@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Webmania.AI.Validation.DFe&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Webmania.AI.Validation.DFe&version=1.0.0
                    
Install as a Cake Tool

Validação de Documentos Fiscais com IA - SDK para C#/.NET

NuGet License: MIT .NET

SDK oficial em C#/.NET para consumir a API de Validação de Documentos Fiscais com IA da WebmaniaBR. Valide NFe, NFCe, NFSe, CTe e MDFe através de imagens ou XML com tecnologia de inteligência artificial.

📋 Índice

🚀 Instalação

Via NuGet

# Package Manager
Install-Package Webmania.AI.Validation.DFe

# .NET CLI
dotnet add package Webmania.AI.Validation.DFe

# PackageReference
<PackageReference Include="Webmania.AI.Validation.DFe" Version="1.0.0" />

Via Docker

# Clone o repositório
git clone https://github.com/webmaniabr/IA-Validacao-DFe-C-Sharp.git
cd IA-Validacao-DFe-C-Sharp

# Build da imagem
docker build -t webmania/csharp-sdk .

# Executar
docker run --rm webmania/csharp-sdk

⚙️ Configuração Inicial

using Webmania.AI.Validation.DFe;

// Configuração básica
var client = new ValidationClient("SEU_TOKEN_API");

// Configuração com opções personalizadas
var client = new ValidationClient("SEU_TOKEN_API", new ValidationClientOptions
{
    Timeout = TimeSpan.FromSeconds(60)  // Timeout personalizado
});

📦 Métodos Disponíveis

Método Descrição
ValidateImageByUrlAsync Valida documentos fiscais através de URLs de imagens
ValidateImageByBase64Async Valida documentos fiscais através de imagens em Base64
ValidateImageUploadAsync Valida documentos fiscais através de upload de arquivos
ValidateXmlAsync Valida documentos fiscais através de XML
RegisterIntegrationAsync Registra integração com provedores externos
GetIntegrationAsync Consulta integração registrada
DeleteIntegrationAsync Remove integração registrada
GetValidationLogAsync Consulta status de validação por UUID

💡 Exemplos de Uso

Validação de Imagens

Por URL (Síncrono - Uma Imagem)
var resultado = await client.ValidateImageByUrlAsync(
    "nfce", 
    new[] { "https://exemplo.com/nota-fiscal.jpg" },
    new Dictionary<string, object?>
    {
        ["formato"] = "json",
        ["assincrono"] = false
    }
);
Por URL (Assíncrono - Múltiplas Imagens)
var resultado = await client.ValidateImageByUrlAsync(
    "nfe", 
    new[] { 
        "https://exemplo.com/nota1.jpg",
        "https://exemplo.com/nota2.jpg" 
    },
    new Dictionary<string, object?>
    {
        ["formato"] = "json",
        ["url_notificacao"] = "https://seu-webhook.com/callback"
    }
);
Por Base64
var base64Image = Convert.ToBase64String(File.ReadAllBytes("nota.jpg"));

var resultado = await client.ValidateImageByBase64Async(
    "nfce",
    new[] { base64Image },
    new Dictionary<string, object?>
    {
        ["assincrono"] = true,
        ["url_notificacao"] = "https://seu-webhook.com/callback"
    }
);
Por Upload de Arquivo
var resultado = await client.ValidateImageUploadAsync(
    "nfe",
    new[] { 
        "/caminho/para/nota1.pdf",
        "/caminho/para/nota2.jpg" 
    },
    new Dictionary<string, object?>
    {
        ["url_notificacao"] = "https://seu-webhook.com/callback"
    }
);

Validação de XML

// Via arquivo
var resultado = await client.ValidateXmlAsync(
    "/caminho/para/nfe.xml",
    new Dictionary<string, object?>
    {
        ["modelo"] = "nfe",
        ["formato"] = "json"
    }
);

// Via conteúdo XML direto
var xmlContent = @"<?xml version=""1.0""?><NFe>...</NFe>";
var resultado = await client.ValidateXmlAsync(
    xmlContent,
    new Dictionary<string, object?>
    {
        ["modelo"] = "nfe"
    }
);

Gerenciamento de Integrações

// Registrar integração
var cadastro = await client.RegisterIntegrationAsync(
    "sefaz",
    new Dictionary<string, object?>
    {
        ["api_key"] = "sua_chave",
        ["api_secret"] = "seu_segredo"
    }
);

// Consultar integração
var integracao = await client.GetIntegrationAsync("sefaz");

// Remover integração
var remocao = await client.DeleteIntegrationAsync("sefaz");

Consulta de Status

// Consultar status de validação assíncrona
var status = await client.GetValidationLogAsync("uuid-da-validacao");

🐳 Docker

Build e Execução

# Build da imagem
docker build -t webmania/csharp-sdk .

# Ver instruções de uso
docker run --rm webmania/csharp-sdk

# Executar com token
docker run --rm \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="help" \
  webmania/csharp-sdk

Exemplos com Docker

Validar Imagem por URL
# Validação síncrona (uma imagem)
docker run --rm \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="ValidateImageByUrlAsync" \
  -e MODELO="nfce" \
  -e IMAGENS_URLS="https://exemplo.com/nota.jpg" \
  -e ASSINCRONO="false" \
  webmania/csharp-sdk

# Validação assíncrona (múltiplas imagens)
docker run --rm \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="ValidateImageByUrlAsync" \
  -e MODELO="nfe" \
  -e IMAGENS_URLS="url1.jpg,url2.jpg,url3.jpg" \
  -e URL_NOTIFICACAO="https://webhook.site/..." \
  webmania/csharp-sdk
Validar com Base64
docker run --rm \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="ValidateImageByBase64Async" \
  -e MODELO="nfce" \
  -e IMAGENS_BASE64="base64_string_aqui" \
  -e ASSINCRONO="true" \
  -e URL_NOTIFICACAO="https://webhook.site/..." \
  webmania/csharp-sdk
Upload de Arquivos Locais
docker run --rm \
  -v /seu/caminho/local:/images:ro \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="ValidateImageUploadAsync" \
  -e MODELO="nfe" \
  -e FILE_PATHS="/images/nota1.jpg,/images/nota2.pdf" \
  -e URL_NOTIFICACAO="https://webhook.site/..." \
  webmania/csharp-sdk
Validar XML
# Com conteúdo XML direto
docker run --rm \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="ValidateXmlAsync" \
  -e XML_CONTENT="<NFe>...</NFe>" \
  -e MODELO_XML="nfe" \
  -e FORMATO="json" \
  webmania/csharp-sdk

# Com arquivo XML montado
docker run --rm \
  -v /caminho/para/xml:/data:ro \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="ValidateXmlAsync" \
  -e XML_FILE="/data/nota.xml" \
  -e MODELO_XML="nfe" \
  webmania/csharp-sdk
Consultar Status
docker run --rm \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="GetValidationLogAsync" \
  -e UUID="uuid-da-validacao" \
  webmania/csharp-sdk
Modo Debug
docker run --rm \
  -e WEBMANIA_TOKEN="seu-token" \
  -e METHOD="ValidateImageByUrlAsync" \
  -e MODELO="nfce" \
  -e IMAGENS_URLS="https://exemplo.com/nota.jpg" \
  -e DEBUG="true" \
  webmania/csharp-sdk

Variáveis de Ambiente Docker

Variável Descrição Obrigatório
WEBMANIA_TOKEN Token de autenticação da API
METHOD Método do SDK a ser executado
MODELO Modelo do documento (nfe, nfce, nfse) Depende do método
IMAGENS_URLS URLs das imagens (separadas por vírgula) Para ValidateImageByUrl
IMAGENS_BASE64 Imagens em Base64 (separadas por vírgula) Para ValidateImageByBase64
FILE_PATHS Caminhos dos arquivos (separados por vírgula) Para ValidateImageUpload
XML_CONTENT Conteúdo XML direto Para ValidateXml
XML_FILE Caminho do arquivo XML Para ValidateXml
UUID UUID da validação Para GetValidationLog
PROVIDER Nome do provedor de integração Para integrações
URL_NOTIFICACAO URL para callback de notificação Para async=true
ASSINCRONO Processamento assíncrono (true/false) Opcional
FORMATO Formato de resposta (json/texto) Opcional
DEBUG Modo debug (true/false) Opcional

📝 Regras de Negócio

Processamento Assíncrono

  • Uma imagem: Pode escolher entre síncrono ou assíncrono
  • Múltiplas imagens: Sempre processado de forma assíncrona
  • Formato texto: Sempre requer processamento assíncrono
  • Assíncrono = true: Requer url_notificacao

Limites

  • Máximo de 10 imagens por requisição
  • Tamanho máximo por arquivo: 10 MB
  • Formatos aceitos: JPEG, PNG, PDF
  • Modelos aceitos para imagens: nfe, nfce, nfse
  • Modelos aceitos para XML: nfe, nfce, cte, mdfe, nfse

🔧 Tratamento de Erros

try
{
    var resultado = await client.ValidateImageByUrlAsync(
        "nfce", 
        new[] { "https://exemplo.com/nota.jpg" }
    );
}
catch (ApiException ex)
{
    Console.WriteLine($"Erro API: {ex.Message}");
    Console.WriteLine($"Status: {ex.StatusCode}");
    Console.WriteLine($"Resposta: {ex.ResponseBody}");
}
catch (ArgumentException ex)
{
    Console.WriteLine($"Erro de validação: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"Erro geral: {ex.Message}");
}

✅ Requisitos

  • .NET 6.0 ou superior
  • Docker (opcional, para uso containerizado)
  • Token de API válido da Webmania

📞 Suporte

📄 Licença

Este projeto está licenciado sob a licença MIT - veja o arquivo LICENSE para detalhes.


WebmaniaBR © 2025 - Todos os direitos reservados

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 206 10/6/2025