Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Add_setSimpleReprompt #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ export class Context implements Clova.ClientContext {
this.responseObject.response.reprompt = { outputSpeech };
}

/**
* Set simple reprompt content
*
* @param {Clova.SpeechInfoObject | Clova.SpeechInfoObject[]} speechInfo
* @memberOf Context
*/
public setSimpleReprompt(speechInfo: Clova.SpeechInfoObject | Clova.SpeechInfoObject[]): void {
let outputSpeech : Clova.OutputSpeechSimple | Clova.OutputSpeechList;
if (Array.isArray(speechInfo)) {
outputSpeech = {
type: 'SpeechList',
values: speechInfo,
};
} else {
outputSpeech = {
type: 'SimpleSpeech',
values: speechInfo,
};
}

this.setReprompt(outputSpeech);
}

/**
* Set SimpleSpeech object for outputSpeech content.
*
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ declare namespace Clova {
getSessionAttributes(): object;
setSessionAttributes(sessionAttributes: object): void;
setReprompt(outputSpeech: OutputSpeech): void;
setSimpleReprompt(speechInfo: SpeechInfoObject | SpeechInfoObject[]): void;
}

export type Middleware = (req: express.Request, res: express.Response, next: express.NextFunction) => void;
Expand Down
22 changes: 22 additions & 0 deletions test/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ describe('Clova Skill Client Context: LaunchRequest', () => {
expect(responseObject.response.reprompt.outputSpeech).toEqual(speechObject);
});

it('should set speech reprompt for response object', () => {
const speechInfo: Clova.SpeechInfoObject = SpeechBuilder.createSpeechText('こんにちは');
const speechObject: Clova.OutputSpeechSimple = {
type: 'SimpleSpeech',
values: speechInfo,
};

context.setSimpleReprompt(speechInfo);
expect(responseObject.response.reprompt.outputSpeech).toEqual(speechObject);
});

it('should set speech list reprompt for response object', () => {
const speechInfo: Clova.SpeechInfoObject[] = [SpeechBuilder.createSpeechText('こんにちは')];
const speechObject: Clova.OutputSpeechList = {
type: 'SpeechList',
values: speechInfo,
};

context.setSimpleReprompt(speechInfo);
expect(responseObject.response.reprompt.outputSpeech).toEqual(speechObject);
});

it('should set shouldEndSession for response object', () => {
context.endSession();
expect(responseObject.response.shouldEndSession).toBeTruthy();
Expand Down