繁体   English   中英

无法使用 Java 中的 slack api DM(发送直接消息)给单个用户(用户)

[英]Unable to DM (send direct message) to individual user (users) using slack api in Java

我正在尝试使用 Java 中的松弛 api 向单个用户发送消息,但我无法做到。 我尝试了各种方法,但没有任何帮助。 我可以将消息发送到频道,但不能直接发送给用户。

以下是我的代码 -

public void postToUsers() {

        var client = Slack.getInstance().methods();
        try {
            ChatPostMessageResponse response = Slack.getInstance().methods().chatPostMessage(r -> r
                    .token("xoxb-2850123307073-2837743345451-e3Y8y4cahtzeLAKIbjUHMMuC")
                    .channel("U02ABCGV9V")
                    .text("hello"));

            System.out.println("::::" + response.getMessage());
        } catch (NoSuchElementException noSuchElementException) {
            logger.error("No record for slack notification exists for id: " + id);
            );
        } catch (IOException | SlackApiException e) {
            logger.error("error: {}", e.getMessage(), e);
            e.printStackTrace();
            );
        }
    }

我没有发布给我在上面的频道中复制的用户 ID 的用户,而是在 slack 中看到应用程序名称下的消息。 我不确定发生了什么。 以下是我得到的回应 -

Message(type=message, subtype=null, team=T02R09Q9125, channel=null, user=U02QMMV6JD9, username=null, text=hello, blocks=null, attachments=null, ts=1639724593.000400, threadTs=null, intro=false, starred=false, wibblr=false, pinnedTo=null, reactions=null, botId=B02QF0PEFQE, botLink=null, displayAsBot=false, botProfile=BotProfile(id=B02QF0PEFQE, deleted=false, name=slack-notification-service, updated=1639470131, appId=A02Q72AKEFR, icons=BotProfile.Icons(image36=https://a.slack-edge.com/80588/img/plugins/app/bot_36.png, image48=https://a.slack-edge.com/80588/img/plugins/app/bot_48.png, image72=https://a.slack-edge.com/80588/img/plugins/app/service_72.png), teamId=T02R09Q9125), icons=null, file=null, files=null, upload=false, parentUserId=null, inviter=null, clientMsgId=null, comment=null, topic=null, purpose=null, edited=null, unfurlLinks=false, unfurlMedia=false, threadBroadcast=false, replies=null, replyCount=null, replyUsers=null, replyUsersCount=null, latestReply=null, subscribed=false, xFiles=null, lastRead=null, root=null, itemType=null, item=null)

通道为 null。

以下是我给出的范围以查看它是否有效,但它没有 -

在此处输入图像描述

首先必须创建对话: https://api.slack.com/methods/conversations.create

然后从字符串conversation(name)转换为conversationId(如果不知道),然后可以在直接消息中解决。 请参阅“选择正确的对话”。 The API has further methods: https://api.slack.com/docs/conversations-api#methods - even if the raw API isn't the Java client, it clearly shows what may be possible, no matter the client.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM