slackapi / java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
https://slack.dev/java-slack-sdk/
MIT License
571 stars 212 forks source link

Fails to parse channel_email_addresses in admin.conversations.search API response #1212

Closed Dunkhell closed 11 months ago

Dunkhell commented 11 months ago

I'm using latest (1.32.1) version of the SDK, trying to list all pending invites for given team using slack method mentioned in the title. As long as the invite list is empty, the request works. It doesn't work when there's at least 1 pending invite.

The Slack SDK version

<dependency>
            <groupId>com.slack.api</groupId>
            <artifactId>slack-api-client</artifactId>
            <version>1.32.1</version>
        </dependency>

Java Runtime version

openjdk version "1.8.0_362"

Steps to reproduce:

  1. Create AdminConversationsSearchRequest
  2. Send request using Slack methods()
  3. Map result to AdminConversationsSearchResponse while having at least 1 channel with channelEmailAddresses set code ran:

    protected List<AdminConversationsSearchResponse.Conversation> searchConversationForTeam(String appId, List<String> teamIds) {
        log.info("Searching for conversations in {}", teamIds);
        AdminConversationsSearchRequest request = AdminConversationsSearchRequest.builder()
                .token(credentialProvider.getTokenForMethod(appId, SlackApiMethodCategory.LOOKUP_CHANNELS))
                .teamIds(teamIds)
                .searchChannelTypes(Collections.singletonList("exclude_archived"))
                .limit(10)
                .build();
    
        List<AdminConversationsSearchResponse.Conversation> result = new ArrayList<>();
        boolean isFirstPageFetched = false;
        RetryService retryService = new RetryService();
        do {
            try {
                AdminConversationsSearchResponse response = slack.methods().adminConversationsSearch(request);
                if (response.isOk()) {
                    log.info("Page fetches with {} items", response.getConversations().size());
                    log.info("Cursor {}", response.getNextCursor());
                    request.setCursor(response.getNextCursor());
                    result.addAll(response.getConversations());
                    isFirstPageFetched = true;
                } else {
                    retryService.handleError("searchConversationForTeam", response.getError());
                }
            } catch (IOException e) {
                retryService.handleError("searchConversationForTeam", e.getMessage());
            } catch (SlackApiException e) {
                retryService.handleError("searchConversationForTeam", e);
            }
        } while (!request.getCursor().isEmpty() || !isFirstPageFetched);
        return result;
    }

    Code contains custom exceptions and logging, which can be ignored since they do not result in the error

Expected result:

Returned value is a List of channelEmailAddresseswith correctly mapped values as per documentation

Actual result:

InviteRequests returned as List, resulting in error:

java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 5198 path $.conversations[1].channel_email_addresses[0]
seratch commented 11 months ago

@Dunkhell Thank you very much for taking the time to report this, and we apologize for the disruption with this SDK. We will release a new patch to resolve the issue shortly.

seratch commented 11 months ago

Version 1.32.2, which resolves this issue, is now available on the Maven Central repositories.