0

Get Message

by
Published today

Get one Chat message by its resource name. Requires chat.messages.readonly or chat.messages on the connection.

Script gchat Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 hours ago
1
//native
2

3
/**
4
 * Get Message
5
 * Get one Chat message (sender, text, thread, attachments, create/update time) by its resource name `spaces/{space}/messages/{message}`, as returned by List Messages or Send Message. Requires chat.messages.readonly or chat.messages on the connection (not in the default scopes).
6
 */
7
export async function main(auth: RT.Gchat, message_name: string) {
8
  const response = await fetch(`https://chat.googleapis.com/v1/${message_name}`, {
9
    headers: {
10
      Authorization: `Bearer ${auth.token}`,
11
      Accept: "application/json",
12
    },
13
  })
14
  if (!response.ok) {
15
    throw new Error(`${response.status} ${await response.text()}`)
16
  }
17

18
  return await response.json()
19
}
20