Changes to root directory

This commit is contained in:
Norm Rasmussen
2022-02-23 17:40:01 -05:00
parent 124571c689
commit eb4c2f6322
321 changed files with 351 additions and 15 deletions

Binary file not shown.

View File

@ -0,0 +1,135 @@
// Setup of the sheet
const sheet = SpreadsheetApp.getActiveSheet();
// Setup of the date range to compare. Currently, it is using 5 days until Present.
var now = new Date();
var formatNow = Utilities.formatDate(now, 'America/New_York', 'MM/dd/yyyy'); // Today
var daysToSubtract = 5;
var withinWeek = new Date(now.getTime()-5*(3600*24*1000));
var formatWeek = Utilities.formatDate(withinWeek, 'America/New_York', 'MM/dd/yyyy'); // 5 Days ago
/*
This function will create two empty arrays, one for the list of missed entries and one for tagging users in Slack
First, the function gets the data ranges in spreadsheed and adds those columns to an array index.
Second, the for loop cycles through the super long array (4 results per line). Based on the if statement,
the loop removes all arrays that don't fit the statement.
*/
function findMeetings() { // Setting up data range and empty arrays
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()-1; // Number of rows to process
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
var data = dataRange.getValues();
var slackingAEListOne = [];
var tagList = [];
for (i in data) { // For a data row within the entire data range
var row = data[i];
let attended = row[6]; // Column G
var name = row[1]; // Column - B
var date = Utilities.formatDate(row[3],'America/New_York','MM/dd/yyyy'); // Column - D
var company = row[4]; // Column - E
let missedEntries = [name, date, company, attended];
// Adding a For Loop will pull a result for EACH element, aka 4 results per line. This pulls one for each group of missedEntries
// This then removes the last value (attended, since we already know it is a blank), converts to a string, and adds to a new array
if ((missedEntries[3] == "") && (missedEntries[1] >= formatWeek) && (missedEntries[1] <= formatNow)) {
missedEntries.pop();
missedEntries.toString();
slackingAEListOne.push(missedEntries);
};
};
// Now outside of the if statement:
// the array is built, and we want each group to be on a new line, remove the commas and add a hyphen.
var slackingAEListTwo = slackingAEListOne.splice(1).join('\n');
var finalAEList = slackingAEListTwo.replace(/,/g, ' - ')
// This if statement is going to only tag those who appear in the previous list.
// No need to tag people who have done their work and contribute to clean data.
if (finalAEList.includes('Norm')) {
tagList.push('<@U020KRBDSDQ>');
}
if (finalAEList.includes('Dan')) {
tagList.push('<@U01P7DTFSQZ>');
}
if (finalAEList.includes('Jon')) {
tagList.push('<@U020YF0Q98R>');
}
if (finalAEList.includes('Charles')) {
tagList.push('<@U01286MQUS2>');
}
var tagUsers = tagList.toString();
/* Now, we're building the payload for the Slack Message.
This is very specific and prone to errors, so check that it works using Slack's tool:
https://app.slack.com/block-kit-builder/ */
let payloadText =
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":bell: *Have you filled out the Sales New Meeting Tracker?* :bell:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "If you're tagged, you haven't filled it out."
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": finalAEList // Sends list with AE, meeting date, and company
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Here, a convenient link to the sheet!:point_right: :point_right: :point_right: :point_right:"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Sales New Meeting Tracker",
"emoji": true
},
"value": "sales_tracker_link_123",
"url": "https://docs.google.com/spreadsheets/d/1o01hj9oOoAR4TeJxXDuA3R7bHNbyCB3eaGJunK6-ojg/edit#gid=0 | First Meeting Tracker",
"action_id": "button-action"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": tagUsers // Tags with slack user numbers if they appear in finalSend
}
}
]
};
// This is standard operating procedure to creating the payload and destination
const webhook = "https://hooks.slack.com/services/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";
const options = {
method: "post",
contentType: "application/json",
muteHttpExceptions: true,
payload: JSON.stringify(payloadText),
};
const sendMsg = UrlFetchApp.fetch(webhook, options);
var respCode = sendMsg.getResponseCode();
Logger.log(sendMsg); // Debug to confirm send
Logger.log(respCode); // Debug to show errors, if any
};

View File

@ -0,0 +1,110 @@
const sheetTwo = SpreadsheetApp.getActiveSheet();
var now = new Date();
var formatToday = Utilities.formatDate(now, 'America/New_York', 'MM/dd/yyyy');
function newMeetings() {
var startRow = 2; // First row of data to process
var numRows = sheetTwo.getLastRow()-1; // Number of rows to process
var dataRange = sheetTwo.getRange(startRow, 1, numRows, sheet.getLastColumn());
var data = dataRange.getValues();
var sdrMeeting = [];
for (i in data) {
var row = data[i];
var sdr = row[0]; // Column A
var date = Utilities.formatDate(row[3],'America/New_York','MM/dd/yyyy'); // Column D
var company = row[4]; // Column E
var outbound = row[5]; // Column F
let sdrMeetingListOne = [sdr, date, company, outbound];
if ((sdrMeetingListOne[1] == formatToday) && (sdrMeetingListOne[0] != '') && (sdrMeetingListOne[3] == "Outbound")) {
sdrMeetingListOne.toString();
sdrMeeting.push(sdrMeetingListOne);
Logger.log(sdrMeetingListOne)
} else if ((sdrMeetingListOne[1] == formatToday) && (sdrMeetingListOne[0] != '')) {
let noMeetingText =
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":star: *C'mon team!* :star:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "No new meetings today? We can do better than that! Hustle!"
}
},
]
}
const webhook = "https://hooks.slack.com/services/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";
const options = {
method: "post",
contentType: "application/json",
muteHttpExceptions: true,
payload: JSON.stringify(noMeetingText),
};
const sendMsg = UrlFetchApp.fetch(webhook, options);
var respCode = sendMsg.getResponseCode();
Logger.log(sendMsg);
Logger.log(respCode);
}
};
Logger.log(sdrMeeting);
var toSend = sdrMeeting.splice(1).join('\n');
var getEm = toSend.replace(/,/g, ' - ')
Logger.log(getEm)
/*
let payloadMeetingText =
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":star: *Pitter Patter!* :star:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Here's who has meetings today. Get after it boys and girls!"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": getEm
}
},
{
"type": "image",
"image_url": "https://media.giphy.com/media/3ohjURBuAtWDV8d3SE/giphy.gif",
"alt_text": "inspiration"
}
]
}
//(array[0] + ", you still need to fill out the cells for" + array[2] + " from " + array[1] + "!\n");
const webhook = "https://hooks.slack.com/services/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";
const options = {
method: "post",
contentType: "application/json",
muteHttpExceptions: true,
payload: JSON.stringify(payloadText),
};
const sendMsg = UrlFetchApp.fetch(webhook, options);
var respCode = sendMsg.getResponseCode();
Logger.log(sendMsg);
Logger.log(respCode);*/
};

View File

@ -0,0 +1,86 @@
function myFunction() {
var URL = "https://northpass.atlassian.net/rest/api/2/issue";
var accountID = "6092af20d353800068863d15";
var token = "2NrKYv22TLWnxTo7EhU3633E";
var UserCredentials = "Basic " + Utilities.base64Encode(accountID+":"+token);
// Setting up data range and empty arrays
const sheet = SpreadsheetApp.getActiveSheet();
for (i in data) { // For a data row within the entire data range
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()-1; // Number of rows to process
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
var data = dataRange.getValues();
let row = data[i];
let name = row[1]; // Column - B
var meetingDate = Utilities.formatDate(row[3],'America/New_York','MM/dd/yyyy'); // Column - D
var company = row[4]; // Column - E
let list = [name, company, meetingDate];
if (list[0] == "Norm") {
Logger.log(list)
var data = {
"fields": {
"project" : {
"key" : "2NrKYv22TLWnxTo7EhU3633E"
},
"summary" : list[1],
"description" : "Meeting scheduled for " + list[3],
"date" : list[3],
"issuetype": {
"name" : Task
}
}
};
};
};
var payload = JSON.stringify(data);
var headers = { "Accept":"application/json",
"Content-Type":"application/json",
"Authorization":UserCredentials,
"muteHttpExceptions":"True"
}
var options = { "method":"POST",
"headers": headers,
"payload": payload
};
var response = UrlFetchApp.fetch(URL, options);
Logger.log(response);
};
// LONG JSON
var data = {
"fields": {
"issuetype": {
"id" : "10203"
},
"parent": {
"key": "NORMPIPE",
"id": "10203",
},
"project" : {
"id" : "10052",
"key" : "NORMPIPE",
},
"description" : "Meeting scheduled for " + list[3],{
"type" : "doc",
"version" : 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text" : "Meeting scheduled for " + list[3],
"type" : "text",
}
]
},
]
},
},
};