Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google AppScript to collect Talkus+Slack data
function doPost(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");
var toLog = handleTalkusEvent(e.postData.contents);
if (!toLog) {
return;
}
// Improve this by getting first row column names
sheet.appendRow([toLog.endTime, toLog.channelName, toLog.userAsking, toLog.userAskingJoinTime, toLog.firstResponder, toLog.firstResponseTime, toLog.messages]);
}
// Get only the useful/actionable events and info
function handleTalkusEvent(eventString) {
var e = JSON.parse(eventString);
if (!e) {
return;
}
if (e.length <= 0) {
return;
}
if (e[0].event != 'end') {
return;
}
var usefulInfo = searchMessages(e[0].messages);
usefulInfo.channelName = e[0].channelName;
usefulInfo.messages = JSON.stringify(e[0].messages); // logging messages for debugging
usefulInfo.endTime = e[0].createdAt;
return usefulInfo;
}
function ignoreUser(msg) {
return (msg.userPicture == 'https://talkus.io/app/avatar-default.png' || msg.userName == 'slackbot' || msg.userName == 'Toucan Tech support');
}
function searchMessages(msgs) {
// separate the messages to get
// time of first person to get in
// time of first responder
var userAsking, userAskingJoinTime, firstResponder, firstResponseTime;
for (var i=0; i < msgs.length ; i++) {
var msg = msgs[i];
if (!userAsking && !ignoreUser(msg)) {
userAsking = msg.userName;
userAskingJoinTime = msg.createdAt;
}
if (!!userAsking && !firstResponder && msg.userName != userAsking && !ignoreUser(msg)) {
firstResponder = msg.userName;
firstResponseTime = msg.createdAt;
}
}
return {
userAsking: userAsking,
userAskingJoinTime: userAskingJoinTime,
firstResponder: firstResponder,
firstResponseTime: firstResponseTime
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment