From 060e0852408dac26d9fe003ef927237b5882b34e Mon Sep 17 00:00:00 2001 From: mochan-tk Date: Mon, 3 Sep 2018 12:05:36 +0000 Subject: [PATCH 1/2] Add_setSimpleReprompt --- src/context.ts | 23 +++++++++++++++++++++++ src/types.ts | 1 + test/context.test.ts | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/context.ts b/src/context.ts index 0e60d90..e5ffdec 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.OutputSpeech; + 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(); From ce3d4a1fe0e53b1484737ac98647ea7902e0abbe Mon Sep 17 00:00:00 2001 From: mochan-tk Date: Tue, 18 Sep 2018 11:52:51 +0000 Subject: [PATCH 2/2] modify type of outputSpeech variable --- src/context.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context.ts b/src/context.ts index e5ffdec..87512fa 100644 --- a/src/context.ts +++ b/src/context.ts @@ -120,7 +120,7 @@ export class Context implements Clova.ClientContext { * @memberOf Context */ public setSimpleReprompt(speechInfo: Clova.SpeechInfoObject | Clova.SpeechInfoObject[]): void { - let outputSpeech : Clova.OutputSpeech; + let outputSpeech : Clova.OutputSpeechSimple | Clova.OutputSpeechList; if (Array.isArray(speechInfo)) { outputSpeech = { type: 'SpeechList',