diff --git a/src/context.ts b/src/context.ts index 0e60d90..87512fa 100644 --- a/src/context.ts +++ b/src/context.ts @@ -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. * diff --git a/src/types.ts b/src/types.ts index 83161bc..6090fad 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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; diff --git a/test/context.test.ts b/test/context.test.ts index 136e936..48fa97a 100644 --- a/test/context.test.ts +++ b/test/context.test.ts @@ -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();