6

Is there a way to get all messages belonging to a thread?

We know from https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages#Message that a Message belongs to a Thread, is there an API to fetch all messages for a given thread?

Francesco Gualazzi
  • 919
  • 1
  • 10
  • 23

1 Answers1

3

I believe that is not possible to get all the messages in a thread, by security design. A bot only receives an event when it is directly mentioned in a message and is only granted access to the text of that message.

The event object received by the bot includes a message object with details of the message, including a reference to the thread.

I wrote a simple Apps Script bot whose onMessage function returns the event object as JSON. The message part of the event provides very limited information about the thread:

    "thread": {
        "retentionSettings": {
            "state": "PERMANENT"
        },
        "name": "spaces/sKkv0fAAAAE/threads/F6qY-rYiwr0"
    },

This behaviour is the same for rooms and DMs.

Human users can scan rooms for threads and threads for messages but bots cannot.

pharsicle
  • 1,209
  • 1
  • 14
  • 18
  • 1
    I'm most interested not in the use of the Bot per se but to have an API call (or many of them) that can fetch messages in a thread. For example: how does the Chat app or website does it? There must be some way in which you can group all messages of a thread... – Francesco Gualazzi Oct 04 '19 at 19:39
  • 1
    I would like that too but, as far as I can tell, currently Google only offers automation and an API for bots. Bots can only run as service accounts, with limited privileges. – pharsicle Oct 07 '19 at 23:01
  • 1
    There is a [feature request](https://issuetracker.google.com/127691116) for this. – ziganotschka Feb 03 '20 at 10:09