Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0c12da8
Moved slack functionality into a new slack directory.
ocielliottc Feb 6, 2025
4ede442
Moved handling of Slack submissions, added code to read slack message…
ocielliottc Feb 7, 2025
6ada313
Process the response from users prompt asking to post kudos in Check-…
ocielliottc Feb 7, 2025
2885adc
Translate channel referencs to channel names and escape the kudos con…
ocielliottc Feb 7, 2025
899ecad
Merge branch 'develop' into feature-2868/pull-slack-kudos-in
ocielliottc Feb 7, 2025
3874759
Persist the last import timestamp so that we can get messages posted …
ocielliottc Feb 10, 2025
173f552
Moved SlackSearch into the slack services directory.
ocielliottc Feb 10, 2025
8d2607d
Fixed test errors.
ocielliottc Feb 10, 2025
f72b174
Fixed incorrect column reference.
ocielliottc Feb 11, 2025
b4a0c91
Added a test for the slack kudos.
ocielliottc Feb 11, 2025
0e2b322
For testing purposes, the send date could be equal.
ocielliottc Feb 11, 2025
69f0655
Added a comment about slack message subtype and removed unused imports.
ocielliottc Feb 11, 2025
a6f5ff6
Merge branch 'develop' into feature-2868/pull-slack-kudos-in
ocielliottc Feb 17, 2025
918a1d0
No need to call the kudos creator if the message list is empty.
ocielliottc Feb 17, 2025
67c8df8
Switch from a scheduled task to being triggered when the check servic…
ocielliottc Feb 17, 2025
00cc1dd
Use the SlackReaderReplacement for the native test.
ocielliottc Feb 17, 2025
7a371a0
Skip messages posted by bot users too.
ocielliottc Feb 17, 2025
6a73655
Not all kudos being deleted are pending.
ocielliottc Feb 18, 2025
e5b8a96
Allow admins to edit approved kudos from the management screen.
ocielliottc Feb 18, 2025
602417d
Merge branch 'develop' into feature-2868/pull-slack-kudos-in
ocielliottc Feb 18, 2025
e1878b3
Merge branch 'develop' into feature-2868/pull-slack-kudos-in
ocielliottc Feb 18, 2025
f4aed83
Remove slack messages sent by our bot in the event that a user change…
ocielliottc Feb 18, 2025
515e513
Updated the test to match how slack messages are now sent.
ocielliottc Feb 18, 2025
11c2594
Updated github actions workflows to provide SLACK_KUDOS_CHANNEL_ID value
mkimberlin Feb 18, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/gradle-build-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
--set-env-vars "SLACK_PULSE_SIGNING_SECRET=${{ secrets.SLACK_PULSE_SIGNING_SECRET }}" \
--set-env-vars "SLACK_PULSE_BOT_TOKEN=${{ secrets.SLACK_PULSE_BOT_TOKEN }}" \
--set-env-vars "SLACK_KUDOS_CHANNEL_ID=${{ secrets.SLACK_KUDOS_CHANNEL_ID }}" \
--platform "managed" \
--max-instances 8 \
--allow-unauthenticated
1 change: 1 addition & 0 deletions .github/workflows/gradle-deploy-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ jobs:
--set-env-vars "SLACK_WEBHOOK_URL=${{ secrets.SLACK_WEBHOOK_URL }}" \
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
--set-env-vars "SLACK_SIGNING_SECRET=${{ secrets.SLACK_PULSE_SIGNING_SECRET }}" \
--set-env-vars "SLACK_KUDOS_CHANNEL_ID=${{ secrets.SLACK_KUDOS_CHANNEL_ID }}" \
--platform "managed" \
--max-instances 2 \
--allow-unauthenticated
1 change: 1 addition & 0 deletions .github/workflows/gradle-deploy-native-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ jobs:
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
--set-env-vars "SLACK_PULSE_SIGNING_SECRET=${{ secrets.SLACK_PULSE_SIGNING_SECRET }}" \
--set-env-vars "SLACK_PULSE_BOT_TOKEN=${{ secrets.SLACK_PULSE_BOT_TOKEN }}" \
--set-env-vars "SLACK_KUDOS_CHANNEL_ID=${{ secrets.SLACK_KUDOS_CHANNEL_ID }}" \
--platform "managed" \
--max-instances 2 \
--allow-unauthenticated
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public static class SlackConfig {

@NotBlank
private String signingSecret;

@NotBlank
private String kudosChannel;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.objectcomputing.checkins.notifications.social_media;

import com.objectcomputing.checkins.configuration.CheckInsConfiguration;

import com.slack.api.Slack;
import com.slack.api.methods.MethodsClient;
import com.slack.api.methods.request.chat.ChatPostMessageRequest;
import com.slack.api.methods.response.chat.ChatPostMessageResponse;
import com.slack.api.methods.request.chat.ChatDeleteRequest;
import com.slack.api.methods.response.chat.ChatDeleteResponse;
import com.slack.api.methods.request.conversations.ConversationsOpenRequest;
import com.slack.api.methods.response.conversations.ConversationsOpenResponse;

import jakarta.inject.Singleton;
import jakarta.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

@Singleton
public class SlackSender {
private static final Logger LOG = LoggerFactory.getLogger(SlackSender.class);

@Inject
private CheckInsConfiguration configuration;

public boolean send(List<String> userIds, String slackBlocks) {
// See if we have a token.
String token = configuration.getApplication()
.getSlack().getBotToken();
if (token != null && !slackBlocks.isEmpty()) {
MethodsClient client = Slack.getInstance().methods(token);

try {
ConversationsOpenResponse openResponse =
client.conversationsOpen(ConversationsOpenRequest.builder()
.users(userIds)
.returnIm(true)
.build());
if (!openResponse.isOk()) {
LOG.error("Unable to open the conversation");
return false;
}

return send(openResponse.getChannel().getId(), slackBlocks);
} catch(Exception ex) {
LOG.error("SlackSender.send: " + ex.toString());
return false;
}
} else {
LOG.error("Missing token or missing slack blocks");
return false;
}
}

public boolean send(String channelId, String slackBlocks) {
// See if we have a token.
String token = configuration.getApplication()
.getSlack().getBotToken();
if (token != null && !slackBlocks.isEmpty()) {
MethodsClient client = Slack.getInstance().methods(token);

try {
ChatPostMessageRequest request = ChatPostMessageRequest
.builder()
.channel(channelId)
.blocksAsString(slackBlocks)
.build();

// Send it to Slack
ChatPostMessageResponse response = client.chatPostMessage(request);

if (!response.isOk()) {
LOG.error("Unable to send the chat message: " +
response.getError());
}

return response.isOk();
} catch(Exception ex) {
LOG.error("SlackSender.send: " + ex.toString());
return false;
}
} else {
LOG.error("Missing token or missing slack blocks");
return false;
}
}

public boolean delete(String channel, String ts) {
// See if we have a token.
String token = configuration.getApplication()
.getSlack().getBotToken();
if (token != null) {
MethodsClient client = Slack.getInstance().methods(token);

try {
ChatDeleteRequest request = ChatDeleteRequest
.builder()
.channel(channel)
.ts(ts)
.build();

// Send it to Slack
ChatDeleteResponse response = client.chatDelete(request);

if (!response.isOk()) {
LOG.error("Unable to delete the chat message: " +
response.getError());
}

return response.isOk();
} catch(Exception ex) {
LOG.error("SlackSender.delete: " + ex.toString());
return false;
}
} else {
LOG.error("Missing token or missing slack blocks");
return false;
}
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.objectcomputing.checkins.services.kudos;

import com.objectcomputing.checkins.notifications.social_media.SlackSearch;
import com.objectcomputing.checkins.services.slack.SlackSearch;
import com.objectcomputing.checkins.services.kudos.kudos_recipient.KudosRecipientServices;
import com.objectcomputing.checkins.services.kudos.kudos_recipient.KudosRecipient;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
Expand All @@ -22,10 +22,6 @@

@Singleton
public class KudosConverter {
private record InternalBlock(
List<LayoutBlock> blocks
) {}

private final MemberProfileServices memberProfileServices;
private final KudosRecipientServices kudosRecipientServices;
private final SlackSearch slackSearch;
Expand Down Expand Up @@ -61,9 +57,8 @@ public String toSlackBlock(Kudos kudos) {
.elements(content).build();
RichTextBlock richTextBlock = RichTextBlock.builder()
.elements(List.of(element)).build();
InternalBlock block = new InternalBlock(List.of(richTextBlock));
Gson mapper = GsonFactory.createSnakeCase();
return mapper.toJson(block);
return mapper.toJson(List.of(richTextBlock));
}

private RichTextSectionElement.TextStyle boldItalic() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface KudosServices {

Kudos approve(Kudos kudos);

Kudos savePreapproved(KudosCreateDTO kudos);

List<KudosResponseDTO> getRecent();

KudosResponseDTO getById(UUID id);
Expand Down
Loading
Loading