I am trying to finish up my Alexa App for music, but for some reason, the stop and cancel part of my app isn't working. This is my code (part of it):
(the async stop is what is called when controller.stop is called)
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
Alexa.getRequestType(handlerInput.requestEnvelope) === "IntentRequest" &&
(Alexa.getIntentName(handlerInput.requestEnvelope) ===
"AMAZON.CancelIntent" ||
Alexa.getIntentName(handlerInput.requestEnvelope) ===
"AMAZON.StopIntent" ||
Alexa.getIntentName(handlerInput.requestEnvelope) ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {
console.log("CancelAndStopIntentHandler");
handlerInput.responseBuilder.speak("Okay")
return controller.stop(handlerInput, "okay"); //Goodbye!");
},
};
-------------------------------------------------------------------------
async stop(handlerInput, message) {
var device_id = handlerInput.requestEnvelope.context.System.device.deviceId;
var info = await getstuffindb(device_id);
console.log(info.length);
var deviceMap = JSON.parse(info.devicemap);
deviceMap[device_id]["is_playing"]=false;
if (deviceMap[device_id]) {
deviceMap[device_id]["g_offset"] = handlerInput.requestEnvelope.context.AudioPlayer.offsetInMilliseconds;
console.log('Stopped at offset', deviceMap[device_id]["g_offset"]);
}
await insertintodb(device_id, JSON.stringify(deviceMap), device_id);
return handlerInput.responseBuilder
.speak(message)
.withShouldEndSession(true)
.addAudioPlayerStopDirective()
.getResponse();
},