alexa-ability
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -36,2 +36,4 @@ 'use strict'; | ||
var _verifyApplication = require('./verifyApplication'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -43,5 +45,12 @@ | ||
var cLog = (0, _debug2.default)('alexa-ability:ability:constructor'); | ||
var uLog = (0, _debug2.default)('alexa-ability:ability:use'); | ||
var oLog = (0, _debug2.default)('alexa-ability:ability:on'); | ||
var hLog = (0, _debug2.default)('alexa-ability:ability:handle'); | ||
var warnAppId = function warnAppId() { | ||
return console.warn( // eslint-disable-line no-console | ||
'No "applicationId" provided, request may come from unauthorized sources'); | ||
}; | ||
var warnSent = function warnSent() { | ||
@@ -61,2 +70,9 @@ return console.warn( // eslint-disable-line no-console | ||
this._handlers = _extends({}, _defaultHandlers.handlers); | ||
if (options.applicationId) { | ||
cLog('adding verifyApplication middleware'); | ||
this.use((0, _verifyApplication.verifyApplication)(options.applicationId)); | ||
} else { | ||
warnAppId(); | ||
} | ||
} | ||
@@ -63,0 +79,0 @@ |
@@ -59,4 +59,4 @@ 'use strict'; | ||
key: 'say', | ||
value: function say(content) { | ||
this._res.outputSpeech = toSpeechResponse(content); | ||
value: function say(type, value) { | ||
this._res.outputSpeech = toSpeechResponse(type, value); | ||
return this; | ||
@@ -76,5 +76,5 @@ } | ||
key: 'reprompt', | ||
value: function reprompt(content) { | ||
value: function reprompt(type, value) { | ||
this._res.reprompt = { | ||
outputSpeech: toSpeechResponse(content) | ||
outputSpeech: toSpeechResponse(type, value) | ||
}; | ||
@@ -120,6 +120,8 @@ return this; | ||
function toSpeechResponse(content) { | ||
var isTag = (0, _get2.default)(content, 'tag'); | ||
function toSpeechResponse(_type, _content) { | ||
var type = _content === undefined ? undefined : _type; | ||
var content = _content === undefined ? _type : _content; | ||
var isTag = !!(0, _get2.default)(content, 'tag'); | ||
return isTag ? { type: 'SSML', ssml: (0, _alexaSsml.renderToString)(content) } : { type: 'PlainText', text: content }; | ||
return isTag || type === 'ssml' ? { type: 'SSML', ssml: isTag ? (0, _alexaSsml.renderToString)(content) : content } : { type: 'PlainText', text: content }; | ||
} |
{ | ||
"name": "alexa-ability", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "An Alexa skills framework for node", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -14,3 +14,5 @@ # alexa-ability [![Build Status](https://travis-ci.org/nickclaw/alexa-ability.svg?branch=master)](https://travis-ci.org/nickclaw/alexa-ability) | ||
const app = new Ability(); | ||
const app = new Ability({ | ||
applicationId: 'my-application-id' | ||
}); | ||
@@ -53,3 +55,6 @@ app.use(function(req, next) { | ||
##### `new Ability(options) -> ability` | ||
Create a new ability. The options object supports the following properties: | ||
* `applicationId` - Defaults to `undefined`, but if included, only allows requests that have a matching `applicationId`. | ||
##### `Ability.prototype.use(handler) -> ability` | ||
@@ -126,4 +131,6 @@ Add middleware to the ability. Middleware will be called in the order added. Each middleware function will be called with a request instance as the first argument and a "next" function that must be called when the middleware is finished. | ||
##### `request.say(text|ssml) -> request` | ||
Indicate the speech to return to the user. | ||
##### `request.say([type, ] value) -> request` | ||
Indicate the speech to return to the user. Type can be `"text"` or `"ssml"`. | ||
If you omit the type argument, the value will be assumed to `"text"` if a string, | ||
or `"ssml"` if an [alexa-ssml](https://github.com/nickclaw/alexa-ssml) object. | ||
@@ -133,5 +140,7 @@ ##### `request.show(title, content) -> request` | ||
##### `request.reprompt(text|ssml) -> request` | ||
##### `request.reprompt([type, ] value) -> request` | ||
Indicate the reprompt speech to say to the user. | ||
This will only be used if the your service keeps the session open after sending the response, but the user does not respond with anything that maps to an intent. | ||
This will only be used if the your service keeps the session open after sending the response, but the user does not respond with anything that maps to an intent. Type can be `"text"` or `"ssml"`. | ||
If you omit the type argument, the value will be assumed to `"text"` if a string, | ||
or `"ssml"` if an [alexa-ssml](https://github.com/nickclaw/alexa-ssml) object. | ||
@@ -138,0 +147,0 @@ If this is not set, the user is not re-prompted. |
@@ -14,5 +14,22 @@ import noop from 'lodash/noop'; | ||
beforeEach(function() { | ||
app = new Ability(); | ||
app = new Ability({ | ||
applicationId: launchRequest.session.application.applicationId | ||
}); | ||
}); | ||
describe('"constructor"', function() { | ||
it('should return an instanceof Ability', function() { | ||
const ability = new Ability({ applicationId: "foo" }); | ||
expect(ability).to.be.instanceOf(Ability); | ||
}); | ||
it('should warn if no applicationId is provided', function() { | ||
const _oldWarn = console.warn; | ||
console.warn = sinon.spy(_oldWarn); | ||
const ability = new Ability(); | ||
expect(console.warn).to.have.been.called; | ||
console.warn = _oldWarn; | ||
}); | ||
}); | ||
describe('"use" function', function() { | ||
@@ -19,0 +36,0 @@ it('should throw if not passed a function', function() { |
@@ -1,1 +0,26 @@ | ||
{} | ||
{ | ||
"version": "1.0", | ||
"session": { | ||
"new": false, | ||
"sessionId": "amzn1.echo-api.session.0000000-0000-0000-0000-00000000000", | ||
"application": { | ||
"applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe" | ||
}, | ||
"attributes": { | ||
"supportedHoroscopePeriods": { | ||
"daily": true, | ||
"weekly": false, | ||
"monthly": false | ||
} | ||
}, | ||
"user": { | ||
"userId": "amzn1.account.AM3B00000000000000000000000" | ||
} | ||
}, | ||
"request": { | ||
"type": "Unknown", | ||
"requestId": "amzn1.echo-api.request.0000000-0000-0000-0000-00000000000", | ||
"timestamp": "2015-05-13T12:34:56Z", | ||
"reason": "USER_INITIATED" | ||
} | ||
} |
@@ -77,2 +77,16 @@ /** @jsx ssml */ | ||
}); | ||
it('should accept an optional type argument', function() { | ||
req.say('ssml', '<speak></speak>'); | ||
expect(req.toJSON().response.outputSpeech).to.deep.equal({ | ||
type: "SSML", | ||
ssml: "<speak></speak>" | ||
}); | ||
req.say('text', 'foobar'); | ||
expect(req.toJSON().response.outputSpeech).to.deep.equal({ | ||
type: "PlainText", | ||
text: "foobar" | ||
}); | ||
}); | ||
}); | ||
@@ -117,2 +131,16 @@ | ||
}); | ||
it('should accept an optional type argument', function() { | ||
req.reprompt('ssml', '<speak></speak>'); | ||
expect(req.toJSON().response.reprompt.outputSpeech).to.deep.equal({ | ||
type: "SSML", | ||
ssml: "<speak></speak>" | ||
}); | ||
req.reprompt('text', 'foobar'); | ||
expect(req.toJSON().response.reprompt.outputSpeech).to.deep.equal({ | ||
type: "PlainText", | ||
text: "foobar" | ||
}); | ||
}); | ||
}); | ||
@@ -119,0 +147,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48804
26
1027
176