-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #732 from AbhiPwr/delegate_from_ac_to_im_handler
Feature: Delegate from AC Dialog to Intent Requesthandler
- Loading branch information
Showing
10 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
ask-sdk-core/lib/dispatcher/request/handler/DelegateToIntentHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
/* | ||
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import { Response, dialog, interfaces, Intent } from 'ask-sdk-model'; | ||
import { generateSlotsFromApiRequest, getRequestType } from '../../../util/RequestEnvelopeUtils'; | ||
import { CustomSkillRequestHandler } from './CustomSkillRequestHandler'; | ||
import { HandlerInput } from './HandlerInput'; | ||
|
||
import APIInvocationRequest = interfaces.conversations.APIInvocationRequest; | ||
import APIRequest = interfaces.conversations.APIRequest; | ||
|
||
const ACDL_AUTOGEN_NAMESPACE:string = "com.amazon.autogenerated"; | ||
const SPLIT_CHAR:string = "_"; | ||
|
||
export class DelegateToIntentHandler implements CustomSkillRequestHandler { | ||
|
||
canHandle(input : HandlerInput) : boolean { | ||
if (getRequestType(input.requestEnvelope) !== 'Dialog.API.Invoked') { | ||
return false; | ||
} | ||
if (!(input.requestEnvelope.request as APIInvocationRequest).apiRequest | ||
|| !(input.requestEnvelope.request as APIInvocationRequest).apiRequest.name) { | ||
return false; | ||
} | ||
const apiName: string = (input.requestEnvelope.request as APIInvocationRequest).apiRequest.name; | ||
if (!apiName.startsWith(ACDL_AUTOGEN_NAMESPACE)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
handle(input: HandlerInput): Response | Promise<Response> { | ||
const apiRequest:APIRequest = (input.requestEnvelope.request as APIInvocationRequest).apiRequest; | ||
const apiName: string = apiRequest.name; | ||
const intentName: string = (apiName.substring(apiName.indexOf(SPLIT_CHAR) + 1)); | ||
|
||
const directiveType: ('Dialog.DelegateRequest') = "Dialog.DelegateRequest"; | ||
const delegationTarget: string = "skill"; | ||
const updatedRequestType: ("Dialog.InputRequest" | "IntentRequest") = "IntentRequest"; | ||
const delegationPeriod:dialog.DelegationPeriod = { | ||
until: 'EXPLICIT_RETURN' | ||
}; | ||
|
||
const intent:Intent = { | ||
name: intentName, | ||
confirmationStatus: 'NONE', | ||
slots: generateSlotsFromApiRequest(apiRequest) | ||
}; | ||
const updatedRequest:dialog.UpdatedRequest = { | ||
type: updatedRequestType, | ||
intent | ||
}; | ||
const delegateRequestDirective:dialog.DelegateRequestDirective = { | ||
type: directiveType, | ||
target: delegationTarget, | ||
period: delegationPeriod, | ||
updatedRequest | ||
}; | ||
|
||
return input.responseBuilder.addDirective(delegateRequestDirective).getResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters