Last active
April 22, 2018 00:00
-
-
Save rishabhgupta/f11fc5202c008cf81050724d79a90400 to your computer and use it in GitHub Desktop.
Alexa Skill Developement
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
options.cardTitle = "Hello World"; | |
options.cardContent = "Hello" + name + " from Helloworld"; |
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
function formatResponse(options){ | |
var response = { | |
version: "1.0", | |
response: { | |
outputSpeech: { | |
type: "PlainText", | |
text: options.speachText | |
}, | |
shouldEndSession: options.endSession | |
} | |
}; | |
if (options.repromptText){ | |
response.response.reprompt = { | |
outputSpeech: { | |
type: "PlainText", | |
text: options.repromptText | |
} | |
}; | |
} | |
return response; | |
} |
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
'use strict'; | |
// Handler function | |
exports.handler = function (event, context) { | |
try { | |
// Get the request object | |
const request = event.request; | |
// Check request type - LaunchRequest, IntentRequest and SessionEndedRequest | |
if (request.type === "LaunchRequest"){ | |
let options = { | |
speechText:"Welcome to Hello World", | |
repromptText:"You can say, greet Cipherhack", | |
endSession: false | |
}; | |
let response = formatResponse(options); | |
context.succeed(response); | |
} else if (request.type === "IntentRequest"){ | |
if (request.intent.name === "HelloIntent"){ | |
let options = {}; | |
// Extract Params/Slots | |
let name = request.intent.slots.FirstName.value; | |
options.speechText = "Hello " + name + "."; | |
options.endSession = true; | |
let response = formatResponse(options); | |
context.succeed(response); | |
} else { | |
throw "Unknown intent type"; | |
} | |
} else if (request.type === "SessionEndedRequest"){ | |
} else { | |
// Unknown Intent Type return error | |
throw "Unknown intent type"; | |
} | |
} catch (err){ | |
context.fail('Exception: ' + err); | |
} | |
}; | |
function formatResponse(options){ | |
let response = { | |
version: "1.0", | |
response: { | |
outputSpeech: { | |
type: "PlainText", | |
text: options.speechText | |
}, | |
shouldEndSession: options.endSession | |
} | |
}; | |
if (options.repromptText){ | |
response.response.reprompt = { | |
outputSpeech: { | |
type: "PlainText", | |
text: options.repromptText | |
} | |
}; | |
} | |
return response; | |
} |
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
exports.handler = function (event, context) { | |
try { | |
// Get the request object | |
const request = event.request; | |
// Get the session object | |
const session = event.session; | |
// Initialize session attributes if not present | |
if (!event.session.attributes){ | |
event.session.attributes = {}; | |
} | |
... | |
... | |
} | |
} |
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
else if (request.type === "IntentRequest"){ | |
if (request.intent.name === "HelloIntent"){ | |
let options = {}; | |
// Extract Params/Slots | |
let name = request.intent.slots.FirstName.value; | |
options.speechText = "Hello " + name + "."; | |
options.endSession = true; | |
let response = formatResponse(options); | |
context.succeed(response); | |
} else { | |
context.fail("Unknown intent type"); | |
} | |
} |
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
if (request.type === "LaunchRequest"){ | |
let options = { | |
speechText:"Welcome to Hello World", | |
repromptText:"You can say, greet Cipherhack", | |
endSession: false | |
}; | |
let response = formatResponse(options); | |
context.succeed(response); | |
} |
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
... | |
... | |
} else if (request.intent.name === "MoreIntent") { | |
let options = {}; | |
// Get Session Attributes | |
options.session = session; | |
if (session.attributes.helloIntent){ | |
options.speechText = "Hello Again, " + session.attributes.firstName; | |
options.endSession = true; | |
context.succeed(formatResponse(options)); | |
} else { | |
options.speechText = "Wrong invocation of more intent"; | |
options.endSession = true; | |
} | |
} else { | |
... | |
... |
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
// Handler function | |
exports.handler = function (event, context) { | |
// Get the request object | |
var request = event.request; | |
// Check request type - LaunchRequest, IntentRequest and SessionEndedRequest | |
if (request.type === "LaunchRequest"){ | |
} else if (request.type === "IntentRequest"){ | |
} else if (request.type === "SessionEndedRequest"){ | |
} else { | |
// Unknown Intent Type return error | |
context.fail("Unknown intent type"); | |
} | |
}; |
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
{ | |
"version": "1.0", | |
"session": { | |
"new": true, | |
"sessionId": "uniqueSessionID123", | |
"application": { | |
"applicationId": "uniqueApplicationID123" | |
}, | |
"attributes": {}, | |
"user": { | |
"userId": "uniqueUserID123", | |
} | |
}, | |
"context": {}, | |
"request": { | |
"intent": { | |
"name": "HelloIntent", | |
"slots": { | |
"FirstName": { | |
"name": "FirstName", | |
"value": "Cipherhack" | |
} | |
} | |
}, | |
"type": "IntentRequest", | |
"requestId": "uniqueRequestID" | |
} | |
} |
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
... | |
... | |
if (options.cardTitle){ | |
response.response.card = { | |
card: { | |
type: 'Simple', | |
title: options.cardTitle, | |
content: options.cardContent | |
} | |
} | |
} | |
... | |
... |
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
{ | |
"version": "1.0", | |
"sessionAttributes": { | |
"attribute":"value" | |
}, | |
"response": { | |
"outputSpeech": { | |
"type": "PlainText", | |
"text": "Hello Cipherhack, have a great day ahead" | |
}, | |
"card": { | |
"type": "Simple", | |
"title": "Hello Cipherhack", | |
"content": "Have a great day ahead" | |
}, | |
"reprompt": { | |
"outputSpeech": { | |
"type": "PlainText", | |
"text": "Can I help you with anything else?" | |
} | |
}, | |
"shouldEndSession": true | |
} | |
} |
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
function formatResponse(options){ | |
... | |
... | |
if (options.session && options.session.attributes){ | |
response.sessionAttributes = options.session.attributes; | |
} | |
return response; | |
} |
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
... | |
... | |
} else if (request.type === "IntentRequest"){ | |
if (request.intent.name === "HelloIntent"){ | |
... | |
... | |
// Add session attributes | |
options.session.attributes.helloIntent = true; | |
options.session.attributes.firstName = name; | |
let response = formatResponse(options); | |
context.succeed(response); | |
} else { | |
... | |
... |
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
'use strict'; | |
// Handler function | |
exports.handler = function (event, context) { | |
try { | |
// Get the request object | |
const request = event.request; | |
// Initialize session attributes if not present | |
if (!event.session.attributes){ | |
event.session.attributes = {}; | |
} | |
let session = event.session; | |
// Check request type - LaunchRequest, IntentRequest and SessionEndedRequest | |
if (request.type === "LaunchRequest"){ | |
let options = { | |
speechText:"Welcome to Hello World", | |
repromptText:"You can say, greet Cipherhack", | |
endSession: false | |
}; | |
let response = formatResponse(options); | |
context.succeed(response); | |
} else if (request.type === "IntentRequest"){ | |
if (request.intent.name === "HelloIntent"){ | |
try { | |
let options = {}; | |
options.session = session; | |
// Extract Params/Slots | |
let name = request.intent.slots.FirstName.value; | |
options.speechText = "Hello " + name + ". Do you wish to listen once more ?"; | |
options.endSession = false; | |
options.session.attributes.helloIntent = true; | |
options.session.attributes.firstName = name; | |
options.cardTitle = "Hello World"; | |
options.cardContent = "Hello" + name + " from Helloworld"; | |
let response = formatResponse(options); | |
context.succeed(response); | |
} catch (err){ | |
throw "Exception" + err; | |
} | |
} else if (request.intent.name === "MoreIntent") { | |
try { | |
let options = {}; | |
// Get Session Attributes | |
options.session = session; | |
if (session.attributes.helloIntent){ | |
options.speechText = "Hello Again, " + session.attributes.firstName; | |
options.endSession = true; | |
context.succeed(formatResponse(options)); | |
} else { | |
options.speechText = "Wrong invocation of more intent"; | |
options.endSession = true; | |
} | |
} catch (err){ | |
throw "Exception in MoreIntent" + err; | |
} | |
} else { | |
throw "Unknown intent type"; | |
} | |
} else { | |
// Unknown Intent Type return error | |
throw "Unknown intent type"; | |
} | |
} catch (err){ | |
context.fail('Exception: ' + err); | |
} | |
}; | |
function formatResponse(options){ | |
let response = { | |
version: "1.0", | |
response: { | |
outputSpeech: { | |
type: "SSML", | |
ssml: "<speak>"+ options.speechText + "</speak>" | |
}, | |
shouldEndSession: options.endSession | |
} | |
}; | |
if (options.repromptText){ | |
response.response.reprompt = { | |
outputSpeech: { | |
type: "SSML", | |
ssml: "<speak>"+ options.repromptText + "</speak>" | |
} | |
}; | |
} | |
if (options.cardTitle){ | |
response.response.card = { | |
type: 'Simple', | |
title: options.cardTitle, | |
content: options.cardContent | |
} | |
} | |
if (options.session && options.session.attributes){ | |
response.sessionAttributes = options.session.attributes; | |
} | |
return response; | |
} |
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
function formatResponse(options){ | |
let response = { | |
version: "1.0", | |
response: { | |
outputSpeech: { | |
type: "SSML", | |
ssml: "<speak>"+ options.speechText + "</speak>" | |
}, | |
shouldEndSession: options.endSession | |
} | |
}; | |
if (options.repromptText){ | |
response.response.reprompt = { | |
outputSpeech: { | |
type: "SSML", | |
ssml: "<speak>"+ options.repromptText + "</speak>" | |
} | |
}; | |
} | |
return response; | |
} |
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
// Plain Text | |
outputSpeech: { | |
type: "PlainText", | |
text: "Welcome to Cipherhack" | |
} | |
// SSML | |
outputSpeech: { | |
type: "SSML", | |
ssml: "<speak>Welcome to Cipherhack<speak>" | |
} |
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
<speak> | |
<say-as interpret-as='cardinal'>12345</say-as> | |
</speak> | |
Will be pronouced as twelve thousand three hundred and forty five. | |
<speak> | |
<say-as interpret-as='ordinal'>12345</say-as> | |
</speak> | |
Will be pronouced as twelve thousand three hundred and forty fifth. | |
<speak> | |
<say-as interpret-as='digits'>12345</say-as> | |
</speak> | |
Will be pronouced as one two three four five. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment