Skip to content

Commit e5938e1

Browse files
committed
Added a slack post containing the slack blocks that make up the Pulse form.
1 parent cf2a90b commit e5938e1

File tree

6 files changed

+235
-3
lines changed

6 files changed

+235
-3
lines changed

server/src/main/java/com/objectcomputing/checkins/services/pulse/PulseServices.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import java.time.LocalDate;
44

55
public interface PulseServices {
6-
public void sendPendingEmail(LocalDate now);
6+
public void notifyUsers(LocalDate now);
77
}

server/src/main/java/com/objectcomputing/checkins/services/pulse/PulseServicesImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ private class Frequency {
4747
@Inject
4848
private PulseEmail email;
4949

50+
@Inject
51+
private PulseSlackPoster slackPoster;
52+
5053
private final DayOfWeek emailDay = DayOfWeek.MONDAY;
5154

5255
private String setting = "bi-weekly";
@@ -69,7 +72,7 @@ public PulseServicesImpl(
6972
this.automatedEmailRepository = automatedEmailRepository;
7073
}
7174

72-
public void sendPendingEmail(LocalDate check) {
75+
public void notifyUsers(LocalDate check) {
7376
if (check.getDayOfWeek() == emailDay) {
7477
LOG.info("Checking for pending Pulse email");
7578
// Start from the first of the year and move forward to ensure that we
@@ -103,6 +106,7 @@ public void sendPendingEmail(LocalDate check) {
103106
if (sent.isEmpty()) {
104107
LOG.info("Sending Pulse Email");
105108
email.send();
109+
slackPoster.send();
106110
automatedEmailRepository.save(new AutomatedEmail(key));
107111
} else {
108112
LOG.info("The Pulse Email has already been sent today");
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.objectcomputing.checkins.services.pulse;
2+
3+
import com.objectcomputing.checkins.configuration.CheckInsConfiguration;
4+
5+
import io.micronaut.http.HttpRequest;
6+
import io.micronaut.http.client.BlockingHttpClient;
7+
import io.micronaut.http.client.HttpClient;
8+
import io.micronaut.context.annotation.Value;
9+
import io.micronaut.core.io.Readable;
10+
import io.micronaut.core.io.IOUtils;
11+
12+
import jakarta.inject.Singleton;
13+
import jakarta.inject.Inject;
14+
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
17+
18+
import java.io.BufferedReader;
19+
20+
@Singleton
21+
public class PulseSlackPoster {
22+
private static final Logger LOG = LoggerFactory.getLogger(PulseSlackPoster.class);
23+
24+
@Inject
25+
private HttpClient slackClient;
26+
27+
@Inject
28+
private CheckInsConfiguration configuration;
29+
30+
@Value("classpath:slack/pulse_slack_blocks.json")
31+
private Readable pulseSlackBlocks;
32+
33+
public void send() {
34+
String slackBlocks = getSlackBlocks();
35+
36+
// See if we can have a webhook URL.
37+
String slackWebHook = configuration.getApplication()
38+
.getPulseResponse()
39+
.getSlack().getWebhookUrl();
40+
if (slackWebHook != null && !slackBlocks.isEmpty()) {
41+
// POST it to Slack.
42+
BlockingHttpClient client = slackClient.toBlocking();
43+
HttpRequest<String> request = HttpRequest.POST(slackWebHook,
44+
slackBlocks);
45+
client.exchange(request);
46+
}
47+
}
48+
49+
private String getSlackBlocks() {
50+
try {
51+
return IOUtils.readText(
52+
new BufferedReader(pulseSlackBlocks.asReader()));
53+
54+
} catch(Exception ex) {
55+
LOG.error(ex.toString());
56+
return "";
57+
}
58+
}
59+
}
60+

server/src/main/java/com/objectcomputing/checkins/services/request_notifications/CheckServicesImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public boolean sendScheduledEmails() {
4141
req.setStatus("sent");
4242
feedbackRequestRepository.update(req);
4343
}
44-
pulseServices.sendPendingEmail(today);
44+
pulseServices.notifyUsers(today);
4545
reviewPeriodServices.sendNotifications(today);
4646
return true;
4747
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Slack Blocks
2+
3+
Place Slack Blocks jSON here.
4+
5+
### Micronaut Usage
6+
7+
```java
8+
@Value("classpath:slack/filename.json")
9+
private Readable slackBlocks;
10+
```
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"type": "modal",
3+
"title": {
4+
"type": "plain_text",
5+
"text": "Check-Ins Pulse",
6+
"emoji": true
7+
},
8+
"submit": {
9+
"type": "plain_text",
10+
"text": "Submit",
11+
"emoji": true
12+
},
13+
"close": {
14+
"type": "plain_text",
15+
"text": "Cancel",
16+
"emoji": true
17+
},
18+
"blocks": [
19+
{
20+
"type": "section",
21+
"text": {
22+
"type": "plain_text",
23+
"text": "How are you feeling about work today?"
24+
},
25+
"accessory": {
26+
"type": "radio_buttons",
27+
"action_id": "internalScore",
28+
"options": [
29+
{
30+
"value": "1",
31+
"text": {
32+
"type": "plain_text",
33+
"text": "😦",
34+
"emoji": true
35+
}
36+
},
37+
{
38+
"value": "2",
39+
"text": {
40+
"type": "plain_text",
41+
"text": "🙁",
42+
"emoji": true
43+
}
44+
},
45+
{
46+
"value": "3",
47+
"text": {
48+
"type": "plain_text",
49+
"text": "😐",
50+
"emoji": true
51+
}
52+
},
53+
{
54+
"value": "4",
55+
"text": {
56+
"type": "plain_text",
57+
"text": "🙂",
58+
"emoji": true
59+
}
60+
},
61+
{
62+
"value": "5",
63+
"text": {
64+
"type": "plain_text",
65+
"text": "😀",
66+
"emoji": true
67+
}
68+
}
69+
]
70+
}
71+
},
72+
{
73+
"type": "input",
74+
"element": {
75+
"type": "plain_text_input",
76+
"action_id": "internalFeelings",
77+
"placeholder": {
78+
"type": "plain_text",
79+
"text": "Comment"
80+
}
81+
},
82+
"label": {
83+
"type": "plain_text",
84+
"text": "Comment",
85+
"emoji": true
86+
}
87+
},
88+
{
89+
"type": "section",
90+
"text": {
91+
"type": "plain_text",
92+
"text": "How are you feeling about life outside of work?"
93+
},
94+
"accessory": {
95+
"type": "radio_buttons",
96+
"action_id": "externalScore",
97+
"options": [
98+
{
99+
"value": "1",
100+
"text": {
101+
"type": "plain_text",
102+
"text": "😦",
103+
"emoji": true
104+
}
105+
},
106+
{
107+
"value": "2",
108+
"text": {
109+
"type": "plain_text",
110+
"text": "🙁",
111+
"emoji": true
112+
}
113+
},
114+
{
115+
"value": "3",
116+
"text": {
117+
"type": "plain_text",
118+
"text": "😐",
119+
"emoji": true
120+
}
121+
},
122+
{
123+
"value": "4",
124+
"text": {
125+
"type": "plain_text",
126+
"text": "🙂",
127+
"emoji": true
128+
}
129+
},
130+
{
131+
"value": "5",
132+
"text": {
133+
"type": "plain_text",
134+
"text": "😀",
135+
"emoji": true
136+
}
137+
}
138+
]
139+
}
140+
},
141+
{
142+
"type": "input",
143+
"element": {
144+
"type": "plain_text_input",
145+
"action_id": "externalFeelings",
146+
"placeholder": {
147+
"type": "plain_text",
148+
"text": "Comment"
149+
}
150+
},
151+
"label": {
152+
"type": "plain_text",
153+
"text": "Comment",
154+
"emoji": true
155+
}
156+
}
157+
]
158+
}

0 commit comments

Comments
 (0)