Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Allow extending functionality of ControlResponseBuilder #82

Open
volkipp opened this issue Aug 30, 2021 · 0 comments
Open

Feature - Allow extending functionality of ControlResponseBuilder #82

volkipp opened this issue Aug 30, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@volkipp
Copy link

volkipp commented Aug 30, 2021

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Currently there is no way to easily hook into the render() and build() phases of the ControlResponseBuilder. I would also like to add additional methods to be used by my Acts.

I would be willing to write the feature and submit a pull request with a little guidance on the approach you think is appropriate.

Possible Solution

A couple of different approaches I can think of are:

  1. Instead of directly instantiating the ControlResponseBuilder class inside of ControlHandler, introduce an overridable method called something like createResponseBuilder(). You could then subclass ControlHandler and override that function easily
  2. Introduce a responseBuilder factory inside ControlServices similar to how the logging service works.

Context

For my specific use-case, I am trying to accomplish a streamlined way to use APLA directives in much the same way as how regular promptFragments get joined together after all the controls and acts have been rendered right when a response is built. It is easy enough to create an APLA document which will support an array of custom JSON fragments, but it is difficult to do that currently within the controls framework without a lot of tight coupling between controls.

If I could use my own extended ControlResponseBuilder, it would give me a clean way to add that custom functionality. Here is basically what I am doing:

export class GameResponseBuilder extends ControlResponseBuilder {
  richAudioFragments: RichAudio[] = []

  addRichAudioFragment(richAudio: RichAudio | RichAudio[]) {
    richAudio = Array.isArray(richAudio) ? richAudio : [richAudio]
    this.richAudioFragments = this.richAudioFragments.concat(richAudio)
  }

  build(): Response {
    if (this.richAudioFragments.length > 0) {
      this.addDirective(createAPLADocument(this.richAudioFragments))
    }
    return super.build()
  }
}

Your Environment

  • ASK SDK Controls used: 0.7.0
@Shreyas-vgr Shreyas-vgr self-assigned this Sep 24, 2021
@Shreyas-vgr Shreyas-vgr added the enhancement New feature or request label Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants