Skip to content

Reclaim contributions - all#166

Merged
szabowexler merged 30 commits intoHubSpot:masterfrom
reclaim-ai:master
Jun 2, 2020
Merged

Reclaim contributions - all#166
szabowexler merged 30 commits intoHubSpot:masterfrom
reclaim-ai:master

Conversation

@lightbody
Copy link
Copy Markdown
Contributor

Hey there - sorry I've been MIA the last few months. Just heads down with our startup and hadn't had a chance to circle back on a couple PRs, plus some new stuff I recently needed.

Rather than letting them linger in my fork for months and get behind, I'm dropping it all here as one PR so that worst case they are on the record. I'll see if I can submit separate ones for each individual improvement, but given my spotty record who knows 🤣

First, some notes about the two existing PRs that this one encapsulates:

PR #145 is here, but also with the move from HomeTabViewResponseIF to HomeTabViewResponse per the comment there by @szabowexler.

PR #134 is also here, with no meaningful changes. I haven't had a chance to resolved the question of testing. The issue I bumped into is that the existing tests in the suite, which I would normally crib from, seem to rely on serializing and deserializing and then comparing the JSON tree. The problem here is that BlockElementActionIF returns a String for getSelectedValue() but the actual JSON payload can sometimes be a string and other times be a complex object representing a "selected option". So the serialization going back ends up different, causing the test to fail. I haven't been able to spend enough time to come up with a more appropriate test for this class.

OK, and now the new stuff captured in here:

  • Three new events: SlackAppUninstalledEventIF, SlackTokensRevokedEventIF, TokensRevoked.
  • A change to StateActionValue to reflect the reality that the value can be something other than a string, depending on what blocks you submit. Without this change, the library will fail to parse the response of a modal submission that includes date or radio selections (and others). I needed date and radio blocks, so this patch includes added support for them, with tests.

Apologies for dumping them in a group like this. By far the biggest inhibitor to being a better contributor is my noob-level git skills. I hope to borrow a teammate in the coming days and enlist his help in breaking these out and squashing them into a single commit, but in the meantime I wanted to get this on the record.

By doing this, code can more easily extract the action_id from the payload without having to cast to every different block element type.

Sadly, all of them except for Image have it, preventing us from just having getActionId() on the root BlockElement class. But perhaps doing that and making it optional is another way to do this?
…payloads

Without this code, I was getting errors when Jackson tried to deserialize payloads that I had just sent containing initially selected options. The reason is that Jackson had no hints on how to deserialize the OptionOrOptionGroup shared interface. This resolves that, though likely not as elegant as it could be given the need to have two implementations, one for the raw class and one for when it is surrounded by Optional (for StaticSelectMenuIF).
Even though the Slack API docs say that when an user select's a menu, the interaction's value should arrive in the "value" field, I believe the docs are incorrect and reality is different.

Specifically, what I am seeing in the real world is that select menus will have their value arrive instead as a "selected_option" field. Thus, this deserializer will inspect for this field and pull the value from there if present.
# Conflicts:
#	slack-base/src/main/java/com/hubspot/slack/client/models/events/SlackEventType.java
# Conflicts:
#	slack-base/src/main/java/com/hubspot/slack/client/models/blocks/elements/ExternalMultiSelectMenuIF.java
#	slack-base/src/main/java/com/hubspot/slack/client/models/blocks/elements/StaticMultiSelectMenuIF.java
#	slack-base/src/main/java/com/hubspot/slack/client/models/blocks/elements/StaticSelectMenuIF.java
#	slack-base/src/main/java/com/hubspot/slack/client/models/blocks/json/OptionOrOptionGroupDeserializer.java
Even though the Slack API docs say that when an user select's a menu, the interaction's value should arrive in the "value" field, I believe the docs are incorrect and reality is different.

Specifically, what I am seeing in the real world is that select menus will have their value arrive instead as a "selected_option" field. Thus, this deserializer will inspect for this field and pull the value from there if present.
…payloads

Without this code, I was getting errors when Jackson tried to deserialize payloads that I had just sent containing initially selected options. The reason is that Jackson had no hints on how to deserialize the OptionOrOptionGroup shared interface. This resolves that, though likely not as elegant as it could be given the need to have two implementations, one for the raw class and one for when it is surrounded by Optional (for StaticSelectMenuIF).
…payloads

Without this code, I was getting errors when Jackson tried to deserialize payloads that I had just sent containing initially selected options. The reason is that Jackson had no hints on how to deserialize the OptionOrOptionGroup shared interface. This resolves that, though likely not as elegant as it could be given the need to have two implementations, one for the raw class and one for when it is surrounded by Optional (for StaticSelectMenuIF).
…ed out here: https://api.slack.com/legacy/interactive-message-field-guide#options_load_url

Specifically, it seems that this different payload is what is sent when using BlockKit + external select menus. These classes are useful for deserializing the alternative incoming payload.
@lightbody
Copy link
Copy Markdown
Contributor Author

I just added to this PR a few more things:

Alternative to InteractiveLoadOptionsRequestIF

An alternative set of classes for handling incoming callbacks for dynamic external select menus. It seems that the documentation here https://api.slack.com/legacy/interactive-message-field-guide#options_load_url is captured by InteractiveLoadOptionsRequestIF

But what I'm finding is that when interacting this type of element from BlockKit-based UI (views, modals, messages) I get a very different payload that is undocumented. The BlocksLoadOptionsRequestIF class is an attempt to ease serializing that alternative payload.

I raised this issue with Slack here: https://twitter.com/plightbo/status/1266113801390190592?s=21

Support for selected_date for BlockElementActionIF

One of the other patches in this PR includes selected_option, but now I needed selected_date, so this was added to BlockElementActionIF and the getSelectedValue() field (which was a required String) is now Optional because you can have a non-String payload (ex: LocalDate).

A couple tests

Some simple serialization tests for BlockElementActionIF selected_option and selected_date. I still need to add some tests for the new InteractiveLoadOptionsRequestIF class, but I'll wait until I hear if you're open to that contribution before bothering.

Copy link
Copy Markdown
Collaborator

@szabowexler szabowexler left a comment

Choose a reason for hiding this comment

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

honestly this looks fine. I'll just merge this in and we can deal with issues down the road.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants