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

✨Improvements for the Core platform #679

Merged
merged 5 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions docs/platforms/core-platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
);
```
1 change: 1 addition & 0 deletions examples/javascript/06_core/hello-world/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
},
Expand Down
1 change: 1 addition & 0 deletions examples/typescript/06_core/hello-world/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
},

Expand Down
9 changes: 6 additions & 3 deletions jovo-platforms/jovo-platform-core/src/ActionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
AudioActionData,
ProcessingActionData,
QuickReply,
QuickReplyActionData,
SpeechActionData,
} from './Interfaces';

Expand All @@ -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;
}

Expand Down
22 changes: 14 additions & 8 deletions jovo-platforms/jovo-platform-core/src/core/CorePlatformApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}