Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.

Google Chat API: How can I get the Google Calendar Event/Task resource from the Chat spaces.messages

I am creating Google Calendar Events within Chat (1:1, group chat, and Space).

Create Google Calendar Event in Chat.png
After creating and sharing the event with the invitees, an automated message is sent in the chat.

Auto message of the Event.png

Using the spaces.messages.list method, I can retrieve the message response containing the text "Created an event" but I cannot access the Google Calendar Event card associated with the message.

Similarly, when a Google Task is created in the Chat Space, I can retrieve the text "Created a task" but not the Task resource details.

Create Task in Space.png

Auto message of the created Task.png


I would like to extract details from this card or obtain the Calendar Event/Task resource via the Chat API. How can I retrieve the calendar event information or card from the message in this scenario? Are there any specific fields or additional API calls I should use to get the Calendar Event/Task resource?

Is there a way to retrieve the iCalUID or id of the Google Calendar Event, or the id of the Google Task associated with this message?Are there any specific fields or API calls within the Google Chat API that could provide these details?"

Thank you. Please let me know if you need any further information.

My code(Java) for listing message in a space:

 

List<String> SCOPE =
    Arrays.asList(
        "https://www.googleapis.com/auth/chat.spaces",
        "https://www.googleapis.com/auth/chat.messages",
        "https://www.googleapis.com/auth/chat.memberships"
    );

try (InputStream isCredential = new ByteArrayInputStream(sServiceAccountJson.getBytes())) {

    GoogleCredentials googleCredentials =
        ServiceAccountCredentials
            .fromStream(isCredential)
            .createDelegated(sAdminAddress)
            .createScoped(SCOPE)
            .toBuilder()
            .build();

    ChatServiceSettings chatServiceSettings =
        ChatServiceSettings.newBuilder()
          .setCredentialsProvider(FixedCredentialsProvider.create(googleCredentials))
            .build();

    ListMessagesRequest request = ListMessagesRequest.newBuilder()
        .setParent("spaces/{space}")
        .build();

    for (Message message : chatServiceClient.listMessages(request).iterateAll()) {
        System.out.println(JsonFormat.printer().print(message));
    }
}

 

 

Message response:

 

{
  "name": "spaces/{spaces}/messages/{message}",
  "sender": {
    "name": "users/{user}",
    "type": "HUMAN"
  },
  "createTime": "2024-09-30T05:29:07.225471Z",
  "text": "Created an event",
  "thread": {
    "name": "spaces/{spaces}/threads/{thread}"
  },
  "space": {
    "name": "spaces/{spaces}"
  },
  "argumentText": "Created an event",
  "formattedText": "Created an event"
}
{
  "name": "spaces/{spaces}/messages/{message}",
  "sender": {
    "name": "users/{user}",
    "type": "HUMAN"
  },
  "createTime": "2024-09-30T05:52:29.173567Z",
  "text": "Created a task (via Tasks)",
  "thread": {
    "name": "spaces/{spaces}/threads/{thread}"
  },
  "space": {
    "name": "spaces/{spaces}"
  },
  "argumentText": "Created a task (via Tasks)",
  "formattedText": "Created a task (via Tasks)"
}

 

 

 

 

 

0 0 724
0 REPLIES 0
Top Labels in this Space
Top Solution Authors