當前位置: 首頁>>代碼示例>>Java>>正文


Java Attachment類代碼示例

本文整理匯總了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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:22,代碼來源:ListRuleImpl.java

示例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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:17,代碼來源:ListRuleImpl.java

示例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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:19,代碼來源:BubbleRuleImpl.java

示例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;
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:17,代碼來源:SlackSendAttachmentFactoryImpl.java

示例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.");
    }
}
 
開發者ID:seratch,項目名稱:jslack,代碼行數:19,代碼來源:ShortcutImpl.java

示例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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:15,代碼來源:ImageRuleImpl.java

示例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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:11,代碼來源:AbstractSlackSendRuleImpl.java

示例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);
	}
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:9,代碼來源:ListRuleImpl.java

示例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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:15,代碼來源:VideoRuleImpl.java

示例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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:15,代碼來源:ButtonsRuleImpl.java

示例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();
    }
}
 
開發者ID:dbpedia,項目名稱:chatbot,代碼行數:70,代碼來源:SlackHandler.java

示例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);
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:6,代碼來源:BubbleRuleImpl.java

示例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();
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:5,代碼來源:SlackSendAttachmentFactoryImpl.java

示例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);
}
 
開發者ID:seratch,項目名稱:jslack,代碼行數:5,代碼來源:ShortcutImpl.java

示例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);
}
 
開發者ID:seratch,項目名稱:jslack,代碼行數:5,代碼來源:ShortcutImpl.java


注:本文中的com.github.seratch.jslack.api.model.Attachment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。