Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1857e1c
commit c6fa92d
Showing
15 changed files
with
444 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function CanHandleIntentRequest(...intentNames: string[]): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; |
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,26 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function CanHandleIntentRequest(...intentNames) { | ||
return function (target, key, descriptor) { | ||
const originalMethod = descriptor.value; | ||
descriptor.value = function (handlerInput) { | ||
const className = target.constructor.name; | ||
let possibleIntentNames = intentNames; | ||
if (possibleIntentNames.length === 0) { | ||
const modifiedClassName = className.replace('Handler', ''); | ||
possibleIntentNames = [className, modifiedClassName]; | ||
} | ||
const request = handlerInput.requestEnvelope.request; | ||
const intentName = request.intent.name; | ||
const canHandle = request.type === 'IntentRequest' && (possibleIntentNames.indexOf(intentName) > -1); | ||
// console.log(`CanHandleIntentRequest for '${className}' checks if '${intentName}' is in '${possibleIntentNames}' returns ${canHandle}`); | ||
if (canHandle === false) { | ||
return false; | ||
} | ||
const result = originalMethod.apply(this, arguments); | ||
return result; | ||
}; | ||
return descriptor; | ||
}; | ||
} | ||
exports.CanHandleIntentRequest = CanHandleIntentRequest; |
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 @@ | ||
export declare function CanHandleLaunchRequest(): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; |
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,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function CanHandleLaunchRequest() { | ||
return function (target, key, descriptor) { | ||
const originalMethod = descriptor.value; | ||
descriptor.value = function (handlerInput) { | ||
const canHandle = handlerInput.requestEnvelope.request.type === 'LaunchRequest'; | ||
// console.log(`CanHandleLaunchRequest for '${target.constructor.name}' checks if '${request.type}' equals 'LaunchRequest' returns ${canHandle}`); | ||
if (canHandle === false) { | ||
return false; | ||
} | ||
const result = originalMethod.apply(this, arguments); | ||
return result; | ||
}; | ||
return descriptor; | ||
}; | ||
} | ||
exports.CanHandleLaunchRequest = CanHandleLaunchRequest; |
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 @@ | ||
export declare function CanHandleSessionEndedRequest(): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; |
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,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function CanHandleSessionEndedRequest() { | ||
return function (target, key, descriptor) { | ||
const originalMethod = descriptor.value; | ||
descriptor.value = function (handlerInput) { | ||
const canHandle = handlerInput.requestEnvelope.request.type === 'SessionEndedRequest'; | ||
// console.log(`CanHandleSessionEndedRequest for '${target.constructor.name}' checks if '${request.type}' equals 'SessionEndedRequest' returns ${canHandle}`); | ||
if (canHandle === false) { | ||
return false; | ||
} | ||
const result = originalMethod.apply(this, arguments); | ||
return result; | ||
}; | ||
return descriptor; | ||
}; | ||
} | ||
exports.CanHandleSessionEndedRequest = CanHandleSessionEndedRequest; |
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,3 @@ | ||
export { CanHandleIntentRequest } from './decorators/CanHandleIntentRequest'; | ||
export { CanHandleLaunchRequest } from './decorators/CanHandleLaunchRequest'; | ||
export { CanHandleSessionEndedRequest } from './decorators/CanHandleSessionEndedRequest'; |
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,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var CanHandleIntentRequest_1 = require("./decorators/CanHandleIntentRequest"); | ||
exports.CanHandleIntentRequest = CanHandleIntentRequest_1.CanHandleIntentRequest; | ||
var CanHandleLaunchRequest_1 = require("./decorators/CanHandleLaunchRequest"); | ||
exports.CanHandleLaunchRequest = CanHandleLaunchRequest_1.CanHandleLaunchRequest; | ||
var CanHandleSessionEndedRequest_1 = require("./decorators/CanHandleSessionEndedRequest"); | ||
exports.CanHandleSessionEndedRequest = CanHandleSessionEndedRequest_1.CanHandleSessionEndedRequest; |
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 @@ | ||
export {}; |
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,231 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const index_1 = require("../../lib/index"); | ||
describe("CanHandleIntentRequest", () => { | ||
describe("with no params", () => { | ||
class TestIntentHandler { | ||
canHandle(handlerInput) { | ||
return true; | ||
} | ||
handle(handlerInput) { | ||
return {}; | ||
} | ||
} | ||
__decorate([ | ||
index_1.CanHandleIntentRequest(), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [Object]), | ||
__metadata("design:returntype", Boolean) | ||
], TestIntentHandler.prototype, "canHandle", null); | ||
describe("where request intent name matches handler class name", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'TestIntentHandler' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(true); | ||
}); | ||
}); | ||
describe("where request intent name does not match handler class name", () => { | ||
it("should return false", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'MismatchIntentHandler' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(false); | ||
}); | ||
}); | ||
describe("where request intent name matches handler class name minus handler suffix", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'TestIntent' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
describe("with one param", () => { | ||
class TestIntentHandler { | ||
canHandle(handlerInput) { | ||
return true; | ||
} | ||
handle(handlerInput) { | ||
return {}; | ||
} | ||
} | ||
__decorate([ | ||
index_1.CanHandleIntentRequest('MyIntent'), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [Object]), | ||
__metadata("design:returntype", Boolean) | ||
], TestIntentHandler.prototype, "canHandle", null); | ||
describe("where request intent name matches decorator intent name", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'MyIntent' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(true); | ||
}); | ||
}); | ||
describe("where request intent name does not matche decorator intent name", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'MismatchIntent' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(false); | ||
}); | ||
}); | ||
}); | ||
describe("with two params", () => { | ||
class TestIntentHandler { | ||
canHandle(handlerInput) { | ||
return true; | ||
} | ||
handle(handlerInput) { | ||
return {}; | ||
} | ||
} | ||
__decorate([ | ||
index_1.CanHandleIntentRequest('MyIntent1', "MyIntent2"), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [Object]), | ||
__metadata("design:returntype", Boolean) | ||
], TestIntentHandler.prototype, "canHandle", null); | ||
describe("where request intent name matches decorator first intent name", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'MyIntent1' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(true); | ||
}); | ||
}); | ||
describe("where request intent name matches decorator second intent name", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'MyIntent2' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(true); | ||
}); | ||
}); | ||
describe("where request intent name does not matche any decorator intent name", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'WrongIntent' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(false); | ||
}); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
export {}; |
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,67 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const index_1 = require("../../lib/index"); | ||
describe("CanHandleLaunchRequest", () => { | ||
class TestIntentHandler { | ||
canHandle(handlerInput) { | ||
return true; | ||
} | ||
handle(handlerInput) { | ||
return {}; | ||
} | ||
} | ||
__decorate([ | ||
index_1.CanHandleLaunchRequest(), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [Object]), | ||
__metadata("design:returntype", Boolean) | ||
], TestIntentHandler.prototype, "canHandle", null); | ||
describe("where request type is LaunchRequest", () => { | ||
it("should return true", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'LaunchRequest', | ||
requestId: '', | ||
timestamp: '', | ||
locale: '' | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(true); | ||
}); | ||
}); | ||
describe("where request is not LaunchRequest", () => { | ||
it("should return false", () => { | ||
const handlerInput = { | ||
requestEnvelope: { | ||
request: { | ||
type: 'IntentRequest', | ||
requestId: '', | ||
timestamp: '', | ||
dialogState: {}, | ||
locale: '', | ||
intent: { | ||
name: 'TestIntentHandler' | ||
} | ||
} | ||
} | ||
}; | ||
const handler = new TestIntentHandler(); | ||
const result = handler.canHandle(handlerInput); | ||
chai_1.expect(result).to.equal(false); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
export {}; |
Oops, something went wrong.