add preliminary Request/Response typings

This commit is contained in:
petebeegle
2016-08-04 19:32:11 -04:00
parent 69eb72614d
commit 81aa948c91
2 changed files with 97 additions and 15 deletions
+8 -5
View File
@@ -3,20 +3,23 @@
import Alexa = require("alexa-sdk");
exports.handler = function(event: Alexa.Request, context: Alexa.Context, callback) {
exports.handler = function(event: Alexa.RequestBody, context: Alexa.Context, callback) {
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
var handlers: Alexa.Handlers = {
'LaunchRequest': function () {
this.emit('SayHello');
var self: Alexa.Handler = this;
self.emit('SayHello');
},
'HelloWorldIntent': function () {
this.emit('SayHello');
var self: Alexa.Handler = this;
self.emit('SayHello');
},
'SayHello': function () {
this.emit(':tell', 'Hello World!');
var self: Alexa.Handler = this;
self.emit(':tell', 'Hello World!');
}
};
+89 -10
View File
@@ -4,7 +4,7 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'alexa-sdk' {
export function handler(event: Request, context: Context, callback?: () => void): AlexaHandler;
export function handler(event: RequestBody, context: Context, callback?: () => void): AlexaHandler;
export function CreateStateHandler(state: string, obj: any): any;
export var StateString: string;
@@ -17,13 +17,17 @@ declare module 'alexa-sdk' {
response: any;
dynamoDBTableName: any;
saveBeforeResponse: boolean;
registerHandlers: (...handlers: any[]) => any;
registerHandlers: (...handlers: Handlers[]) => any;
execute: () => void;
}
interface Handlers {
[intent: string]: () => void;
}
interface Handler {
on: any;
emit: any;
emit(event: string, ...args: any[]): boolean;
emitWithState: any;
state: any;
handler: any;
@@ -34,12 +38,6 @@ declare module 'alexa-sdk' {
isOverriden: any;
}
interface Request {
version: string;
request: any;
session: any;
}
interface Context {
callbackWaitsForEmptyEventLoop: boolean;
logGroupName: string;
@@ -50,4 +48,85 @@ declare module 'alexa-sdk' {
invokeid: string;
awsRequestId: string;
}
}
interface RequestBody {
version: string;
session: Session;
request: LaunchRequest | IntentRequest | SessionEndedRequest;
}
interface Session {
new: boolean;
sessionId: string;
attributes: any;
application: SessionApplication;
user: SessionUser;
}
interface SessionApplication {
applicationId: string;
}
interface SessionUser {
userId: string;
accessToken: string;
}
interface LaunchRequest extends IRequest {}
interface IntentRequest extends IRequest {
intent: Intent;
}
interface Intent {
name: string;
slots: any;
}
interface SessionEndedRequest extends IRequest{
reason: string;
}
interface IRequest {
type: "LaunchRequest" | "IntentRequest" | "SessionEndedRequest";
requestId: string;
timeStamp: string;
}
interface ResponseBody {
version: string;
sessionAttributes?: any;
response: Response;
}
interface Response {
outputSpeech?: OutputSpeech;
card?: Card;
reprompt?: Reprompt;
shouldEndSession: boolean;
}
interface OutputSpeech {
type: "PlainText" | "SSML";
text?: string;
ssml?: string;
}
interface Card {
type: "Simple" | "Standard" | "LinkAccount";
title?: string;
content?: string;
text?: string;
image?: Image;
}
interface Image {
smallImageUrl: string;
largeImageUrl: string;
}
interface Reprompt {
outputSpeech: OutputSpeech;
}
}