【问题标题】:How to return node js output to test-bot (aws-lex) frpm aws lambda如何将节点 js 输出返回到 test-bot (aws-lex) frpm aws lambda
【发布时间】:2017-11-02 22:54:59
【问题描述】:

我是 AWS lambda、lex 和 node-js 的新手,所以这是一个非常基本的问题:

我正在尝试编写一个 node-js lambda 函数,它将简单的命令输出返回到 test-bot (lex),我能够将正确的输出记录到 cloud-watch,但同样没有返回到 test- bot - 我相信我必须使用回调之类的东西(我能够将硬编码的字符串返回给自动机器人,但不能返回我的命令的输出)但不知道如何使用它,下面是我正在尝试的代码片段跑,你能吗?帮助

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/')
            }
            }
        });
}

【问题讨论】:

    标签: node.js lambda aws-lambda


    【解决方案1】:

    试试这个,

    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(); 
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-23
      • 2021-09-11
      • 2018-07-22
      • 2020-10-20
      • 2015-11-15
      • 2020-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多