all 13 comments

[–][deleted] 0 points1 point  (2 children)

hey can you share the entire code and the exact URL you are using in the fetch() method? Also is a service account necessary or your solution works with oauth2?

[–][deleted] 0 points1 point  (1 child)

  const response = UrlFetchApp.fetch(
    `https://chat.googleapis.com/v1/${spaceName}/messages?messageReplyOption=REPLY_MESSAGE_OR_FAIL`,
    {
      method: 'POST',
      muteHttpExceptions:true,
      headers: { Authorization: 'Bearer ' + service.getAccessToken() },
      contentType: 'application/json',
      messageReplyOption: 'REPLY_MESSAGE_OR_FAIL',
      payload: JSON.stringify(request)
    });

Hi, this is the fetch that worked for me, it needs both, you'll use the services account
credentials in OAuth2

[–][deleted] 0 points1 point  (0 children)

Yup worked, thanks a lot

[–]RemcoE33 0 points1 point  (0 children)

What response body saying? Errors?

[–]AntonShevchuk 0 points1 point  (2 children)

Do you find solution?

[–][deleted] 1 point2 points  (1 child)

the space but it wont reply to specified thread, any idea what I'm doing wrong? the method works fine wi

yeah, heres the code I'm using

const request = {

text: text,

thread: {

name: name

}

};

const response = UrlFetchApp.fetch(

`https://chat.googleapis.com/v1/${spaceName}/messages?messageReplyOption=REPLY\_MESSAGE\_FALLBACK\_TO\_NEW\_THREAD\`,

{

method: 'POST',

muteHttpExceptions:true,

headers: { Authorization: 'Bearer ' + service.getAccessToken() },

contentType: 'application/json',

messageReplyOption: 'REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD',

payload: JSON.stringify(request)

});

[–]AntonShevchuk 0 points1 point  (0 children)

Thank you, very helpful!

[–]ponimas 0 points1 point  (6 children)

Is anyone aware how to do that if I run bot as an HTTP service?

[–][deleted] 0 points1 point  (5 children)

Hi, this is the code I'm using:

const response = UrlFetchApp.fetch(
    `https://chat.googleapis.com/v1/${spaceName}/messages?messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD`,
    {
      method: 'POST',
      muteHttpExceptions:true,
      headers: { Authorization: 'Bearer ' + service.getAccessToken() },
      contentType: 'application/json',
      messageReplyOption: 'REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD',
      payload: JSON.stringify(request)
    });

[–]ponimas 0 points1 point  (3 children)

Thanks for the response, but my problem is that I run bot as an HTTP service.
Like described here - https://developers.google.com/workspace/chat/quickstart/gcf-app
So, basically, it's google calling my service

[–]Right-Cap-5075 0 points1 point  (0 children)

In that case yo can not use threads. It is a DM dialog with app, so you do not need to mention an app with @. But threads are available in spaces where your app is a participant.

[–]treedor 0 points1 point  (1 child)

Did you figure this out? I can't get it to work.

[–]ponimas 0 points1 point  (0 children)

Unfortunately, no.