Skip to content

Add Slack connect API support + tests#1089

Merged
seratch merged 9 commits intoslackapi:mainfrom
srajiang:sj-add-slack-connect-api
Aug 12, 2021
Merged

Add Slack connect API support + tests#1089
seratch merged 9 commits intoslackapi:mainfrom
srajiang:sj-add-slack-connect-api

Conversation

@srajiang
Copy link
Copy Markdown
Contributor

@srajiang srajiang commented Aug 12, 2021

Summary

Fixes #1058 by adding support for recently added Slack Connect AP methods.

  • conversations.acceptSharedInvite
  • conversations.approveSharedInvite
  • conversations.declineSharedInvite
  • conversations.inviteShared
  • conversations.listConnectInvites

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs-src (Documents, have you run ./docs.sh?)
  • /docs-src-v2 (Documents, have you run ./docs-v2.sh?)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements (place an x in each [ ])

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

@gitwave gitwave bot added the untriaged label Aug 12, 2021
@srajiang srajiang force-pushed the sj-add-slack-connect-api branch from c253296 to 9eae59a Compare August 12, 2021 01:18
@srajiang srajiang added enhancement M-T: A feature request for new functionality and removed untriaged labels Aug 12, 2021
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 12, 2021

Codecov Report

Merging #1089 (32663c5) into main (cbafdd1) will increase coverage by 0.11%.
The diff coverage is 97.53%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1089      +/-   ##
==========================================
+ Coverage   86.07%   86.19%   +0.11%     
==========================================
  Files         110      110              
  Lines        9847     9928      +81     
==========================================
+ Hits         8476     8557      +81     
  Misses       1371     1371              
Impacted Files Coverage Δ
slack_sdk/web/async_client.py 92.80% <92.59%> (-0.01%) ⬇️
slack_sdk/web/client.py 94.40% <100.00%> (+0.19%) ⬆️
slack_sdk/web/legacy_client.py 94.04% <100.00%> (+0.20%) ⬆️
slack_sdk/socket_mode/builtin/connection.py 36.13% <0.00%> (+0.42%) ⬆️
slack_sdk/socket_mode/builtin/client.py 79.86% <0.00%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbafdd1...32663c5. Read the comment docs.

@srajiang srajiang added this to the 3.10.0 milestone Aug 12, 2021
Copy link
Copy Markdown
Contributor

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few (early) comments. I hope these were helpful to you!

Comment on lines +1322 to +1323
channel_id: str = None,
invite_id: str = None,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know some existing methods (e.g., views_update) are not yet consistent about this but let's use Optional type hint for the value that can be None.

Suggested change
channel_id: str = None,
invite_id: str = None,
channel_id: Optional[str] = None,
invite_id: Optional[str] = None,

For existing others, we are happy to change the type hint this time! We don't call it a breaking change. It's a correction that does not affect runtime behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. I see that the type hint is another way of declaring a union type with None. I've included that for other existing methods that don't currently use the Optional type hint as well (including views_update) in the latest changes.

kwargs.update({"channel_id": channel_id})
else:
kwargs.update({"invite_id": invite_id})
return self.api_call("conversations.acceptSharedInvite", json=kwargs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no strong reason to use json request body here, let's use params for new ones. Although this method does not have any array arguments at this moment, we may encounter #1054 with future updates of the endpoint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context with #1054. I've modified acceptSharedInvite and approveSharedInvite to accept params instead.

@@ -0,0 +1,129 @@
import logging
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this file has only tests for Slack Connect APIs, how about naming it to test_conversations_connect.py? If we will have integration tests for other conversations.* endpoints in the future, we can have them in a different file.

invite_id=invite["invite_id"],
)

# clean up created channel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about having this part with if channel_id is not None: in finally clause? We can have a new local variable channel_id: Optional[str] outside the try/finally block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is much nicer - and we will always attempt to cleanup any channels in the course of the test. Thanks for the suggestion - I've included these changes!

Copy link
Copy Markdown
Contributor Author

@srajiang srajiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks always for the prompt feedback! I've included some updates based on that feedback.

Comment on lines +1322 to +1323
channel_id: str = None,
invite_id: str = None,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. I see that the type hint is another way of declaring a union type with None. I've included that for other existing methods that don't currently use the Optional type hint as well (including views_update) in the latest changes.

kwargs.update({"channel_id": channel_id})
else:
kwargs.update({"invite_id": invite_id})
return self.api_call("conversations.acceptSharedInvite", json=kwargs)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context with #1054. I've modified acceptSharedInvite and approveSharedInvite to accept params instead.

invite_id=invite["invite_id"],
)

# clean up created channel
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is much nicer - and we will always attempt to cleanup any channels in the course of the test. Thanks for the suggestion - I've included these changes!

@srajiang srajiang marked this pull request as ready for review August 12, 2021 17:21
@srajiang srajiang self-assigned this Aug 12, 2021
@srajiang srajiang requested review from seratch and stevengill August 12, 2021 17:28
Copy link
Copy Markdown
Contributor

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srajiang Finally comments before merging this!

def test_sync(self):
sender = self.sender_sync_client
receiver = self.receiver_sync_client
channel_id: Optional[str]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no assignment and we access the value in finally clause, it should raise an exception.

Suggested change
channel_id: Optional[str]
channel_id: Optional[str] = None

)

# For Slack Connect shared tests
SLACK_SDK_TEST_SENDER_BOT_TOKEN = "SLACK_SDK_TEST_SENDER_BOT_TOKEN"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these names more specific?

Suggested change
SLACK_SDK_TEST_SENDER_BOT_TOKEN = "SLACK_SDK_TEST_SENDER_BOT_TOKEN"
SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN = "SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN"

date: Optional[str] = None,
metadata_only: Optional[bool] = None,
**kwargs
**kwargs,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine to have these changes but, out of curiosity, do you use some code formatter that does this? I don't believe that you manually added these commas.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, these were added by the Python extension I have in my VSCode, it seems. But I kept it in there because it seemed better style to leave the trailing commas in there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks!

@seratch seratch modified the milestones: 3.10.0, 3.9.0 Aug 12, 2021
@seratch
Copy link
Copy Markdown
Contributor

seratch commented Aug 12, 2021

Probably, we can merge this PR soon. I've moved this one to v3.9 milestone.

@srajiang
Copy link
Copy Markdown
Contributor Author

Probably, we can merge this PR soon. I've moved this one to v3.9 milestone.

Thanks @seratch - I think it should be ready now with the last set of tweaks based on your last comments.

date: Optional[str] = None,
metadata_only: Optional[bool] = None,
**kwargs
**kwargs,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks!

@seratch seratch merged commit b2364d2 into slackapi:main Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality Version: 3x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new Slack Connect API methods

2 participants