当前位置: 首页>>代码示例>>Java>>正文


Java ChatPostMessageRequest类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:18,代码来源:SlackHandler.java

示例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.");
    }
}
 
开发者ID:seratch,项目名称:jslack,代码行数:19,代码来源:ShortcutImpl.java

示例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();
    }
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:70,代码来源:SlackHandler.java

示例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));

}
 
开发者ID:seratch,项目名称:jslack,代码行数:38,代码来源:Slack_reactions_Test.java

示例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));
}
 
开发者ID:seratch,项目名称:jslack,代码行数:31,代码来源:ExamplesTest.java


注:本文中的com.github.seratch.jslack.api.methods.request.chat.ChatPostMessageRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。