Thursday, 1 June 2017

How to return node js output to test-bot (aws-lex) frpm aws lambda

I am new to AWS lambda, lex and node-js, so this is very basic question:

I am trying to write a node-js lambda function which will return simple command output to test-bot (lex), I am able to log the correct output to cloud-watch but same is not getting returned to the test-bot - I believe that I have to use something like callback (I am able to return hardcoded string to auto-bot but not able to return my command's output) but not sure how to use it, below is code snip which I am trying to run, can you pl. help

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



via Sneha

No comments:

Post a Comment