2

I want to make a workflow that whenever someone joins the organization, they are automatically added to an organization-wide room on Google Chat (not Google Group).

In the Google Chat room, if you mention someone in your organization and if they are not present in the room, then they are automatically added to the room.

So, I thought to create a Google App Script which will fetch the users of the organization and then send a message, using webhook, in a room. The problem is that it is not mentioning the user who is not in the room already. Therefore, it is not making my idea work.

Is there any way around to this? Can I use Google Chat API to add users to a room? Please point me to a relevant resource for this.

Please find the code I used below

function listAllUsers() {
  var pageToken;
  var page;
  var userList = []
  do {
    page = AdminDirectory.Users.list({
      domain: 'domain.xyz',
      maxResults: 100,
      pageToken: pageToken
    });
    var users = page.users;
    if (users) {
      for (var i = 0; i < users.length; i++) {
        var user = users[i];
        sendMessage('<users/'+user.id+'>');
        Logger.log('u:%s, %s (%s)', user.id, user.name.fullName, user.primaryEmail);
      }
    } else {
      Logger.log('No users found.');
    }
    pageToken = page.nextPageToken;
  } while (pageToken);



}

function sendMessage(userid){
      message = {'text':userid}

      UrlFetchApp.fetch('<webhook-url>', {
        method: 'post',
        headers: {},
        contentType: 'application/json',
        payload: JSON.stringify(message),
      });
}
Harsh Choudhary
  • 475
  • 5
  • 12

1 Answers1

2

Just simply sending a message in the chat using the following format "@User Name" won't add the member within the UI either.

If you do want to add the member from the UI, you will have to select the user manually and afterwards confirm that you want to add it to the specific room.

mention user

confirm the user has been added

Taking these into account and also checking the methods specific for the Chat API, adding a member is not possible using the Chat API. However, what you can do in this situation is to create a feature request on Google's Issue Tracker following the link here and filling in the template accordingly.

ale13
  • 5,679
  • 3
  • 10
  • 25