Skip to content

Commit

Permalink
fix(ms-teams): add list chats method
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiivanov committed Jan 16, 2023
1 parent 47c96d0 commit 8e799c7
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
"name": "Get chat by ID",
"value": "getChat"
},
{
"name": "List chats",
"value": "listChats"
},
{
"name": "List chat members",
"value": "listMembersOfChat"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. Licensed under a proprietary license.
* See the License.txt file for more information. You may not use this file
* except in compliance with the proprietary license.
*/
package io.camunda.connector;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.camunda.connector.suppliers.ObjectMapperSupplier;

public class RemoveNullFieldsUtil {

private RemoveNullFieldsUtil() {}

public static Object removeNullFieldsInObject(Object object) {
ObjectMapper objectMapper = ObjectMapperSupplier.nonNullObjectMapper();
try {
return objectMapper.readValue(objectMapper.writer().writeValueAsString(object), Object.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
*/
package io.camunda.connector.model.request.chat;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import static io.camunda.connector.RemoveNullFieldsUtil.removeNullFieldsInObject;

import com.microsoft.graph.requests.ChatRequest;
import com.microsoft.graph.requests.GraphServiceClient;
import io.camunda.connector.api.annotation.Secret;
import io.camunda.connector.model.request.MSTeamsRequestData;
import io.camunda.connector.suppliers.ObjectMapperSupplier;
import java.util.List;
import java.util.Objects;
import javax.validation.constraints.NotBlank;
Expand All @@ -33,15 +32,6 @@ public Object invoke(final GraphServiceClient<Request> graphClient) {
return removeNullFieldsInObject(chatRequest.get());
}

private Object removeNullFieldsInObject(Object object) {
ObjectMapper objectMapper = ObjectMapperSupplier.nonNullObjectMapper();
try {
return objectMapper.readValue(objectMapper.writer().writeValueAsString(object), Object.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

public String getChatId() {
return chatId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. Licensed under a proprietary license.
* See the License.txt file for more information. You may not use this file
* except in compliance with the proprietary license.
*/
package io.camunda.connector.model.request.chat;

import static io.camunda.connector.RemoveNullFieldsUtil.removeNullFieldsInObject;

import com.microsoft.graph.requests.GraphServiceClient;
import io.camunda.connector.model.request.MSTeamsRequestData;
import okhttp3.Request;

public class ListChats extends MSTeamsRequestData {

@Override
public Object invoke(final GraphServiceClient<Request> graphClient) {
return removeNullFieldsInObject(graphClient.chats().buildRequest().get());
}

@Override
public String toString() {
return "ListChats{}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.camunda.connector.model.request.chat.GetChat;
import io.camunda.connector.model.request.chat.GetMessageInChat;
import io.camunda.connector.model.request.chat.ListChatMembers;
import io.camunda.connector.model.request.chat.ListChats;
import io.camunda.connector.model.request.chat.ListMessagesInChat;
import io.camunda.connector.model.request.chat.SendMessageInChat;

Expand All @@ -50,6 +51,7 @@ public final class GsonSupplier {
// chat
.registerSubtype(CreateChat.class, "createChat")
.registerSubtype(GetChat.class, "getChat")
.registerSubtype(ListChats.class, "listChats")
.registerSubtype(GetMessageInChat.class, "getMessageFromChat")
.registerSubtype(ListChatMembers.class, "listMembersOfChat")
.registerSubtype(ListMessagesInChat.class, "listMessagesInChat")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.camunda.connector.model.request.chat.GetChat;
import io.camunda.connector.model.request.chat.GetMessageInChat;
import io.camunda.connector.model.request.chat.ListChatMembers;
import io.camunda.connector.model.request.chat.ListChats;
import io.camunda.connector.model.request.chat.ListMessagesInChat;
import io.camunda.connector.model.request.chat.SendMessageInChat;
import java.util.HashMap;
Expand Down Expand Up @@ -58,6 +59,7 @@ public void init() {
// chat
methodsMap.put("createChat", CreateChat.class);
methodsMap.put("getChat", GetChat.class);
methodsMap.put("listChats", ListChats.class);
methodsMap.put("getMessageFromChat", GetMessageInChat.class);
methodsMap.put("listMembersOfChat", ListChatMembers.class);
methodsMap.put("listMessagesInChat", ListMessagesInChat.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@
"method": "getChat"
}
},
{
"authentication": {
"type": "clientCredentials"
},
"data": {
"method": "listChats"
}
},
{
"authentication": {
"type": "clientCredentials"
Expand Down Expand Up @@ -352,6 +360,14 @@
"method": "getChat"
}
},
{
"authentication": {
"type": "token"
},
"data": {
"method": "listChats"
}
},
{
"authentication": {
"type": "token"
Expand Down

0 comments on commit 8e799c7

Please sign in to comment.