为什么 Slack.getInstance().send API 不能按预期工作?

问题描述

我正在使用 Slack API for Java 向频道发送 FYI。这是我的专家所拥有的:

<dependency>

            <groupId>com.slack.api</groupId>

            <artifactId>slack-api-client</artifactId>

            <version>1.5.0</version>

</dependency>

我正在使用一个简单的 Spring Boot Server 应用程序,该应用程序使用 servlet,取自 github 中的示例。

成功处理 authredirect 后,我​​的服务器会收到一个 Webhook URL(在 Slack 的文档中指定)。 我正在尝试使用 Slack 的 send() API 向此 Webhook 发送消息(在安装了我的 Slack 应用程序(我们称之为 Slapp)的频道中。

@GetMapping(value = "/authredirect")

public httpentity<?> handleAuthRedirection(@RequestParam("code") String codePassed,@RequestParam("state") String statePassed) throws JsonProcessingException,JsonMappingException {

  // The Oauth2 flow happens here. What I receive finally,among other things,are...
  // Note: I have skipped construction,assignments,etc.  

 unjsonifiedResponseFromSlackV2.getAppID(),unjsonifiedResponseFromSlackV2.getScopesAllowed(),unjsonifiedResponseFromSlackV2.getTokenType(),unjsonifiedResponseFromSlackV2.getBotUserID(),unjsonifiedResponseFromSlackV2.getTeamFromSlack().getTeamName(),unjsonifiedResponseFromSlackV2.getSlackWebhookURLDetails().getChannel(),unjsonifiedResponseFromSlackV2.getSlackWebhookURLDetails().getChannelID(),unjsonifiedResponseFromSlackV2.getSlackWebhookURLDetails().getConfigurationURL(),unjsonifiedResponseFromSlackV2.getSlackWebhookURLDetails().getWebhookURL(),// I want to use this webhookURL for posting something to the channel. So,...

var frequencyChoiceHelperTask = CompletableFuture
        .supplyAsync(
                () -> askForPreferredFrequency(slackAuthenticatedUserDetails),CompletableFuture.delayedExecutor(10,TimeUnit.SECONDS,this.zapierPusher)
        )
        .thenAccept(e -> System.out.println(e.get().getCode()));

// Of course,return to Slack dutifully ..

return new httpentity<>("AckNowledged by 1Huddle. Please contact 1Huddle support to set up your company-specific token!");

}

这是上面调用函数体,在 CompletableFuture 中:

private Option<WebhookResponse> askForPreferredFrequency(SlackAuthenticatedUserDetails slackAuthenticatedUserDetails) {

 var k = Try.
        of(() -> {
                 var resp = this.slackhandler.send(
                            slackAuthenticatedUserDetails.webhookURL,payload(p -> p
                                         .text("Just wanted to say Hello.")
  ));
                    return (resp);
                }
        )
        .onFailure(e -> System.out.println("Posting to webhook [" + slackAuthenticatedUserDetails.webhookURL + "] fails,reason = [" + e.getMessage() + "]"))
        .onSuccess(resp -> System.out.println("Posting to webhook [" + slackAuthenticatedUserDetails.webhookURL + "] succeeds,with [" + resp.getMessage()));

        return (k.isFailure() ? Option.none() : Option.some(k.get()));
}

确认消息显示正常,在 Slapp 的安装网页上。

enter image description here

Slack 也同意 Slapp 已安装!

enter image description here

现在,我的日志显示 send() 调用正常:

About to send buttons useing webhookURL = [https://hooks.slack.com/services/YYYYYYYY/ddddddddD/higglypiggly] .....

但是,频道上没有显示任何内容。我的日志中也没有错误消息。

当我尝试通过 cURL 向该 webhook URL 发送消息时,它可以工作。

所以,我很困惑。我看不出哪里出错了。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)