-
Notifications
You must be signed in to change notification settings - Fork 23
Description
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:
- Instead of directly instantiating the
ControlResponseBuilder
class inside ofControlHandler
, introduce an overridable method called something likecreateResponseBuilder()
. You could then subclass ControlHandler and override that function easily - 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