2 years ago
#65235
oki_oki
Send 2 slack messages with 1 Google Forms answer - 1 as new message and 1 as its reply
I have a Google Apps Script script from a spreadsheet to send an automatic message to slack (and an auto-reply email) when a Google Form answer is submitted. How do I send 2 slack messages in 1 script, one as a new message in a specific channel and another as a reply (thread) to the message I just sent? The current script runs as a single slack message like below and I want to split it into 2; sending the --REQUEST CONTENT-- part as a thread.
function autoReply(e) {
var values = e.values;
var name = values[1];
var email = values[2];
var phone = values[3];
var office = values[4];
var comment = values[5];
var title = "EMAIL TITLE";
var body = `
Dear ${name},
TEXT
-------------------------------------------------------
SIGNATURE
-------------------------------------------------------
`;
GmailApp.sendEmail(email, title, body);
notifySlack(`
<!channel>
You received a Google Form request:
-----REQUEST CONTENT-----
・NAME: ${name}
・EMAIL: ${email}
・PHONE: ${phone}
・OFFICE: ${office}
・COMMENT: ${comment}
-------------------------
`);
}
function notifySlack(message) {
var postUrl =
"https://hooks.slack.com/services/XXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX";
var userName = "[alert] FORM REQUEST";
var payloadObj = {
username:userName,
text:message,
icon_emoji : ":mega:"
}
var payloadJson = JSON.stringify(payloadObj);
var options = {
method:"post",
contentType:"application/json",
payload:payloadJson
}
UrlFetchApp.fetch(postUrl, options);
}
javascript
google-apps-script
webhooks
slack
0 Answers
Your Answer