Info VerifyGoogle Docs

Google Docs Add-on

Aggiungi il pulsante "Certifica con ProofPress" direttamente in Google Docs tramite un Apps Script. Nessuna installazione esterna, nessun plugin da marketplace.

Zero dipendenze esterne Certifica documento intero o selezione API Key configurabile in-app
Prerequisiti
  • Un account Google (Gmail o Google Workspace)
  • Una API Key ProofPress Verify™ — ottienila qui
  • Nessuna installazione aggiuntiva richiesta

Installazione in 6 passi

01
Apri Google Apps Script

Nel documento Google Docs che vuoi integrare, vai su Estensioni → Apps Script. Si aprirà l'editor di script.

02
Incolla il codice

Cancella il contenuto predefinito (function myFunction() {}) e incolla il codice Apps Script qui sopra.

⚠️ Sostituisci ppv_YOUR_API_KEY con la tua API Key reale.
03
Salva il progetto

Clicca sull'icona di salvataggio (o Ctrl+S). Dai un nome al progetto, ad esempio "ProofPress Verify Add-on".

04
Autorizza le permissions

Clicca su Esegui → Esegui funzione → onOpen. Google chiederà di autorizzare l'accesso al documento e alle richieste HTTP esterne. Clicca Consenti.

⚠️ Vedrai un avviso 'app non verificata' — è normale per script personali. Clicca Avanzate → Vai a ProofPress Verify Add-on.
05
Ricarica il documento

Torna al documento Google Docs e ricarica la pagina. Vedrai il menu "🛡️ ProofPress Verify™" nella barra dei menu.

06
Configura l'API Key

Clicca su ProofPress Verify™ → Impostazioni API Key. Inserisci la tua API Key (ppv_...) e salva. Puoi ottenere la tua API Key dalla dashboard.

Codice Apps Script completo

Code.gs

Copia e incolla questo codice nell'editor Apps Script. Sostituisci ppv_YOUR_API_KEY con la tua chiave reale.

google-apps-script
/**
 * ProofPress Verify™ — Google Docs Add-on
 * Versione: 1.0.0
 * 
 * Installa questo script in Google Apps Script per aggiungere
 * il menu "ProofPress Verify™" direttamente in Google Docs.
 * 
 * Istruzioni: https://proofpressverify.com/docs/google-docs-addon
 */

// ─── CONFIGURAZIONE ───────────────────────────────────────────────────────────
const PROOFPRESS_API_URL = "https://proofpressverify.com/api/v1/verify";
const PROOFPRESS_API_KEY = "ppv_YOUR_API_KEY"; // ← Sostituisci con la tua API Key
const PRODUCT_TYPE = "info_verify"; // info_verify | news_verify | email_verify
// ─────────────────────────────────────────────────────────────────────────────

/**
 * Aggiunge il menu ProofPress Verify™ alla barra dei menu di Google Docs.
 * Viene eseguita automaticamente all'apertura del documento.
 */
function onOpen() {
  DocumentApp.getUi()
    .createMenu("🛡️ ProofPress Verify™")
    .addItem("Certifica questo documento", "certifyDocument")
    .addSeparator()
    .addItem("Certifica selezione", "certifySelection")
    .addSeparator()
    .addItem("Impostazioni API Key", "showSettings")
    .addToUi();
}

/**
 * Certifica l'intero documento corrente.
 */
function certifyDocument() {
  const doc = DocumentApp.getActiveDocument();
  const title = doc.getName();
  const content = doc.getBody().getText();

  if (!content || content.trim().length < 50) {
    DocumentApp.getUi().alert(
      "Documento troppo breve",
      "Il documento deve contenere almeno 50 caratteri per essere certificato.",
      DocumentApp.getUi().ButtonSet.OK
    );
    return;
  }

  showProgressDialog("Certificazione in corso...");
  
  try {
    const result = callProofPressAPI(title, content);
    showResultDialog(result, title);
  } catch (e) {
    DocumentApp.getUi().alert(
      "Errore di certificazione",
      "Si è verificato un errore: " + e.message,
      DocumentApp.getUi().ButtonSet.OK
    );
  }
}

/**
 * Certifica solo il testo selezionato nel documento.
 */
function certifySelection() {
  const doc = DocumentApp.getActiveDocument();
  const selection = doc.getSelection();
  
  if (!selection) {
    DocumentApp.getUi().alert(
      "Nessuna selezione",
      "Seleziona il testo che vuoi certificare, poi riprova.",
      DocumentApp.getUi().ButtonSet.OK
    );
    return;
  }

  const elements = selection.getRangeElements();
  let selectedText = "";
  for (const element of elements) {
    if (element.getElement().editAsText) {
      const text = element.getElement().asText();
      if (element.isPartial()) {
        selectedText += text.getText().substring(element.getStartOffset(), element.getEndOffsetInclusive() + 1);
      } else {
        selectedText += text.getText();
      }
    }
  }

  if (selectedText.trim().length < 50) {
    DocumentApp.getUi().alert(
      "Selezione troppo breve",
      "Seleziona almeno 50 caratteri di testo.",
      DocumentApp.getUi().ButtonSet.OK
    );
    return;
  }

  const title = doc.getName() + " [selezione]";
  showProgressDialog("Certificazione selezione...");
  
  try {
    const result = callProofPressAPI(title, selectedText);
    showResultDialog(result, title);
  } catch (e) {
    DocumentApp.getUi().alert(
      "Errore di certificazione",
      "Si è verificato un errore: " + e.message,
      DocumentApp.getUi().ButtonSet.OK
    );
  }
}

/**
 * Chiama l'API ProofPress Verify™ e restituisce il risultato.
 */
function callProofPressAPI(title, content) {
  const apiKey = PropertiesService.getUserProperties().getProperty("PROOFPRESS_API_KEY") || PROOFPRESS_API_KEY;
  
  const payload = JSON.stringify({
    product_type: PRODUCT_TYPE,
    title: title,
    content: content,
  });

  const options = {
    method: "post",
    contentType: "application/json",
    headers: {
      Authorization: "Bearer " + apiKey,
    },
    payload: payload,
    muteHttpExceptions: true,
  };

  const response = UrlFetchApp.fetch(PROOFPRESS_API_URL, options);
  const responseCode = response.getResponseCode();
  const responseText = response.getContentText();

  if (responseCode !== 200) {
    const error = JSON.parse(responseText);
    throw new Error(error.error || "Errore API (HTTP " + responseCode + ")");
  }

  return JSON.parse(responseText);
}

/**
 * Mostra un dialog di progresso (non-blocking in Apps Script).
 */
function showProgressDialog(message) {
  const html = HtmlService.createHtmlOutput(
    '<p style="font-family:sans-serif;padding:16px;">' + message + '</p>'
  ).setWidth(300).setHeight(80);
  DocumentApp.getUi().showModelessDialog(html, "ProofPress Verify™");
}

/**
 * Mostra il dialog con il risultato della certificazione.
 */
function showResultDialog(result, title) {
  const grade = result.trust_grade || result.trustGrade || "–";
  const score = result.trust_score || result.trustScore || 0;
  const verifyCode = result.verify_code || result.verifyCode || "–";
  const hash = result.hash || "–";
  const certUrl = result.certificate_url || result.certificateUrl || ("#");
  const badgeUrl = result.badge_url || result.badgeUrl || "";

  const gradeColor = grade === "A" ? "#22c55e" : grade === "B" ? "#84cc16" : grade === "C" ? "#eab308" : "#ef4444";

  const htmlContent = `
    <style>
      body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; margin: 0; padding: 16px; background: #fff; }
      .grade { font-size: 48px; font-weight: 900; color: ${gradeColor}; text-align: center; }
      .score { text-align: center; color: #666; font-size: 14px; margin-top: -8px; }
      .badge { display: inline-block; background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; border-radius: 4px; padding: 2px 8px; font-size: 12px; }
      table { width: 100%; border-collapse: collapse; margin-top: 12px; }
      td { padding: 6px 4px; border-bottom: 1px solid #f0f0f0; font-size: 12px; }
      td:first-child { color: #666; width: 40%; }
      td:last-child { font-family: monospace; word-break: break-all; }
      .btn { display: block; width: 100%; padding: 10px; background: #f97316; color: white; border: none; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer; text-align: center; text-decoration: none; margin-top: 12px; }
      .btn:hover { background: #ea580c; }
    </style>
    <div class="grade">${grade}</div>
    <div class="score">Score: ${score}/100 &nbsp; <span class="badge">✓ Certificato</span></div>
    <table>
      <tr><td>Documento</td><td>${title.substring(0, 40)}${title.length > 40 ? "..." : ""}</td></tr>
      <tr><td>Codice</td><td>${verifyCode}</td></tr>
      <tr><td>Hash SHA-256</td><td>${hash.substring(0, 20)}...</td></tr>
    </table>
    <a href="${certUrl}" target="_blank" class="btn">Visualizza certificato →</a>
  `;

  const html = HtmlService.createHtmlOutput(htmlContent).setWidth(360).setHeight(320);
  DocumentApp.getUi().showModelessDialog(html, "✓ ProofPress Verify™ — Certificato");
}

/**
 * Dialog per configurare la API Key.
 */
function showSettings() {
  const currentKey = PropertiesService.getUserProperties().getProperty("PROOFPRESS_API_KEY") || "";
  
  const htmlContent = `
    <style>
      body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; padding: 16px; }
      label { display: block; font-size: 13px; color: #333; margin-bottom: 6px; font-weight: 600; }
      input { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-family: monospace; font-size: 12px; box-sizing: border-box; }
      .btn { padding: 8px 16px; background: #f97316; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 600; margin-top: 12px; }
      .hint { font-size: 11px; color: #888; margin-top: 6px; }
    </style>
    <label>API Key ProofPress Verify™</label>
    <input id="apiKey" type="text" value="${currentKey}" placeholder="ppv_..." />
    <p class="hint">Ottieni la tua API Key su <a href="https://proofpressverify.com/dashboard/api-keys" target="_blank">proofpressverify.com/dashboard/api-keys</a></p>
    <button class="btn" onclick="saveKey()">Salva</button>
    <script>
      function saveKey() {
        const key = document.getElementById("apiKey").value.trim();
        google.script.run.withSuccessHandler(function() {
          google.script.host.close();
        }).saveApiKey(key);
      }
    </script>
  `;

  const html = HtmlService.createHtmlOutput(htmlContent).setWidth(400).setHeight(200);
  DocumentApp.getUi().showModalDialog(html, "Impostazioni ProofPress Verify™");
}

/**
 * Salva la API Key nelle proprietà utente (chiamata dal dialog settings).
 */
function saveApiKey(key) {
  PropertiesService.getUserProperties().setProperty("PROOFPRESS_API_KEY", key);
}

Come usarlo

Certifica documento

Clicca ProofPress Verify™ → Certifica questo documento. L'intero testo del documento viene inviato all'API e certificato su IPFS.

Certifica selezione

Seleziona una porzione di testo, poi clicca ProofPress Verify™ → Certifica selezione. Utile per certificare singoli paragrafi o sezioni.

Visualizza risultato

Un dialog mostra il Certification Grade (A/B/C/D), il codice PP- e il link al certificato pubblico verificabile da chiunque.

Personalizzazione

Puoi modificare il PRODUCT_TYPE nella configurazione per usare un prodotto diverso:

javascript
// Riga 14 del codice — cambia il product_type in base al tuo caso d'uso:
const PRODUCT_TYPE = "info_verify";   // Documenti aziendali (default)
const PRODUCT_TYPE = "news_verify";   // Articoli e notizie
const PRODUCT_TYPE = "email_verify";  // Email e comunicazioni

Risoluzione problemi

Il menu non appare dopo il ricaricamento
Assicurati di aver eseguito la funzione onOpen almeno una volta dall'editor Apps Script. Vai su Esegui → Esegui funzione → onOpen.
Errore 401 Unauthorized
La API Key non è valida o è scaduta. Vai su ProofPress Verify™ → Impostazioni API Key e inserisci una chiave valida dalla dashboard.
Errore 403 Forbidden
Il tuo piano non include Info Verify. Vai su proofpressverify.com/pricing per attivare il servizio.
Il dialog non si apre
Controlla che il browser non stia bloccando i popup. Aggiungi docs.google.com alle eccezioni del blocco popup.

Pronto a integrare?

Ottieni la tua API Key dalla dashboard e inizia a certificare i tuoi documenti Google Docs in pochi minuti.