Docs / Connect it
Connect Google Sheets
Check claims listed in a spreadsheet and write the verdict next to each one.
Put one claim per row in column A. Run the menu command. The verdict, confidence and a one-line summary appear in columns B to D.
- Open the script editorIn your sheet, click Extensions, then Apps Script.
- Paste the scriptDelete anything in the editor, paste the code below, and save.
- Add the key safelyIn Apps Script click Project Settings, scroll to Script properties, add a property named
PIJ_KEYwith your key. This keeps it out of the sheet. - Run itReload the sheet. A new menu News Intelligence appears. Choose Check selected rows. The first time, Google asks you to allow it.
function onOpen() {
SpreadsheetApp.getUi().createMenu('News Intelligence').addItem('Check selected rows', 'checkSelected').addToUi();
}
function checkSelected() {
var key = PropertiesService.getScriptProperties().getProperty('PIJ_KEY');
var sh = SpreadsheetApp.getActiveSheet(), rng = sh.getActiveRange();
var H = { Authorization: 'Bearer ' + key };
for (var r = rng.getRow(); r < rng.getRow() + rng.getNumRows(); r++) {
var text = String(sh.getRange(r, 1).getValue() || '').trim();
if (!text) continue;
sh.getRange(r, 2).setValue('checking...');
var start = JSON.parse(UrlFetchApp.fetch('https://api.chatniai.com/v1/check', {
method: 'post', contentType: 'application/json', headers: H, muteHttpExceptions: true,
payload: JSON.stringify({ text: text, async: true }) }).getContentText());
if (!start.job_id) { sh.getRange(r, 2).setValue(start.message || 'error'); continue; }
for (var i = 0; i < 24; i++) { // up to about 4 minutes per row
Utilities.sleep(10000);
var j = JSON.parse(UrlFetchApp.fetch('https://api.chatniai.com/v1/job/' + start.job_id, { headers: H, muteHttpExceptions: true }).getContentText());
if (j.state === 'done') {
var c = (j.result.claims || [])[0] || {};
sh.getRange(r, 2, 1, 3).setValues([[c.verdict || 'HELD for editor', c.confidence || '', String(c.summary || '').slice(0, 300)]]);
break;
}
if (j.state === 'failed') { sh.getRange(r, 2).setValue('failed, try again'); break; }
}
}
}
LimitGoogle stops a script after six minutes. Select two or three rows at a time, not a whole column.