Created
August 29, 2019 22:19
-
-
Save andrewkim316/8a71c2955b536cf6b40d8a295015c649 to your computer and use it in GitHub Desktop.
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
const CancelOrderIntentHandler = { | |
canHandle(handlerInput) { | |
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' | |
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'CancelOrderIntent'; | |
}, | |
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 | |
}); | |
const orders = await api.getOrders({ | |
status: "open", | |
limit: 1, | |
}); | |
// Get the most recent order and cancel it | |
if(orders.length == 0){ | |
return handlerInput.responseBuilder | |
.speak("No orders to cancel.") | |
.getResponse(); | |
} else { | |
await api.cancelOrder(orders[0].id); | |
// Send verbal response to user | |
const speakOutput = "Order canceled."; | |
return handlerInput.responseBuilder | |
.speak(speakOutput) | |
.getResponse(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment