Попытка разработать инструмент для увеличения team.accesslog
провала в электронной таблице Google.Изменил публично представленный скрипт GitHub для ссылки на файл на приведенный ниже.
Но столкнулся с ошибкой, что раздел не определил функцию должным образом,
разделчто показало ошибку:
SlackTeamAccess.prototype.run = function () {
var teamaccessResp = this.requestSlackAPI('username.list');
for (var _i = 0, _a = teamaccessResp.pages; _i < _a.length; _i++) {
var page = _a[_i];
this.importTeamAccessDelta(page);
}
};
но не знаю, как это исправить ...
Может кто-нибудь сказать мне решение?Спасибо.
// Configuration: Obtain Slack web API token at https://api.slack.com/web
var API_TOKEN = PropertiesService.getScriptProperties().getProperty('slack_api_token');
if (!API_TOKEN) {
throw 'You should set "slack_api_token" property from [File] > [Project properties] > [Script properties]';
}
var FOLDER_NAME = 'Slack Team Access Logs';
/**** Do not edit below unless you know what you are doing ****/
var COL_LOG_USERID = 1;
var COL_LOG_USERNAME = 2;
var COL_LOG_DATEFIRST = 3;
var COL_LOG_DATELAST = 4;
var COL_LOG_IP =5;
var COL_LOG_USERAGENT = 6;
var COL_LOG_ISP = 7;
var COL_LOG_RAW_JSON = 8;
var COL_MAX = COL_LOG_RAW_JSON;
// Slack offers 10,000 history logs for free plan teams. As premium, pagination assumes 1,000(maximum count per page assumes 1,000)
var MAX_HISTORY_PAGINATION = 1000;
var HISTORY_COUNT_PER_PAGE = 1000;
function StoreLogsDelta() {
var logger = new SlackTeamAccessLogger();
logger.run();
}
;
var SlackTeamAccessLogger = function SlackTeamAccessLogger(){
SlackTeamAccessLogger.prototype.requestSlackAPI = function (path, params) {
if (params === void 0) { params = {}; }
var url = "https://slack.com/api/" + path + "?";
var qparams = [("token=" + encodeURIComponent(API_TOKEN))];
for (var k in params) {
qparams.push(encodeURIComponent(k) + "=" + encodeURIComponent(params[k]));
}
url += qparams.join('&');
Logger.log("==> GET " + url);
var resp = UrlFetchApp.fetch(url);
var data = JSON.parse(resp.getContentText());
if (data.error) {
throw "GET " + path + ": " + data.error;
}
return data;
};
SlackTeamAccess.prototype.run = function () {
var teamaccessResp = this.requestSlackAPI('username.list');
for (var _i = 0, _a = teamaccessResp.pages; _i < _a.length; _i++) {
var page = _a[_i];
this.importTeamAccessDelta(page);
}
};
//use google apps to flow data from slack to spreadsheet
SlackTeamAccessLogger.prototype.getLogsFolder = function () {
var folder = DriveApp.getRootFolder();
var path = [FOLDER_NAME];
path.forEach(function (name) {
var it = folder.getFoldersByName(name);
if (it.hasNext()) {
folder = it.next();
}
else {
folder = folder.createFolder(name);
}
});
return folder;
};
//if case "ta", "d", "readonly", then defined proccess would be applied
SlackTeamAccessLogger.prototype.getSheet = function (ta, d, readonly) {
if (readonly === void 0) { readonly = false; }
var dateString;
if (d instanceof Date) {
dateString = this.formatDate(d);
}
else {
dateString = '' + d;
}
var spreadsheet;
var sheetByID = {};
var spreadsheetName = dateString;
var folder = this.getLogsFolder();
var it = folder.getFilesByName(spreadsheetName);
if (it.hasNext()) {
var file = it.next();
spreadsheet = SpreadsheetApp.openById(file.getId());
}
else {
if (readonly)
return null;
spreadsheet = SpreadsheetApp.create(spreadsheetName);
folder.addFile(DriveApp.getFileById(spreadsheet.getId()));
}
var sheets = spreadsheet.getSheets();
sheets.forEach(function (s) {
var name = s.getName();
var m = /^(.+) \((.+)\)$/.exec(username); // eg. "general (C123456)"
if (!m)
return;
sheetByID[m[2]] = s;
});
var sheet = sheetByID[ch.id];
//if sheet isn't sheet
if (!sheet) {
if (readonly)
return null;
sheet = spreadsheet.insertSheet();
}
var sheetName = ta.username ;
//if gotten sheet name isn't eqaul to sheet name, set sheet name
if (sheet.getName() !== sheetName) {
sheet.setName(sheetName);
}
return sheet;
};
SlackTeamAccessLogger.prototype.importTeamAccessDelta = function (ta) {
var _this = this;
Logger.log("importTeamAccessDelta " + "ta.username ");
var now = new Date();
var page = '1'; // page=0 does not work
var existingSheet = this.getSheet(ta, now, true);
if (!existingSheet) {
// try previous month
now.setMonth(now.getMonth() - 1);
existingSheet = this.getSheet(ta, now, true);
}
if (existingSheet) {
var lastRow = existingSheet.getLastRow();
try {
var data = JSON.parse(existingSheet.getRange(lastRow, COL_LOG_RAW_JSON).getValue());
oldest = data.ts;
}
catch (e) {
Logger.log("while trying to parse the latest history item from existing sheet: " + e);
}
}
};
SlackTeamAccessLogger.prototype.formatDate = function (dt) {
return Utilities.formatDate(dt, Session.getScriptTimeZone(), 'yyyy-MM');
};
return SlackTeamAccessLogger;}