-2

Can we have API's for monitoring the chats between different users and group in Hangout within our organisation . This will help Admin to have better control over the content which is being communicated within organisation and to control outside of organisation. Also if any of these type of API is present where I can get detail chats of all user, please let me know.

1 Answers1

1

Google chat's messages can be fetch through Gmail API, you can make a Messages.List request to get all the messages from Chat and Gmail. To filter only by the ones in chat, you can use the following query q parameter:

label:CHAT

With a Messages.Get request you can get the data for each message.

Finally, that would only give you the data of the user you're using the credentials from, to get the data for all the organization you need to use a service account with domain wide delegation in order to impersonate each user in the domain and be able to do the mentioned process with each user's credentials.

EDIT

As you also need chat group's information as name and members, you need to use Hangouts Chat API and set-up an application/bot using a service account credentials as explained in this example with Python:

from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
scopes = 'https://www.googleapis.com/auth/chat.bot'
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'service-account.json', scopes)
chat = build('chat', 'v1', http=credentials.authorize(Http()))
resp = chat.spaces().messages().create(
    parent='spaces/AAAA2CiqVDM', # use your space here
    body={'text': 'Test message'}).execute()
print(resp)

The above code makes a message create request, but similarly you can use it to make any of the other available requests. You can use a different language library as well.

user7610
  • 25,267
  • 15
  • 124
  • 150
Andres Duarte
  • 3,166
  • 1
  • 7
  • 14
  • Thanks for the response. The issue in this i am facing is in case of group we are not getting details of group like group name or members of the group and any group specific actions like adding or removing members. – Ikjot Singh Mar 20 '20 at 16:31
  • Also in this Chat between 2 users have different threadId and id which will make it difficult to know whether these both chats are same of different. Why google doesn't provide any common id for 1 chat room like message id in case of gmail. – Ikjot Singh Mar 23 '20 at 10:09
  • I edited my answer to reply to your first comment. For your 2nd comment, it's true what you say, they have different threadIDs for different users, that's the intended behavior for all messages in Gmail API. But Chat API has a different way of working with [threads](https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages#Thread), you might want to check how does that work. – Andres Duarte Mar 23 '20 at 16:42