本文整理匯總了Java中com.github.seratch.jslack.api.model.Attachment類的典型用法代碼示例。如果您正苦於以下問題:Java Attachment類的具體用法?Java Attachment怎麽用?Java Attachment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Attachment類屬於com.github.seratch.jslack.api.model包,在下文中一共展示了Attachment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addListElementAttachment
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
protected void addListElementAttachment(final ListSendElement listSendElement, final List<Attachment> attachments) {
final AbstractSendButton button = listSendElement.getButton();
final Attachment result;
if (button != null) {
result = slackSendAttachmentFactory.createAttachment(button);
final boolean isWebButton = AbstractSendButton.Type.WEB_BUTTON.equals(button.getType());
if (isWebButton) {
final String title = listSendElement.getTitle() + ": " + button.getTitle();
result.setTitle(title);
}
} else {
result = Attachment.builder().title(listSendElement.getTitle()).build();
}
result.setText(listSendElement.getSubTitle());
result.setImageUrl(listSendElement.getImageUrl());
attachments.add(result);
}
示例2: apply
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public void apply(final SendMessage sendMessage) {
final ListSendPayload listSendPayload = sendMessage.getPayloadWithType(ListSendPayload.class);
final List<Attachment> attachments = new ArrayList<Attachment>();
for (final ListSendElement listSendElement : listSendPayload.getListElements()) {
addListElementAttachment(listSendElement, attachments);
}
addListAttachment(listSendPayload, attachments);
final String channel = sendMessage.getRecipient().getId();
final String text = listSendPayload.getTitle();
final Payload payload = Payload.builder().channel(channel).text(text).attachments(attachments).build();
chatPostMessage(sendMessage, payload);
}
示例3: apply
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public void apply(final SendMessage sendMessage) {
final BubbleSendPayload bubbleSendPayload = sendMessage.getPayloadWithType(BubbleSendPayload.class);
final Bubble bubble = bubbleSendPayload.getBubbles().get(0);
final List<Attachment> attachments = new ArrayList<Attachment>();
addHeader(bubble, attachments);
for (final AbstractSendButton button : bubble.getButtons()) {
attachments.add(slackSendAttachmentFactory.createAttachment(button));
}
final String channel = sendMessage.getRecipient().getId();
final String text = bubble.getTitle();
final Payload payload = Payload.builder().channel(channel).text(text).attachments(attachments).build();
chatPostMessage(sendMessage, payload);
}
示例4: createAttachment
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public Attachment createAttachment(final AbstractSendButton button) {
final Attachment result;
switch (button.getType()) {
case POSTBACK_BUTTON:
result = createPostbackButton((PostbackSendButton) button);
break;
case WEB_BUTTON:
default:
result = createWebButton((WebSendButton) button);
break;
}
return result;
}
示例5: _post
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的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.");
}
}
示例6: apply
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public void apply(final SendMessage sendMessage) {
final ImageSendPayload imageSendPayload = sendMessage.getPayloadWithType(ImageSendPayload.class);
final String title = imageSendPayload.getTitle();
final String imageUrl = imageSendPayload.getImageUrl();
final Attachment attachment = Attachment.builder().fallback(title).imageUrl(imageUrl).build();
final List<Attachment> attachments = Lists.newArrayList(attachment);
final String channel = sendMessage.getRecipient().getId();
final Payload payload = Payload.builder().channel(channel).attachments(attachments).build();
chatPostMessage(sendMessage, payload);
}
示例7: chatPostMessage
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
protected void chatPostMessage(final SendMessage sendMessage, final Payload payload) {
final String channel = payload.getChannel();
final String username = payload.getUsername();
final String text = payload.getText();
final List<Attachment> attachments = payload.getAttachments();
LOG.info("sending with username {} to channel {} payload {}", username, channel, payload);
chatPostMessage(sendMessage, channel, username, text, attachments);
}
示例8: addListAttachment
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
protected void addListAttachment(final ListSendPayload listSendPayload, final List<Attachment> attachments) {
final AbstractSendButton button = listSendPayload.getButton();
if (button != null) {
final Attachment result = slackSendAttachmentFactory.createAttachment(button);
attachments.add(result);
}
}
示例9: apply
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public void apply(final SendMessage sendMessage) {
final VideoSendPayload videoSendPayload = sendMessage.getPayloadWithType(VideoSendPayload.class);
final String title = videoSendPayload.getTitle();
final String videoUrl = videoSendPayload.getVideoUrl();
final Attachment attachment = Attachment.builder().fallback(title).imageUrl(videoUrl).build();
final List<Attachment> attachments = Lists.newArrayList(attachment);
final String channel = sendMessage.getRecipient().getId();
final Payload payload = Payload.builder().channel(channel).attachments(attachments).build();
chatPostMessage(sendMessage, payload);
}
示例10: apply
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public void apply(final SendMessage sendMessage) {
final ButtonsSendPayload buttonsSendPayload = sendMessage.getPayloadWithType(ButtonsSendPayload.class);
final List<Attachment> attachments = new ArrayList<Attachment>();
for (final AbstractSendButton sendButton : buttonsSendPayload.getButtons()) {
final Attachment attachment = slackSendAttachmentFactory.createAttachment(sendButton);
attachments.add(attachment);
}
final String channel = sendMessage.getRecipient().getId();
final Payload payload = Payload.builder().channel(channel).attachments(attachments).build();
chatPostMessage(sendMessage, payload);
}
示例11: sendGenericMessage
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的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();
}
}
示例12: addHeader
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
protected void addHeader(final Bubble bubble, final List<Attachment> attachments) {
final Attachment attachment = Attachment.builder().title(bubble.getTitle()).titleLink(bubble.getUrl())
.fallback(bubble.getTitle()).imageUrl(bubble.getImageUrl()).build();
attachments.add(attachment);
}
示例13: createWebButton
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
protected Attachment createWebButton(final WebSendButton webSendButton) {
return Attachment.builder().title(webSendButton.getTitle()).titleLink(webSendButton.getUrl())
.fallback(webSendButton.getTitle()).build();
}
示例14: post
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public ChatPostMessageResponse post(ChannelName channel, String text, List<Attachment> attachments) throws IOException, SlackApiException {
return _post(channel, text, attachments, true);
}
示例15: postAsBot
import com.github.seratch.jslack.api.model.Attachment; //導入依賴的package包/類
@Override
public ChatPostMessageResponse postAsBot(ChannelName channel, String text, List<Attachment> attachments) throws IOException, SlackApiException {
return _post(channel, text, attachments, false);
}