问题描述
我们有与 Slack API 集成并通过 https://api.slack.com/methods/chat.postMessage Slack API 发送消息的应用程序。最近此 API 开始无法向用户发送消息并显示错误消息:method_deprecated
。我找不到它在上个月被弃用并停止工作的原因。
为了发送消息,我们使用以下内容:
String userId = slackFacade.getUserId(recipientEmail);
String channelId = slackFacade.getDirectChannelId(userId);
slackFacade.postMessage(
Message.builder()
.channel(channelId)
.text(message)
.mrkdwn(true)
.attachment(attachment)
.build());
slackFacade 实现的样子:
public String getUserId(String email) throws SlackCommunicationException {
return logErrors(slackClient.getUserByEmail(email)).getUser().getId(); //users.lookupByEmail
}
public String getDirectChannelId(String userId) throws SlackCommunicationException {
return logErrors(slackClient.imOpen(userId)).getChannel().getId();
}
解决方法
我找到了根本原因。实际上,chat.postMessage 没有问题,但它是与 imOpen API 相关的更改的一部分: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api