Skip to content

Commit

Permalink
Added a slack post containing the slack blocks that make up the Pulse…
Browse files Browse the repository at this point in the history
… form.
  • Loading branch information
ocielliottc committed Jan 10, 2025
1 parent cf2a90b commit e5938e1
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import java.time.LocalDate;

public interface PulseServices {
public void sendPendingEmail(LocalDate now);
public void notifyUsers(LocalDate now);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ private class Frequency {
@Inject
private PulseEmail email;

@Inject
private PulseSlackPoster slackPoster;

private final DayOfWeek emailDay = DayOfWeek.MONDAY;

private String setting = "bi-weekly";
Expand All @@ -69,7 +72,7 @@ public PulseServicesImpl(
this.automatedEmailRepository = automatedEmailRepository;
}

public void sendPendingEmail(LocalDate check) {
public void notifyUsers(LocalDate check) {
if (check.getDayOfWeek() == emailDay) {
LOG.info("Checking for pending Pulse email");
// Start from the first of the year and move forward to ensure that we
Expand Down Expand Up @@ -103,6 +106,7 @@ public void sendPendingEmail(LocalDate check) {
if (sent.isEmpty()) {
LOG.info("Sending Pulse Email");
email.send();
slackPoster.send();
automatedEmailRepository.save(new AutomatedEmail(key));
} else {
LOG.info("The Pulse Email has already been sent today");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.objectcomputing.checkins.services.pulse;

import com.objectcomputing.checkins.configuration.CheckInsConfiguration;

import io.micronaut.http.HttpRequest;
import io.micronaut.http.client.BlockingHttpClient;
import io.micronaut.http.client.HttpClient;
import io.micronaut.context.annotation.Value;
import io.micronaut.core.io.Readable;
import io.micronaut.core.io.IOUtils;

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

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

import java.io.BufferedReader;

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

@Inject
private HttpClient slackClient;

@Inject
private CheckInsConfiguration configuration;

@Value("classpath:slack/pulse_slack_blocks.json")
private Readable pulseSlackBlocks;

public void send() {
String slackBlocks = getSlackBlocks();

// See if we can have a webhook URL.
String slackWebHook = configuration.getApplication()
.getPulseResponse()
.getSlack().getWebhookUrl();
if (slackWebHook != null && !slackBlocks.isEmpty()) {
// POST it to Slack.
BlockingHttpClient client = slackClient.toBlocking();
HttpRequest<String> request = HttpRequest.POST(slackWebHook,
slackBlocks);
client.exchange(request);
}
}

private String getSlackBlocks() {
try {
return IOUtils.readText(
new BufferedReader(pulseSlackBlocks.asReader()));

} catch(Exception ex) {
LOG.error(ex.toString());
return "";
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean sendScheduledEmails() {
req.setStatus("sent");
feedbackRequestRepository.update(req);
}
pulseServices.sendPendingEmail(today);
pulseServices.notifyUsers(today);
reviewPeriodServices.sendNotifications(today);
return true;
}
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/resources/slack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Slack Blocks

Place Slack Blocks jSON here.

### Micronaut Usage

```java
@Value("classpath:slack/filename.json")
private Readable slackBlocks;
```
158 changes: 158 additions & 0 deletions server/src/main/resources/slack/pulse_slack_blocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"type": "modal",
"title": {
"type": "plain_text",
"text": "Check-Ins Pulse",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "How are you feeling about work today?"
},
"accessory": {
"type": "radio_buttons",
"action_id": "internalScore",
"options": [
{
"value": "1",
"text": {
"type": "plain_text",
"text": "😦",
"emoji": true
}
},
{
"value": "2",
"text": {
"type": "plain_text",
"text": "🙁",
"emoji": true
}
},
{
"value": "3",
"text": {
"type": "plain_text",
"text": "😐",
"emoji": true
}
},
{
"value": "4",
"text": {
"type": "plain_text",
"text": "🙂",
"emoji": true
}
},
{
"value": "5",
"text": {
"type": "plain_text",
"text": "😀",
"emoji": true
}
}
]
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "internalFeelings",
"placeholder": {
"type": "plain_text",
"text": "Comment"
}
},
"label": {
"type": "plain_text",
"text": "Comment",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "How are you feeling about life outside of work?"
},
"accessory": {
"type": "radio_buttons",
"action_id": "externalScore",
"options": [
{
"value": "1",
"text": {
"type": "plain_text",
"text": "😦",
"emoji": true
}
},
{
"value": "2",
"text": {
"type": "plain_text",
"text": "🙁",
"emoji": true
}
},
{
"value": "3",
"text": {
"type": "plain_text",
"text": "😐",
"emoji": true
}
},
{
"value": "4",
"text": {
"type": "plain_text",
"text": "🙂",
"emoji": true
}
},
{
"value": "5",
"text": {
"type": "plain_text",
"text": "😀",
"emoji": true
}
}
]
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "externalFeelings",
"placeholder": {
"type": "plain_text",
"text": "Comment"
}
},
"label": {
"type": "plain_text",
"text": "Comment",
"emoji": true
}
}
]
}

0 comments on commit e5938e1

Please sign in to comment.