Skip to content

Instantly share code, notes, and snippets.

@andrewkim316
Last active August 29, 2019 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewkim316/1910f1c62405c74b92b62a00a1e3e117 to your computer and use it in GitHub Desktop.
Save andrewkim316/1910f1c62405c74b92b62a00a1e3e117 to your computer and use it in GitHub Desktop.
const AccountIntentHandler = {
// Triggers when user wants to lookup account info
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'AccountIntent';
},
async handle(handlerInput) {
// Get user inputs and declare the Alpaca object
const slots = handlerInput.requestEnvelope.request.intent.slots;
const api = new Alpaca({
keyId: keyId,
secretKey: secretKey,
paper: true
});
// Get account from Alpaca trade API and craft response
const account = await api.getAccount();
const speakOutput = `Account info: current equity is ${account.equity}, current cash is ${account.cash}, buying power is ${account.buying_power}, portfolio value is ${account.portfolio_value}, currency is ${account.currency}.`;
// Send verbal response to user
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment