本文整理汇总了Java中com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest类的典型用法代码示例。如果您正苦于以下问题:Java ChatPostMessageRequest类的具体用法?Java ChatPostMessageRequest怎么用?Java ChatPostMessageRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChatPostMessageRequest类属于com.github.seratch.jslack.api.methods.request.chat包,在下文中一共展示了ChatPostMessageRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendTextMessage
import com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest; //导入依赖的package包/类
private void sendTextMessage(String channel, String message) {
try {
Slack.getInstance().methods().chatPostMessage(
ChatPostMessageRequest.builder()
.token(slackToken)
.channel(channel)
.username(botData.getUser())
.asUser(false)
.text(message)
.iconUrl(getIconUrl())
.build()
);
}
catch (Exception e) {
e.printStackTrace();
}
}
示例2: _post
import com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest; //导入依赖的package包/类
private ChatPostMessageResponse _post(ChannelName channel, String text, List<Attachment> attachments, boolean asUser) throws IOException, SlackApiException {
if (apiToken.isPresent()) {
Optional<ChannelId> channelId = findChannelIdByName(channel);
if (channelId.isPresent()) {
return slack.methods().chatPostMessage(ChatPostMessageRequest.builder()
.token(apiToken.get().getValue())
.asUser(asUser)
.channel(channelId.get().getValue())
.text(text)
.attachments(attachments)
.build());
} else {
throw new IllegalStateException("Unknown channel: " + channel.getValue());
}
} else {
throw new IllegalStateException("apiToken is absent.");
}
}
示例3: sendGenericMessage
import com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest; //导入依赖的package包/类
private void sendGenericMessage(String channel, List<ResponseData> responseDatas) {
try {
List<com.github.seratch.jslack.api.model.Attachment> attachments = new ArrayList<>();
for (ResponseData data : responseDatas) {
Attachment.AttachmentBuilder attachmentBuilder = Attachment.builder();
attachmentBuilder.title(data.getTitle()).color(Colors.PRIMARY);
String footer = "";
if (data.getImage() != null) {
attachmentBuilder.thumbUrl(Utility.generateImageUrl(baseUrl, data.getImage()));
}
if (data.getText() != null) {
attachmentBuilder.text(processText(data.getText()));
}
attachmentBuilder.callbackId("dummy");
List<Action> actions = new ArrayList();
if (data.getButtons().size() > 0) {
for(ResponseData.Button button : data.getButtons()) {
switch (button.getButtonType()) {
case ResponseType.BUTTON_LINK:
footer += "<" + button.getUri() + "|" + button.getTitle() + ">\n";
break;
case ResponseType.BUTTON_PARAM:
actions.add(Action.builder().style(button.getSlackStyle()).name("dummy").type("button").text(button.getTitle()).value(button.getUri()).build());
break;
}
}
attachmentBuilder.actions(actions);
attachmentBuilder.footer(footer);
}
else if(data.getSmartReplies().size() > 0) {
for(ResponseData.SmartReply smartReply : data.getSmartReplies()) {
actions.add(Action.builder().style(smartReply.getSlackStyle()).name("dummy").type("button").text(smartReply.getTitle()).value(smartReply.getUri()).build());
}
}
if(data.getFields().size() > 0) {
List<Field> fields = new ArrayList<>();
for(ResponseData.Field field : data.getFields()) {
fields.add(Field.builder()
.title(field.getName())
.value(field.getFieldValue(Platform.SLACK))
.valueShortEnough(field.isShort()).build()
);
}
attachmentBuilder.fields(fields);
}
attachmentBuilder.actions(actions);
attachments.add(attachmentBuilder.build());
}
slack.methods().chatPostMessage(
ChatPostMessageRequest.builder()
.token(slackToken)
.channel(channel)
.username(botData.getUser())
.asUser(false)
.attachments(attachments)
.iconUrl(getIconUrl())
.build()
);
}
catch (Exception e) {
e.printStackTrace();
}
}
示例4: test
import com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest; //导入依赖的package包/类
@Test
public void test() throws IOException, SlackApiException {
String channel = slack.methods().channelsList(ChannelsListRequest.builder().token(token).excludeArchived(1).build())
.getChannels().get(0).getId();
ChatPostMessageResponse postMessage = slack.methods().chatPostMessage(ChatPostMessageRequest.builder()
.token(token)
.channel(channel)
.text("hello")
.build());
assertThat(postMessage.isOk(), is(true));
String timestamp = postMessage.getTs();
ReactionsAddResponse addResponse = slack.methods().reactionsAdd(ReactionsAddRequest.builder()
.token(token)
.name("smile")
.channel(channel)
.timestamp(timestamp)
.build());
assertThat(addResponse.isOk(), is(true));
ReactionsGetResponse getResponse = slack.methods().reactionsGet(ReactionsGetRequest.builder()
.token(token)
.channel(channel)
.timestamp(timestamp)
.build());
assertThat(getResponse.isOk(), is(true));
ReactionsRemoveResponse removeResponse = slack.methods().reactionsRemove(ReactionsRemoveRequest.builder()
.token(token)
.name("smile")
.channel(channel)
.timestamp(timestamp)
.build());
assertThat(removeResponse.isOk(), is(true));
}
示例5: postAMessageToGeneralChannel
import com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest; //导入依赖的package包/类
@Test
public void postAMessageToGeneralChannel() throws IOException, SlackApiException, InterruptedException {
// find all channels in the team
ChannelsListResponse channelsResponse = slack.methods().channelsList(ChannelsListRequest.builder().token(token).build());
assertThat(channelsResponse.isOk(), is(true));
// find #general
Channel general = channelsResponse.getChannels().stream()
.filter(c -> c.getName().equals("general")).findFirst().get();
// https://slack.com/api/chat.postMessage
ChatPostMessageResponse postResponse = slack.methods().chatPostMessage(ChatPostMessageRequest.builder()
.token(token)
.channel(general.getId())
.text("Hello World!")
.build());
assertThat(postResponse.isOk(), is(true));
// timestamp of the posted message
String messageTimestamp = postResponse.getMessage().getTs();
Thread.sleep(1000L);
ChatDeleteResponse deleteResponse = slack.methods().chatDelete(ChatDeleteRequest.builder()
.token(token)
.channel(general.getId())
.ts(messageTimestamp)
.build());
assertThat(deleteResponse.isOk(), is(true));
}