Skip to content

Instantly share code, notes, and snippets.

@andrewkim316
Created August 29, 2019 22:19
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/8a71c2955b536cf6b40d8a295015c649 to your computer and use it in GitHub Desktop.
Save andrewkim316/8a71c2955b536cf6b40d8a295015c649 to your computer and use it in GitHub Desktop.
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