Apollon77 / alexa-remote

MIT License
92 stars 23 forks source link

Alexa sendSequenceCommand speak/ssml dosn't work #191

Closed bschumm closed 2 years ago

bschumm commented 2 years ago

Describe the bug

I can't use the sendSequenceCommand in alexa-remote.js#L2527 with the speak or ssml action alexa-remote.js#L2341

alexa.sendSequenceCommand(deviceSerial, "speak", 'Hallo', overrideCustomerId, rf);  

other actions are working:

alexa.sendMessage(deviceSerial, 'next', 1, rf); //works
alexa.sendSequenceCommand(deviceSerial, "curatedtts", 'compliments', overrideCustomerId, rf); //works
alexa.sendSequenceCommand(deviceSerial, "textCommand", 'Sprich mir nach, Hallo', overrideCustomerId, rf); //works

To Reproduce

Code:

let Alexa = require('./node_modules/alexa-remote2');
let alexa = new Alexa();
const fs = require('fs');
/***************************************************************/

// storage box path
const storage_box = "./storage/";

const Alexa_cookie_data = JSON.parse(fs.readFileSync(storage_box+"alexa.cookieData", 'utf8'));
const Alexa_macDms = JSON.parse(fs.readFileSync(storage_box+"alexa.cookieData.macDms", 'utf8'));
const Alexa_cookie = JSON.parse(fs.readFileSync(storage_box+"alexa.cookie", 'utf8'));

var debug = false;
var deviceSerial = "GXXX";
var overrideCustomerId = "AXXX";

alexa.init({
        cookie: Alexa_cookie,  // cookie if already known, else can be generated using proxy
        proxyOnly: true,
        proxyOwnIp: 'localhost',
        proxyPort: 3001,
        proxyLogLevel: 'info',
        bluetooth: false,
        logger: function(msg) { if(debug) console.log(msg) }, // optional
//        alexaServiceHost: 'pitangui.amazon.com', // optional, e.g. "pitangui.amazon.com" for amazon.com, default is "layla.amazon.de"
//        userAgent: '...', // optional, override used user-Agent for all Requests and Cookie determination
//        acceptLanguage: '...', // optional, override Accept-Language-Header for cookie determination
//        amazonPage: '...', // optional, override Amazon-Login-Page for cookie determination and referer for requests
        useWsMqtt: false, // optional, true to use the Websocket/MQTT direct push connection
        cookieRefreshInterval: 7*24*60*1000, // optional, cookie refresh intervall, set to 0 to disable refresh
        formerDataStorePath: storage_box+"alexa.baseic_info", // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
        formerRegistrationData: Alexa_cookie_data, // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
        macDms: Alexa_macDms, // required since version 4.0 to use Push connection! Is returned in cookieData.macDms
    },
    async function (err) {
        if (err) {
            console.log (err);
            return;
        }

        // write cookie data to disk
        fs.writeFileSync(storage_box+'alexa.cookie', JSON.stringify(alexa.cookie));
        fs.writeFileSync(storage_box+'alexa.cookieData.macDms', JSON.stringify(Alexa_macDms));
        fs.writeFileSync(storage_box+'alexa.cookieData', JSON.stringify(alexa.cookieData));

       // console.log(JSON.stringify(alexa.cookie));
       // console.log(JSON.stringify(alexa.csrf));
       // console.log(JSON.stringify(alexa.cookieData));
       // console.log(alexa);

        debug = true;   
        var rf = function(err, result){console.log("\t\t");console.log(err, result)};

        //alexa.getDoNotDisturb(rf); // works
        //alexa.setDoNotDisturb(deviceSerial, false, rf); // works
        //alexa.sendMessage(deviceSerial, 'next', 1, rf); //works
        //alexa.sendSequenceCommand(deviceSerial, "curatedtts", 'compliments', overrideCustomerId, rf); //works
        //alexa.sendSequenceCommand(deviceSerial, "textCommand", 'Sprich mir nach, Hallo', overrideCustomerId, rf); //works

        console.log("\n ----------------------------- sending command");
        //alexa.sendSequenceCommand(deviceSerial, "speak", 'Hallo', overrideCustomerId, rf); // dosnt work
        alexa.sendSequenceCommand(deviceSerial, "ssml", '<speak>Hallo</speak>', overrideCustomerId, rf); // dosnt work
        console.log("\n ---------------------------- sending command END");
    }
); 

Logfiles

Response from alexa.sendSequenceCommand(deviceSerial, "speak", 'Hallo', overrideCustomerId, rf);

 node test.js

 ----------------------------- sending command
Alexa-Remote: No authentication check needed (time elapsed 1640)
Alexa-Remote: Sending Request with {"host":"eu-api-alexa.amazon.com","path":"/api/behaviors/preview","method":"POST","timeout":10000,"headers":{}}  and data=
{"behaviorId":"PREVIEW","sequenceJson":"{\"@type\":\"com.amazon.alexa.behaviors.model.Sequence\",\"startNode\":{\"@type\":\"com.amazon.alexa.behaviors.model.
OpaquePayloadOperationNode\",\"operationPayload\":{\"deviceType\":\"A1RABVCI4QCIKC\",\"deviceSerialNumber\":\"GXXX\",\"locale\":\"de-DE\",\"custo
merId\":\"AXXX\",\"textToSpeak\":\"Hallo\"},\"type\":\"Alexa.Speak\",\"skillId\":\"amzn1.ask.1p.saysomething\"}}","status":"ENABLED"}
 ---------------------------- sending command END
Alexa-Remote: Response: No body

null { success: true }

Response from alexa.sendSequenceCommand(deviceSerial, "ssml", 'Hallo', overrideCustomerId, rf);

$ node test.js

 ----------------------------- sending command
Alexa-Remote: No authentication check needed (time elapsed 1592)
Alexa-Remote: Sending Request with {"host":"eu-api-alexa.amazon.de","path":"/api/behaviors/preview","method":"POST","timeout":10000,"headers":{}}  and data={
"behaviorId":"PREVIEW","sequenceJson":"{\"@type\":\"com.amazon.alexa.behaviors.model.Sequence\",\"startNode\":{\"@type\":\"com.amazon.alexa.behaviors.model.O
paquePayloadOperationNode\",\"operationPayload\":{\"customerId\":\"AXXX\",\"expireAfter\":\"PT5S\",\"content\":[{\"locale\":\"de-DE\",\"display\":{
\"title\":\"ioBroker\",\"body\":\"Hallo\"},\"speak\":{\"type\":\"ssml\",\"value\":\"<speak>Hallo</speak>\"}}],\"target\":{\"customerId\":\"AXXX\",\
"devices\":[{\"deviceSerialNumber\":\"GXXX\",\"deviceTypeId\":\"A1RABVCI4QCIKC\"}]}},\"type\":\"AlexaAnnouncement\",\"skillId\":\"amzn1.ask.1p.ro
utines.messaging\"}}","status":"ENABLED"}

 ---------------------------- sending command END
Alexa-Remote: Response: No body

null { success: true }

Working response from alexa.sendSequenceCommand(deviceSerial, "textCommand", 'Sprich mir nach, Hallo', overrideCustomerId, rf);

$ node test.js
Alexa-Remote: No authentication check needed (time elapsed 1472)
Alexa-Remote: Sending Request with {"host":"eu-api-alexa.amazon.de","path":"/api/behaviors/preview","method":"POST","timeout":10000,"headers":{}}  and data={
"behaviorId":"PREVIEW","sequenceJson":"{\"@type\":\"com.amazon.alexa.behaviors.model.Sequence\",\"startNode\":{\"@type\":\"com.amazon.alexa.behaviors.model.O
paquePayloadOperationNode\",\"operationPayload\":{\"deviceType\":\"A1RABVCI4QCIKC\",\"deviceSerialNumber\":\"GXXX\",\"locale\":\"de-DE\",\"custom
erId\":\"AXXX\",\"text\":\"Sprich mir nach, Hallo\"},\"type\":\"Alexa.TextCommand\",\"skillId\":\"amzn1.ask.1p.tellalexa\"}}","status":"ENABLED"}

 ----------------------------- sending command

 ---------------------------- sending command END
Alexa-Remote: Response: No body

null { success: true }

Versions:

$ cat package.json
{
  "dependencies": {
    "alexa-remote2": "^5.8.2"
  }
}

Additional context
Add any other context about the problem here.

Apollon77 commented 2 years ago

Does it work if you create a speak routine in the Alexa App?

If no ... (most likely) disable the do not disturb mode :-) If yes ... why you use a overrideCustomerId and are you sure that this ID is correct? because if not it will also not work

In my systems and many users it does work, so most likely one of the two told options are most likely

bschumm commented 2 years ago

Thanks for the clarification. Sometimes it helps just to take a step back and have a overview:

Alexa wasn't in DND mode and a speak routine was working. I figured out, that that Alexa was initialized with another family member account. After changing Alexa to the main account it worked. ( That might also be the issue why I needed the overrideCustomerId )

Now speak and ssml are working!

Apollon77 commented 2 years ago

Thank you for the info and glad it now works