Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

653 fr slack connector post message add option to post to an existing thread #2773

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.thread",
"label" : "Thread",
"optional" : true,
"feel" : "optional",
"group" : "channel",
"binding" : {
"name" : "data.thread",
"type" : "zeebe:input"
},
"condition" : {
"property" : "method",
"equals" : "chat.postMessage",
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.newChannelName",
"label" : "Channel name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.thread",
"label" : "Thread",
"optional" : true,
"feel" : "optional",
"group" : "channel",
"binding" : {
"name" : "data.thread",
"type" : "zeebe:input"
},
"condition" : {
"property" : "method",
"equals" : "chat.postMessage",
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.newChannelName",
"label" : "Channel name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public record ChatPostMessageData(
binding = @PropertyBinding(name = "data.channel"))
@NotBlank
String channel,
@TemplateProperty(
label = "Thread",
id = "data.thread",
group = "channel",
optional = true,
feel = FeelMode.optional,
binding = @PropertyBinding(name = "data.thread"))
String thread,
@TemplateProperty(
label = "Message type",
id = "data.messageType",
Expand Down Expand Up @@ -108,7 +116,9 @@ public SlackResponse invoke(MethodsClient methodsClient) throws SlackApiExceptio
// Enables plain text message formatting
requestBuilder.linkNames(true);
}

if (StringUtils.isNotBlank(thread)) {
requestBuilder.threadTs(thread);
}
if (blockContent != null) {
if (!blockContent.isArray()) {
throw new ConnectorException("Block section must be an array");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface ChatPostMessageData {
String EMAIL = "john.dou@camundamail.com";
String USERNAME = "@" + USER_REAL_NAME;
String CHANNEL_NAME = "#john.channel";
String THREAD_NAME = "thread_ts";
String CHANNEL_ID = "12345678";
String TEXT = "_ this is secret test text _";
}
Expand All @@ -53,6 +54,7 @@ interface ChatPostMessageData {
String USERNAME = "USERNAME_KEY";
String CHANNEL_NAME = "CHANNEL_NAME_KEY";
String CHANNEL_ID = "CHANNEL_ID_KEY";
String THREAD_NAME = "THREAD_NAME_KEY";
String TEXT = "TEXT_KEY";
}

Expand All @@ -71,6 +73,9 @@ protected static OutboundConnectorContextBuilder getContextBuilderWithSecrets()
.secret(
SecretsConstant.ChatPostMessageData.CHANNEL_NAME,
ActualValue.ChatPostMessageData.CHANNEL_NAME)
.secret(
SecretsConstant.ChatPostMessageData.THREAD_NAME,
ActualValue.ChatPostMessageData.THREAD_NAME)
.secret(
SecretsConstant.ChatPostMessageData.CHANNEL_ID,
ActualValue.ChatPostMessageData.CHANNEL_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ChatPostMessageDataTest {
void invoke_shouldThrowExceptionWhenUserWithoutEmail() throws SlackApiException, IOException {
// Given
ChatPostMessageData chatPostMessageData =
new ChatPostMessageData("test@test.com", "plainText", "Test text", EMPTY_JSON);
new ChatPostMessageData("test@test.com", "thread_ts", "plainText", "Test text", EMPTY_JSON);
when(methodsClient.usersLookupByEmail(any(UsersLookupByEmailRequest.class))).thenReturn(null);
// When and then
Throwable thrown = catchThrowable(() -> chatPostMessageData.invoke(methodsClient));
Expand All @@ -80,7 +80,7 @@ void invoke_shouldThrowExceptionWhenUserWithoutEmail() throws SlackApiException,
void invoke_shouldFindUserIdByEmail(String email) throws SlackApiException, IOException {
// Given
ChatPostMessageData chatPostMessageData =
new ChatPostMessageData(email, "plainText", "test", null);
new ChatPostMessageData(email, "thread_ts", "plainText", "test", null);

when(methodsClient.usersLookupByEmail(any(UsersLookupByEmailRequest.class)))
.thenReturn(lookupByEmailResponse);
Expand All @@ -102,7 +102,7 @@ void invoke_shouldFindUserIdByEmail(String email) throws SlackApiException, IOEx
void invoke_WhenTextIsGiven_ShouldInvoke() throws SlackApiException, IOException {
// Given
ChatPostMessageData chatPostMessageData =
new ChatPostMessageData("test@test.com", "plainText", "test", null);
new ChatPostMessageData("test@test.com", "thread_ts", "plainText", "test", null);

when(methodsClient.usersLookupByEmail(any(UsersLookupByEmailRequest.class)))
.thenReturn(lookupByEmailResponse);
Expand Down Expand Up @@ -169,7 +169,11 @@ void invoke_WhenContentBlockIsGiven_ShouldInvoke() throws SlackApiException, IOE

ChatPostMessageData chatPostMessageData =
new ChatPostMessageData(
"test@test.com", "messageBlock", "test", objectMapper.readTree(blockContent));
"test@test.com",
"thread_ts",
"messageBlock",
"test",
objectMapper.readTree(blockContent));

when(methodsClient.usersLookupByEmail(any(UsersLookupByEmailRequest.class)))
.thenReturn(lookupByEmailResponse);
Expand Down Expand Up @@ -205,7 +209,7 @@ void invoke_WhenContentBlockIsNotArray_ShouldThrow() throws SlackApiException, I

ChatPostMessageData chatPostMessageData =
new ChatPostMessageData(
"test@test.com", "plainText", "test", objectMapper.readTree(blockContent));
"test@test.com", "thread_ts", "plainText", "test", objectMapper.readTree(blockContent));

when(methodsClient.usersLookupByEmail(any(UsersLookupByEmailRequest.class)))
.thenReturn(lookupByEmailResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.CHANNEL_NAME_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"text": "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
Expand All @@ -14,7 +15,8 @@
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.CHANNEL_NAME_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"text": "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
Expand All @@ -23,7 +25,8 @@
"method": "chat.postMessage",
"data": {
"channel": "#john.channel",
"text": "some text"
"text": "some text",
"thread" : "normal_thread"
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.EMAIL_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"text": "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
Expand All @@ -14,7 +15,8 @@
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.EMAIL_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"text": "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
Expand All @@ -23,7 +25,8 @@
"method": "chat.postMessage",
"data": {
"channel": "john.dou@camundamail.com",
"text": "some text"
"text": "some text",
"thread" : "normal_thread"
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.USERNAME_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"text": "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
Expand All @@ -14,7 +15,8 @@
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.USERNAME_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"text": "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
Expand All @@ -23,7 +25,8 @@
"method": "chat.postMessage",
"data": {
"channel": "@JohnDou",
"text": "some text"
"text": "some text",
"thread" : "test thread"
}
}
]
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
[
{
"description": "all secrets keys exist without braces",
"token": "{{secrets.TOKEN_KEY}}",
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.EMAIL_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"description" : "all secrets keys exist without braces",
"token" : "{{secrets.TOKEN_KEY}}",
"method" : "chat.postMessage",
"data" : {
"channel" : "{{secrets.EMAIL_KEY}}",
"text" : "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
"description": "all secrets keys exist with braces",
"token": "{{secrets.TOKEN_KEY}}",
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.EMAIL_KEY}}",
"text": "{{secrets.TEXT_KEY}}"
"description" : "all secrets keys exist with braces",
"token" : "{{secrets.TOKEN_KEY}}",
"method" : "chat.postMessage",
"data" : {
"channel" : "{{secrets.EMAIL_KEY}}",
"text" : "{{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
"description": "secrets in braces after text",
"token": "{{secrets.TOKEN_KEY}}",
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.EMAIL_KEY}}",
"text": "some text {{secrets.TEXT_KEY}}"
"description" : "secrets in braces after text",
"token" : "{{secrets.TOKEN_KEY}}",
"method" : "chat.postMessage",
"data" : {
"channel" : "{{secrets.EMAIL_KEY}}",
"text" : "some text {{secrets.TEXT_KEY}}",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
"description": "secrets in braces in text",
"token": "{{secrets.TOKEN_KEY}}",
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.EMAIL_KEY}}",
"text": "some {{ secrets.TEXT_KEY}} text"
"description" : "secrets in braces in text",
"token" : "{{secrets.TOKEN_KEY}}",
"method" : "chat.postMessage",
"data" : {
"channel" : "{{secrets.EMAIL_KEY}}",
"text" : "some {{ secrets.TEXT_KEY}} text",
"thread" : "{{secrets.THREAD_NAME_KEY}}"
}
},
{
"description": "secrets before braces in text",
"token": "{{secrets.TOKEN_KEY}}",
"method": "chat.postMessage",
"data": {
"channel": "{{secrets.EMAIL_KEY}}",
"text": "{{secrets.TEXT_KEY}} some text"
"description" : "secrets before braces in text",
"token" : "{{secrets.TOKEN_KEY}}",
"method" : "chat.postMessage",
"data" : {
"channel" : "{{secrets.EMAIL_KEY}}",
"text" : "{{secrets.TEXT_KEY}} some text",
"thread" : "thread {{secrets.THREAD_NAME_KEY}}"
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"method": "chat.postMessage",
"data": {
"channel": "channel",
"text": "_ this is secret test text _"
"text": "_ this is secret test text _",
"thread": "normal_thread"
}
},
{
Expand All @@ -13,7 +14,8 @@
"method": "chat.postMessage",
"data": {
"channel": "channel",
"text": "_ this is secret test text _"
"text": "_ this is secret test text _",
"thread": "normal_thread"
}
},

Expand All @@ -23,7 +25,8 @@
"method": "chat.postMessage",
"data": {
"channel": null,
"text": "_ this is secret test text _"
"text": "_ this is secret test text _",
"thread": "normal_thread"
}
},
{
Expand All @@ -32,7 +35,8 @@
"method": "chat.postMessage",
"data": {
"channel": " ",
"text": "_ this is secret test text _"
"text": "_ this is secret test text _",
"thread": "normal_thread"
}
},
{
Expand Down
Loading