-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a slack post containing the slack blocks that make up the Pulse…
… form.
- Loading branch information
1 parent
cf2a90b
commit e5938e1
Showing
6 changed files
with
235 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
server/src/main/java/com/objectcomputing/checkins/services/pulse/PulseSlackPoster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
158
server/src/main/resources/slack/pulse_slack_blocks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
] | ||
} |