Search code examples
google-apps-scriptgoogle-oauthgoogle-chat

OAuth problem with Apps Script and Google Chat


I'm currently trying to make a google chat bot on Apps Script, using webhooks that supposedly don't require any authentification. However, when I run my Apps Script function from Apps Script, it seems like I have to allow my account to "use external web apps" or something along these lines. I developped the Apps Script as an API, so that I could call the functions from an external point, but it says that I need OAuth credentials to do so. And I know how to implement OAuth credentials, I just have no idea what scope I'm supposed to use since webhooks are supposed to work without authentification.

Here's the function:

function sendText(text) {

  var url = "https://chat.googleapis.com/v1/spaces/[space]/messages?key=[webhook-key]&token=[token]";

  message = { 'text': text };
  var message_headers = {};


  const response = UrlFetchApp.fetch(url, {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify(message),
  });

  Logger.log(response);
}


Solution

  • okay I found the answer myself;

    scope is : https://googleapis.com/auth/script.external_request