0

AlexaスキルからトリガされるLambda関数からIoTトピックにパブリッシュしようとしています。ラムダ関数の中で、私はこれのIoTが公開やってる:私はラムダ関数でこのコード(とのみ、このコードを)実行した場合AWS:AlexaスキルテンプレートのintentHandler.call()は先行する関数呼び出しをキャンセルします

var params = { 
    topic: 'testTopic', 
    payload: new Buffer('test message'), 
    qos: 1 
}; 

iotData.publish(params, function(err, data) { 
    if (err) console.log('ERR: ', err); // an error occurred 
    else if (data) console.log('DATA: ', data); // successful response 
}); 

、それが正常に動作します。しかし、私がAlexa SkillテンプレートのonIntent関数にparamsとpublish関数を入れて、それを新しいラムダ関数に入れると、それは機能しません。 (両方のラムダ関数が同じ設定とポリシーを持っています)

intentHandler.call()をコメントアウトすると、iotData.publish()が実行されるため、intentHandler呼び出しが何らかの理由でキャンセルするように見えます理解していない。

onIntent: function (intentRequest, session, response) { 
    var intent = intentRequest.intent, 
     intentName = intentRequest.intent.name, 
     intentHandler = this.intentHandlers[intentName]; 

    if (intentHandler) { 
    console.log('dispatch intent = ' + intentName); 

    var params = { 
     topic: 'testTopic', 
     payload: new Buffer('test message'), 
     qos: 1 
    }; 

    iotData.publish(params, function(err, data) { 
     if (err) console.log('ERR: ', err); // an error occurred 
     else if (data) console.log('DATA: ', data); // successful response 
    }); 

    intentHandler.call(this, intent, session, response); 
    } else { 
    throw 'Unsupported intent = ' + intentName; 
    } 
} 

答えて

0

これは、ラムダ関数のコンテキストに関連しているようです。 intentHandler.call()は問題のインテントを呼び出し、次にcontext.succeed()を呼び出します。私は、これはラムダ関数は、私はこのようなiotData.publish()のためにコールバックでintentHandler.call()を入れたときに、すべてが正常に動作しますのでiotData.publish()呼び出しは、実行される前に実行が終了を意味と仮定しています:

onIntent: function (intentRequest, session, response) { 
    var intent = intentRequest.intent, 
     intentName = intentRequest.intent.name, 
     intentHandler = this.intentHandlers[intentName]; 

    if (intentHandler) { 
    console.log('dispatch intent = ' + intentName); 

    var params = { 
     topic: 'signals', 
     payload: new Buffer(intentName), 
     qos: 1 
    }; 

    iotData.publish(params, function(err, data) { 
     if (err) console.log(err, err.stack); // an error occurred 
     else { 
     console.log(data);   // successful response 
     intentHandler.call(this, intent, session, response); 
     }  
    }); 
    } else { 
    throw 'Unsupported intent = ' + intentName; 
    } 
} 
関連する問題