Search code examples
slack-api

Why I am unable to send message to the user via chat postMessage api?


We have application that integrates with Slack API and sends the messages via https://api.slack.com/methods/chat.postMessage Slack API. Recently this API started to failing to sent messages to users with error message: method_deprecated. I cannot find the reason why it's deprecated and stopped working in last month.

In order to sent message we use following:

            String userId = slackFacade.getUserId(recipientEmail);
            String channelId = slackFacade.getDirectChannelId(userId);

            slackFacade.postMessage(
                    Message.builder()
                            .channel(channelId)
                            .text(message)
                            .mrkdwn(true)
                            .attachment(attachment)
                            .build());

where slackFacade implementation looks like:

    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();
    }

Solution

  • I've found the root cause. Actually it was not problem with chat.postMessage but it was part of the changes related to imOpen API: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api