-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add invite users to channel method
- Loading branch information
1 parent
3cd738e
commit 83d913c
Showing
13 changed files
with
559 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
connectors/slack/src/main/java/io/camunda/connector/slack/Conversation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.camunda.connector.slack; | ||
|
||
import java.util.Objects; | ||
|
||
public class Conversation { | ||
|
||
private final String id; | ||
private final String name; | ||
|
||
public Conversation(com.slack.api.model.Conversation conversation) { | ||
this.id = conversation.getId(); | ||
this.name = conversation.getName(); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Conversation that = (Conversation) o; | ||
return Objects.equals(id, that.id) && Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Conversation{" + "id='" + id + '\'' + ", name='" + name + '\'' + '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
connectors/slack/src/main/java/io/camunda/connector/slack/ConversationsInviteData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.camunda.connector.slack; | ||
|
||
import com.slack.api.methods.MethodsClient; | ||
import com.slack.api.methods.SlackApiException; | ||
import com.slack.api.methods.request.conversations.ConversationsInviteRequest; | ||
import com.slack.api.methods.response.conversations.ConversationsInviteResponse; | ||
import io.camunda.connector.api.annotation.Secret; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class ConversationsInviteData implements SlackRequestData { | ||
|
||
@NotBlank | ||
@Secret | ||
private String channelName; | ||
@NotBlank | ||
@Secret | ||
private String users; | ||
|
||
@Override | ||
public SlackResponse invoke(MethodsClient methodsClient) throws SlackApiException, IOException { | ||
List<String> userList = DataLookupService.getUserIdsFromNameOrEmail(DataLookupService.convertStringToList(users), methodsClient); | ||
ConversationsInviteRequest request = | ||
ConversationsInviteRequest.builder() | ||
.channel(DataLookupService.getChannelIdByName(channelName, methodsClient)) | ||
.users(userList) | ||
.build(); | ||
|
||
ConversationsInviteResponse response = methodsClient.conversationsInvite(request); | ||
|
||
if (response.isOk()) { | ||
return new ConversationsInviteSlackResponse(response); | ||
} else { | ||
throw new RuntimeException(response.getError()); | ||
} | ||
} | ||
|
||
public String getChannelName() { | ||
return channelName; | ||
} | ||
|
||
public void setChannelName(String channelName) { | ||
this.channelName = channelName; | ||
} | ||
|
||
public String getUsers() { | ||
return users; | ||
} | ||
|
||
public void setUsers(String users) { | ||
this.users = users; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ConversationsInviteData that = (ConversationsInviteData) o; | ||
return channelName.equals(that.channelName) && Objects.equals(users, that.users); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(channelName, users); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ConversationsInviteData{" + | ||
"channelName='" + channelName + '\'' + | ||
", users=" + users + | ||
'}'; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...tors/slack/src/main/java/io/camunda/connector/slack/ConversationsInviteSlackResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.camunda.connector.slack; | ||
|
||
import com.slack.api.methods.response.conversations.ConversationsInviteResponse; | ||
import java.util.Objects; | ||
|
||
public class ConversationsInviteSlackResponse implements SlackResponse { | ||
|
||
private final Conversation channel; | ||
private final String needed; | ||
private final String provided; | ||
|
||
public ConversationsInviteSlackResponse(ConversationsInviteResponse conversationsInviteResponse) { | ||
this.channel = new Conversation(conversationsInviteResponse.getChannel()); | ||
this.needed = conversationsInviteResponse.getNeeded(); | ||
this.provided = conversationsInviteResponse.getProvided(); | ||
} | ||
|
||
public Conversation getChannel() { | ||
return channel; | ||
} | ||
|
||
public String getNeeded() { | ||
return needed; | ||
} | ||
|
||
public String getProvided() { | ||
return provided; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ConversationsInviteSlackResponse that = (ConversationsInviteSlackResponse) o; | ||
return Objects.equals(channel, that.channel) && Objects.equals(needed, that.needed) && Objects.equals(provided, that.provided); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(channel, needed, provided); | ||
} | ||
} |
Oops, something went wrong.