I'd like you to automatically enter the person who executed this script in this part of vartxt=';, what should I do from here?
function onOpen2(){
varurl='https://chat.googleapis.com';
var text = 'Automatically insert viewer's name';
var payload = {
"text"—text
}
varjson=JSON.stringify(payload);
var options = {
"method": "POST",
"contentType": 'application/json; charset=utf-8',
"payload": json
}
var response=UrlFetchApp.fetch(url, options);
Logger.log(response);
}
The email address (login ID) of the current session user (the user who opened the GAS) can be obtained from Session.getActiveUser().getEmail()
.
Documentation: Session.getActiveUser()
However, only getEmail()
methods are available for users who can obtain only the email address (login ID).If you also want to get a user's name, you will need to get the user information from that email address using Directory API.
© 2024 OneMinuteCode. All rights reserved.