I want to automatically replace my username with GAS.

Asked 1 years ago, Updated 1 years ago, 406 views

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);

}

google-apps-script

2022-11-19 02:50

1 Answers

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.


2022-11-19 11:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.