diff --git a/docs/platforms/core-platform/README.md b/docs/platforms/core-platform/README.md index 044381ef61..15ceaf104b 100644 --- a/docs/platforms/core-platform/README.md +++ b/docs/platforms/core-platform/README.md @@ -5,11 +5,13 @@ Learn more about the Jovo Core Platform, which can be used to deploy a voice exp ## Installation Install the integration into your project directory. + ```sh npm install jovo-platform-core --save ``` -Import the installed module, initialize and add it to the `app` object. +Import the installed module, initialize and add it to the `app` object. + ```javascript // @language=javascript @@ -114,64 +116,64 @@ this.$corePlatformApp?.$actions.addSpeech({ #### Adding Actions +Adds the given actions or actions of the given ActionBuilder. + ```javascript // @language=javascript if (this.$corePlatformApp) - this.$corePlatformApp.addActions({ - type: ActionType.Speech, - plain: 'plainText' - }); + this.$corePlatformApp.addActions(this.$corePlatformApp.$actions); // @language=typescript -this.$corePlatformApp?.addActions({ - type: ActionType.Speech, - plain: 'plainText' -}); +this.$corePlatformApp?.addActions(this.$corePlatformApp?.$actions); ``` #### Setting Actions +Sets the current actions to the given actions or to the actions of the given ActionBuilder. + +> **INFO** The actions generated for the speech of `tell` and `ask` will NOT be overwritten. + ```javascript // @language=javascript if (this.$corePlatformApp) - this.$corePlatformApp.setActions( - this.$actions.addSpeech({ plain: 'text' }).build() - ); + this.$corePlatformApp.setActions(this.$corePlatformApp.$actions); // @language=typescript -this.$corePlatformApp?.setActions( - this.$actions.addSpeech({ plain: 'text' }).build() -); +this.$corePlatformApp?.setActions(this.$corePlatformApp?.$actions); ``` #### Adding RepromptActions +Adds the given actions or actions of the given ActionBuilder. + ```javascript // @language=javascript if (this.$corePlatformApp) - this.$corePlatformApp.addRepromptActions({ - type: ActionType.Speech, - plain: 'plainText' - }); + this.$corePlatformApp.addRepromptActions( + this.$corePlatformApp.$repromptActions + ); // @language=typescript -this.$corePlatformApp?.addRepromptActions({ - type: ActionType.Speech, - plain: 'plainText' -}); +this.$corePlatformApp?.addRepromptActions( + this.$corePlatformApp?.$repromptActions +); ``` #### Setting RepromptActions +Sets the reprompt actions to the given actions or to the actions of the given ActionBuilder. + +> **INFO** The action generated for the reprompt of `ask` will NOT be overwritten. + ```javascript // @language=javascript if (this.$corePlatformApp) this.$corePlatformApp.setRepromptActions( - this.$repromptActions.addSpeech({ plain: 'text' }).build() + this.$corePlatformApp.$repromptActions ); // @language=typescript this.$corePlatformApp?.setRepromptActions( - this.$repromptActions.addSpeech({ plain: 'text' }).build() + this.$corePlatformApp?.$repromptActions ); ``` diff --git a/examples/javascript/06_core/hello-world/src/app.js b/examples/javascript/06_core/hello-world/src/app.js index 861ce76873..d69738d898 100644 --- a/examples/javascript/06_core/hello-world/src/app.js +++ b/examples/javascript/06_core/hello-world/src/app.js @@ -43,6 +43,7 @@ app.setHandler({ HelloWorldIntent() { if (this.$corePlatformApp) { this.$corePlatformApp.$actions.addQuickReplies(['John', 'Jack', 'Joe']); + this.$corePlatformApp.setActions(this.$corePlatformApp.$actions); } this.ask("Hello World! What's your name?", 'Please tell me your name.'); }, diff --git a/examples/typescript/06_core/hello-world/src/app.ts b/examples/typescript/06_core/hello-world/src/app.ts index 3bff43baf0..6270f05e20 100644 --- a/examples/typescript/06_core/hello-world/src/app.ts +++ b/examples/typescript/06_core/hello-world/src/app.ts @@ -31,6 +31,7 @@ app.setHandler({ HelloWorldIntent() { this.$corePlatformApp?.$actions.addQuickReplies(['Joe', 'Jane', 'Max']); + this.$corePlatformApp?.setActions(this.$corePlatformApp?.$actions); this.ask("Hello World! What's your name?", 'Please tell me your name.'); }, diff --git a/jovo-platforms/jovo-platform-core/src/ActionBuilder.ts b/jovo-platforms/jovo-platform-core/src/ActionBuilder.ts index 2ae63b10b3..05f147f586 100644 --- a/jovo-platforms/jovo-platform-core/src/ActionBuilder.ts +++ b/jovo-platforms/jovo-platform-core/src/ActionBuilder.ts @@ -4,7 +4,6 @@ import { AudioActionData, ProcessingActionData, QuickReply, - QuickReplyActionData, SpeechActionData, } from './Interfaces'; @@ -25,8 +24,12 @@ export class ActionBuilder { return this; } - addSpeech(data: SpeechActionData): ActionBuilder { - this.actions.push({ type: ActionType.Speech, ...data }); + addSpeech(data: SpeechActionData | string): ActionBuilder { + const action = + typeof data === 'string' + ? { type: ActionType.Speech, plain: data } + : { type: ActionType.Speech, ...data }; + this.actions.push(action); return this; } diff --git a/jovo-platforms/jovo-platform-core/src/core/CorePlatformApp.ts b/jovo-platforms/jovo-platform-core/src/core/CorePlatformApp.ts index e8abab8f89..377072d2ca 100644 --- a/jovo-platforms/jovo-platform-core/src/core/CorePlatformApp.ts +++ b/jovo-platforms/jovo-platform-core/src/core/CorePlatformApp.ts @@ -91,23 +91,29 @@ export class CorePlatformApp extends Jovo { } // Output methods - setActions(actions: Action[]): CorePlatformApp { - this.$output.CorePlatform.Actions = actions; + setActions(actions: Action[] | ActionBuilder): CorePlatformApp { + this.$output.CorePlatform.Actions = + actions instanceof ActionBuilder ? actions.build() : actions; return this; } - addActions(...actions: Action[]): CorePlatformApp { - this.$output.CorePlatform.Actions.push(...actions); + addActions(actions: Action[] | ActionBuilder): CorePlatformApp { + this.$output.CorePlatform.Actions.push( + ...(actions instanceof ActionBuilder ? actions.build() : actions), + ); return this; } - setRepromptActions(actions: Action[]): CorePlatformApp { - this.$output.CorePlatform.RepromptActions = actions; + setRepromptActions(actions: Action[] | ActionBuilder): CorePlatformApp { + this.$output.CorePlatform.RepromptActions = + actions instanceof ActionBuilder ? actions.build() : actions; return this; } - addRepromptActions(...actions: Action[]): CorePlatformApp { - this.$output.CorePlatform.RepromptActions.push(...actions); + addRepromptActions(actions: Action[] | ActionBuilder): CorePlatformApp { + this.$output.CorePlatform.RepromptActions.push( + ...(actions instanceof ActionBuilder ? actions.build() : actions), + ); return this; } }