2017-06-01 14 views
0

我是新来的AWS拉姆达,lex和节点JS,所以这是很基本的问题:如何节点JS输出回归测试BOT(AWS-法)FRPM AWS拉姆达

我想写一个node-js lambda函数,它将返回简单的命令输出到test-bot(lex),我能够将正确的输出记录到云端监视器,但同样没有返回到测试机器人 - 我相信我必须使用像回调(我能够返回硬编码的字符串自动机器人,但不能够返回我的命令的输出),但不知道如何使用它,下面是我试图运行的代码片断,你可以pl。帮助

var SSH = require('simple-ssh') 
var ssh_test = new SSH({ 
    host: 'xx.xx.xx.xx', 
    user: 'xyz', 
    pass: 'xyz' 
}); 

exports.handler = (event, context, callback) => { 
    var test = event.currentIntent.slots.purchase,   
     ssh_test.exec('ls /tmp/', { 
        out: console.log.bind(console) 
      }) 
      .exec('exit', {            
        out: console.log.bind(console) 
      }).start(); 
     callback(null, { 
      "dialogAction": { 
       "type": "Close", 
       "fulfillmentState": "Fulfilled", 
      "message": { 
       "contentType": "PlainText", 
       "content": "I AM ABLE TO RETURN THIS HARDCODED STRING TO BOT" //ALONG WITH THIS I WANT TO APPEND COMMAND OUTPUT ('ls /tmp/') 
      } 
      } 
     }); 
} 

回答

2

试试这个,

var SSH = require('simple-ssh') 
var ssh_test = new SSH({ 
    host: 'xx.xx.xx.xx', 
    user: 'xyz', 
    pass: 'xyz' 
}); 

exports.handler = (event, context, callback) => { 
    var test = event.currentIntent.slots.purchase,   
     ssh_test.exec('ls /tmp/', { 
        out: console.log.bind(console) 
        callback(null, { 
      "dialogAction": { 
       "type": "Close", 
       "fulfillmentState": "Fulfilled", 
      "message": { 
       "contentType": "PlainText", 
       "content": "I AM ABLE TO RETURN THIS HARDCODED STRING TO BOT" //ALONG WITH THIS I WANT TO APPEND COMMAND OUTPUT ('ls /tmp/') 
      } 
      } 
       }); 
      }) 
      .exec('exit', {            
        out: console.log.bind(console) 
      }).start(); 


}