Почему у моего набора Alexa Skills нет намерений - PullRequest
0 голосов
/ 28 октября 2019

Использование модуля узла набора навыков Alexa. Я пытаюсь сделать MQTT-вызов из моей функции обработчика с помощью набора навыков Alexa. Кажется, что сообщение отправлено правильно, выполнить обещание, но когда я проверяю его, фактическое намерение истекает. Я просмотрел код несколько раз, но не могу понять.

    const NextPatternIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'NextPatternIntent';
    },
    async handle(handlerInput) {
        const speakOutput = handlerInput.t('NEXT_MSG');
        const response = await sendMQTT();
        console.log(response);

        return handlerInput.responseBuilder
            .speak("Okay updated the pattern")
            .getResponse();
    }
    };

    function sendMQTT() {
    return new Promise(((resolve, reject) => {
        var client  = mqtt.connect('mqtt://broker.mqtt-dashboard.com')
        client.on('connect', function () {
            console.log("connected to mqtt server");
            client.subscribe('prancerInTopic', function (err) {
                if (!err) {
                    console.log("subscribed, sending message");
                    client.publish('mytopic', '{"event":"nextpattern"}');
                    resolve("it worked");
                }
                else
                {
                    console.log(err);
                    reject(err);
                }
            })
        })
    }));
}
...