-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetHelp.gs
58 lines (50 loc) · 2.1 KB
/
getHelp.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function contactPartner() {
try {
// Constants
const userEmail = Session.getUser().getEmail();
const docId = SpreadsheetApp.getActiveSpreadsheet().getId();
const sheetLink = `https://docs.google.com/spreadsheets/d/${docId}/edit`;
const subject = `Assistance Request - ${userEmail}`;
let body = `Hi DoiT Team,\n\n${userEmail} has requested assistance with the Security Checklist for Workspace Admins. Please do your best to help them.`;
const recipient = "[email protected]";
// Create a radio button prompt
const ui = SpreadsheetApp.getUi();
const response = ui.alert(
'Send Email',
'Are you sure you want to send an email to DoiT International to request assistance?',
ui.ButtonSet.YES_NO
);
if (response !== ui.Button.YES) {
return; // User canceled, do nothing
}
// Display a radio button prompt
const includeLink = ui.alert(
'Include Link to Spreadsheet',
'Include a link to your spreadsheet in the email?',
ui.ButtonSet.YES_NO
);
if (includeLink === ui.Button.YES) {
body += `\n\nA link to the customer's Security Checklist is included below: \n${sheetLink}`;
}
// Send the email using MailApp service
MailApp.sendEmail({
to: recipient,
subject: subject,
body: body,
});
// Display a message to the user
ui.alert(`Email Sent! \n\nDoiT may request viewer access to assist you.`);
// Log confirmation
console.log("Email Sent successfully.");
} catch (error) {
// Log any errors
console.error("Error: " + error.toString());
// Display troubleshooting suggestions
const ui = SpreadsheetApp.getUi();
if (error.message.includes("Required permissions: https://www.googleapis.com/auth/userinfo.email")) {
ui.alert("Error: You do not have permission to access user information. Please enable the required permission and try again.");
} else {
ui.alert("Error sending email. Please check your internet connection and try again. If the problem persists, contact support at [email protected].");
}
}
}