Kelvin L
Kelvin L

Reputation: 1

Google Chat API: How can I retrieve the Google Calendar Event or Google Task resource from the Chat spaces.messages.list?

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

After creating and sharing the event with the invitees, an automated message is sent in the chat. Auto message of the Event

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 Auto message of the created Task

I used the Google Chat API (spaces.messages.list) to retrieve Google Calendar Event/Task details from a message in Chat, but it only returns the text response without the card details. I reviewed the Google Calendar API and Tasks API documentation but couldn’t find any references to the auto-generated message, card object, or any information related to Google Chat.

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)"
}

Upvotes: 0

Views: 122

Answers (0)

Related Questions