Skip to content

Commit e783fd8

Browse files
committed
add ephemeral
1 parent 2318513 commit e783fd8

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

src/main/java/allbegray/slack/webapi/SlackWebApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public interface SlackWebApiConstants {
4343
String CHAT_POST_MESSAGE = "chat.postMessage";
4444
String CHAT_UPDATE = "chat.update";
4545
String CHAT_UNFURL = "chat.unfurl";
46+
String CHAT_POST_EPHEMERAL = "chat.postEphemeral";
4647

4748
// dnd
4849
String DND_END_DND = "dnd.endDnd";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package allbegray.slack.webapi.method.chats;
2+
3+
import allbegray.slack.exception.SlackException;
4+
import allbegray.slack.type.Attachment;
5+
import allbegray.slack.validation.ValidationError;
6+
import allbegray.slack.webapi.SlackWebApiConstants;
7+
import allbegray.slack.webapi.method.AbstractMethod;
8+
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
public class ChatPostEphemeral extends AbstractMethod {
16+
protected String channel;
17+
protected String user;
18+
protected String text;
19+
protected List<Attachment> attachments;
20+
21+
protected ObjectMapper mapper;
22+
23+
public ChatPostEphemeral(String channel, String user) {
24+
this.channel = channel;
25+
this.user = user;
26+
}
27+
28+
public void setText(String text) {
29+
this.text = text;
30+
}
31+
32+
public void setAttachments(List<Attachment> attachments) {
33+
this.attachments = attachments;
34+
}
35+
36+
public void addAttachment(Attachment attachment) {
37+
if (attachments == null) {
38+
attachments = new ArrayList<>();
39+
}
40+
attachments.add(attachment);
41+
}
42+
43+
@Override
44+
public String getMethodName() {
45+
return SlackWebApiConstants.CHAT_POST_EPHEMERAL;
46+
}
47+
48+
@Override
49+
public void validate(List<ValidationError> errors) {
50+
51+
}
52+
53+
@Override
54+
protected void createParameters(Map<String, String> parameters) {
55+
parameters.put("channel", channel);
56+
parameters.put("user", user);
57+
parameters.put("text", text);
58+
59+
if (attachments != null && !attachments.isEmpty()) {
60+
try {
61+
parameters.put("attachments", mapper.writeValueAsString(attachments));
62+
} catch (JsonProcessingException e) {
63+
throw new SlackException(e);
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)