alexa-ability
Advanced tools
Comparing version 0.3.6 to 0.4.0
@@ -38,4 +38,6 @@ 'use strict'; | ||
dLog('unhandled request', req); | ||
throw new Error("No event handler found."); | ||
}), _defineProperty(_handlers, e.unknownEvent, function unknownEventHandler(req) { | ||
uLog('unknown request', req); | ||
throw new Error("Unknown request type."); | ||
}), _defineProperty(_handlers, e.error, function defaultErrorHandler(err, req) { | ||
@@ -42,0 +44,0 @@ eLog('unhandled error', err); |
@@ -28,4 +28,3 @@ 'use strict'; | ||
this._event = event; | ||
this.raw = event; | ||
this.isNew = (0, _get2.default)(event, 'session.new', false); | ||
@@ -36,6 +35,8 @@ this.version = (0, _get2.default)(event, 'version', '1.0'); | ||
this._speech = null; | ||
this._card = null; | ||
this._reprompt = null; | ||
this._end = false; | ||
this._res = { | ||
outputSpeech: null, | ||
card: null, | ||
reprompt: null, | ||
shouldEndSession: false | ||
}; | ||
} | ||
@@ -46,3 +47,3 @@ | ||
value: function say(content) { | ||
this._speech = content; | ||
this._res.outputSpeech = toSpeechResponse(content); | ||
return this; | ||
@@ -52,4 +53,8 @@ } | ||
key: 'show', | ||
value: function show(content) { | ||
this._card = content; | ||
value: function show(title, content) { | ||
this._res.card = { | ||
type: "Simple", | ||
title: title, | ||
content: content | ||
}; | ||
return this; | ||
@@ -60,3 +65,5 @@ } | ||
value: function reprompt(content) { | ||
this._reprompt = content; | ||
this._res.reprompt = { | ||
outputSpeech: toSpeechResponse(content) | ||
}; | ||
return this; | ||
@@ -67,3 +74,3 @@ } | ||
value: function end() { | ||
this._end = true; | ||
this._res.shouldEndSession = true; | ||
return this; | ||
@@ -74,21 +81,11 @@ } | ||
value: function toJSON() { | ||
var data = { | ||
version: this.version, | ||
sessionAttributes: this.session, | ||
response: { shouldEndSession: this._end } | ||
}; | ||
var version = this.version; | ||
var session = this.session; | ||
var response = this._res; | ||
if (this._speech) data.response.outputSpeech = toSpeechResponse(this._speech); | ||
if (this._card) data.response.card = { | ||
type: "Simple", | ||
title: "Response", | ||
content: this._card | ||
return { | ||
version: version, | ||
response: response, | ||
sessionAttributes: { session: session } | ||
}; | ||
if (this._reprompt) data.response.reprompt = { | ||
outputSpeech: toSpeechResponse(this._reprompt) | ||
}; | ||
return data; | ||
} | ||
@@ -95,0 +92,0 @@ }]); |
{ | ||
"name": "alexa-ability", | ||
"version": "0.3.6", | ||
"version": "0.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -43,2 +43,3 @@ import noop from 'lodash/noop'; | ||
it('should return a promise', function() { | ||
app.on(e.launch, function(){}); | ||
const result = app.handle(launchRequest); | ||
@@ -49,2 +50,3 @@ expect(result).to.be.instanceOf(Promise); | ||
it('should return a promise that resolves to a request when successful', function() { | ||
app.on(e.launch, function(){}); | ||
return app.handle(launchRequest).should.be.fulfilled | ||
@@ -57,2 +59,3 @@ .then(req => expect(req).to.be.instanceOf(Request)); | ||
app.use(function(){ throw err }); | ||
app.on(e.launch, function(){}); | ||
return app.handle(launchRequest).should.be.rejected | ||
@@ -67,2 +70,3 @@ .then(err => expect(err).to.equal(err)); | ||
app.use(function(){ throw err }); | ||
app.on(e.launch, function(){}); | ||
app.on(e.error, spy); | ||
@@ -69,0 +73,0 @@ |
{ | ||
"version": "1.0", | ||
"sessionAttributes": {}, | ||
"sessionAttributes": { | ||
"session": {} | ||
}, | ||
"response": { | ||
@@ -11,4 +13,4 @@ "outputSpeech": { | ||
"type": "Simple", | ||
"title": "Response", | ||
"content": "foo" | ||
"title": "foo", | ||
"content": "bar" | ||
}, | ||
@@ -15,0 +17,0 @@ "reprompt": { |
@@ -22,2 +22,3 @@ import { Ability } from '../src/Ability'; | ||
app.use(spy); | ||
app.on('launch', function(){}); | ||
@@ -69,2 +70,3 @@ return app.handle(launchRequest) | ||
app.use(spy); | ||
app.on('unhandledEvent', function(){}); | ||
app.handle(launchRequest).then(function() { | ||
@@ -71,0 +73,0 @@ expect(spy).to.have.been.called; |
@@ -60,3 +60,3 @@ /** @jsx ssml */ | ||
describe.skip('"show" function', function() { | ||
describe('"show" function', function() { | ||
@@ -68,3 +68,8 @@ it('should chain', function() { | ||
it('should set the title and content of the card', function() { | ||
req.show('foo', 'bar'); | ||
expect(req.toJSON().response.card).to.deep.equal({ | ||
type: "Simple", | ||
title: 'foo', | ||
content: 'bar' | ||
}); | ||
}); | ||
@@ -110,3 +115,3 @@ }); | ||
it('should work', function() { | ||
req.say("foo").show("foo").reprompt(<speak>foo</speak>).end(); | ||
req.say("foo").show("foo", "bar").reprompt(<speak>foo</speak>).end(); | ||
expect(req.toJSON()).to.deep.equal(intentResponse); | ||
@@ -113,0 +118,0 @@ }); |
32407
755