Alexa スキルからトリガーされる Lambda 関数から IoT トピックに発行しようとしています。Lambda 関数では、次の IoT パブリッシュを実行しています。
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
});
このコード (およびこのコードのみ) を Lambda 関数で実行すると、正常に動作します。しかし、params と publish 関数を Alexa スキル テンプレートの onIntent 関数に入れ、それを新しい Lambda 関数に入れると、機能しません。(両方の Lambda 関数の設定とポリシーは同じです。)
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;
}
}