Skip to content

Commit f40943d

Browse files
authored
Merge branch 'develop' into feature-2893/remove-run-search-button
2 parents cf8cce0 + 9364239 commit f40943d

File tree

44 files changed

+1607
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1607
-222
lines changed

.github/workflows/gradle-build-production.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
9090
--set-env-vars "SLACK_PULSE_SIGNING_SECRET=${{ secrets.SLACK_PULSE_SIGNING_SECRET }}" \
9191
--set-env-vars "SLACK_PULSE_BOT_TOKEN=${{ secrets.SLACK_PULSE_BOT_TOKEN }}" \
92+
--set-env-vars "SLACK_KUDOS_CHANNEL_ID=${{ secrets.SLACK_KUDOS_CHANNEL_ID }}" \
9293
--platform "managed" \
9394
--max-instances 8 \
9495
--allow-unauthenticated

.github/workflows/gradle-deploy-develop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ jobs:
113113
--set-env-vars "SLACK_WEBHOOK_URL=${{ secrets.SLACK_WEBHOOK_URL }}" \
114114
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
115115
--set-env-vars "SLACK_SIGNING_SECRET=${{ secrets.SLACK_PULSE_SIGNING_SECRET }}" \
116+
--set-env-vars "SLACK_KUDOS_CHANNEL_ID=${{ secrets.SLACK_KUDOS_CHANNEL_ID }}" \
116117
--platform "managed" \
117118
--max-instances 2 \
118119
--allow-unauthenticated

.github/workflows/gradle-deploy-native-develop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ jobs:
113113
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
114114
--set-env-vars "SLACK_PULSE_SIGNING_SECRET=${{ secrets.SLACK_PULSE_SIGNING_SECRET }}" \
115115
--set-env-vars "SLACK_PULSE_BOT_TOKEN=${{ secrets.SLACK_PULSE_BOT_TOKEN }}" \
116+
--set-env-vars "SLACK_KUDOS_CHANNEL_ID=${{ secrets.SLACK_KUDOS_CHANNEL_ID }}" \
116117
--platform "managed" \
117118
--max-instances 2 \
118119
--allow-unauthenticated

server/src/main/java/com/objectcomputing/checkins/configuration/CheckInsConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public static class SlackConfig {
8282

8383
@NotBlank
8484
private String signingSecret;
85+
86+
@NotBlank
87+
private String kudosChannel;
8588
}
8689
}
8790
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package com.objectcomputing.checkins.notifications.social_media;
2+
3+
import com.objectcomputing.checkins.configuration.CheckInsConfiguration;
4+
5+
import com.slack.api.Slack;
6+
import com.slack.api.methods.MethodsClient;
7+
import com.slack.api.methods.request.chat.ChatPostMessageRequest;
8+
import com.slack.api.methods.response.chat.ChatPostMessageResponse;
9+
import com.slack.api.methods.request.chat.ChatDeleteRequest;
10+
import com.slack.api.methods.response.chat.ChatDeleteResponse;
11+
import com.slack.api.methods.request.conversations.ConversationsOpenRequest;
12+
import com.slack.api.methods.response.conversations.ConversationsOpenResponse;
13+
14+
import jakarta.inject.Singleton;
15+
import jakarta.inject.Inject;
16+
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
20+
import java.util.List;
21+
22+
@Singleton
23+
public class SlackSender {
24+
private static final Logger LOG = LoggerFactory.getLogger(SlackSender.class);
25+
26+
@Inject
27+
private CheckInsConfiguration configuration;
28+
29+
public boolean send(List<String> userIds, String slackBlocks) {
30+
// See if we have a token.
31+
String token = configuration.getApplication()
32+
.getSlack().getBotToken();
33+
if (token != null && !slackBlocks.isEmpty()) {
34+
MethodsClient client = Slack.getInstance().methods(token);
35+
36+
try {
37+
ConversationsOpenResponse openResponse =
38+
client.conversationsOpen(ConversationsOpenRequest.builder()
39+
.users(userIds)
40+
.returnIm(true)
41+
.build());
42+
if (!openResponse.isOk()) {
43+
LOG.error("Unable to open the conversation");
44+
return false;
45+
}
46+
47+
return send(openResponse.getChannel().getId(), slackBlocks);
48+
} catch(Exception ex) {
49+
LOG.error("SlackSender.send: " + ex.toString());
50+
return false;
51+
}
52+
} else {
53+
LOG.error("Missing token or missing slack blocks");
54+
return false;
55+
}
56+
}
57+
58+
public boolean send(String channelId, String slackBlocks) {
59+
// See if we have a token.
60+
String token = configuration.getApplication()
61+
.getSlack().getBotToken();
62+
if (token != null && !slackBlocks.isEmpty()) {
63+
MethodsClient client = Slack.getInstance().methods(token);
64+
65+
try {
66+
ChatPostMessageRequest request = ChatPostMessageRequest
67+
.builder()
68+
.channel(channelId)
69+
.blocksAsString(slackBlocks)
70+
.build();
71+
72+
// Send it to Slack
73+
ChatPostMessageResponse response = client.chatPostMessage(request);
74+
75+
if (!response.isOk()) {
76+
LOG.error("Unable to send the chat message: " +
77+
response.getError());
78+
}
79+
80+
return response.isOk();
81+
} catch(Exception ex) {
82+
LOG.error("SlackSender.send: " + ex.toString());
83+
return false;
84+
}
85+
} else {
86+
LOG.error("Missing token or missing slack blocks");
87+
return false;
88+
}
89+
}
90+
91+
public boolean delete(String channel, String ts) {
92+
// See if we have a token.
93+
String token = configuration.getApplication()
94+
.getSlack().getBotToken();
95+
if (token != null) {
96+
MethodsClient client = Slack.getInstance().methods(token);
97+
98+
try {
99+
ChatDeleteRequest request = ChatDeleteRequest
100+
.builder()
101+
.channel(channel)
102+
.ts(ts)
103+
.build();
104+
105+
// Send it to Slack
106+
ChatDeleteResponse response = client.chatDelete(request);
107+
108+
if (!response.isOk()) {
109+
LOG.error("Unable to delete the chat message: " +
110+
response.getError());
111+
}
112+
113+
return response.isOk();
114+
} catch(Exception ex) {
115+
LOG.error("SlackSender.delete: " + ex.toString());
116+
return false;
117+
}
118+
} else {
119+
LOG.error("Missing token or missing slack blocks");
120+
return false;
121+
}
122+
}
123+
}
124+

server/src/main/java/com/objectcomputing/checkins/services/kudos/KudosConverter.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.objectcomputing.checkins.services.kudos;
22

3-
import com.objectcomputing.checkins.notifications.social_media.SlackSearch;
3+
import com.objectcomputing.checkins.services.slack.SlackSearch;
44
import com.objectcomputing.checkins.services.kudos.kudos_recipient.KudosRecipientServices;
55
import com.objectcomputing.checkins.services.kudos.kudos_recipient.KudosRecipient;
66
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
@@ -22,10 +22,6 @@
2222

2323
@Singleton
2424
public class KudosConverter {
25-
private record InternalBlock(
26-
List<LayoutBlock> blocks
27-
) {}
28-
2925
private final MemberProfileServices memberProfileServices;
3026
private final KudosRecipientServices kudosRecipientServices;
3127
private final SlackSearch slackSearch;
@@ -61,9 +57,8 @@ public String toSlackBlock(Kudos kudos) {
6157
.elements(content).build();
6258
RichTextBlock richTextBlock = RichTextBlock.builder()
6359
.elements(List.of(element)).build();
64-
InternalBlock block = new InternalBlock(List.of(richTextBlock));
6560
Gson mapper = GsonFactory.createSnakeCase();
66-
return mapper.toJson(block);
61+
return mapper.toJson(List.of(richTextBlock));
6762
}
6863

6964
private RichTextSectionElement.TextStyle boldItalic() {

server/src/main/java/com/objectcomputing/checkins/services/kudos/KudosServices.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface KudosServices {
1313

1414
Kudos approve(Kudos kudos);
1515

16+
Kudos savePreapproved(KudosCreateDTO kudos);
17+
1618
List<KudosResponseDTO> getRecent();
1719

1820
KudosResponseDTO getById(UUID id);

0 commit comments

Comments
 (0)