Day 2:高效沟通
javaCopy Codeimport com.slack.api.Slack;
import com.slack.api.methods.MethodsClient;
import com.slack.api.methods.request.chat.ChatPostMessageRequest;
import com.slack.api.methods.response.chat.ChatPostMessageResponse;
import com.slack.api.model.block.LayoutBlock;
import java.io.IOException;
import java.util.Collections;
public class SlackNotifier {
public static void main(String[] args) throws IOException {
String slackBotToken = "YOUR_SLACK_BOT_TOKEN";
MethodsClient methods = Slack.getInstance().methods(slackBotToken);
ChatPostMessageRequest request = ChatPostMessageRequest.builder()
.channel("#general")
.text("大家好!今天的进展如何?")
.blocks(Collections.<LayoutBlock>emptyList())
.build();
ChatPostMessageResponse response = methods.chatPostMessage(request);
if (response.isOk()) {
System.out.println("已发送消息: " + response.getTs());
} else {
System.err.println("发送消息失败: " + response.getError());
}
}
}
标签:slack,冲刺,api,import,com,response,methods From: https://www.cnblogs.com/2574999647wyx/p/17473078.html