•   almost 9 years ago

How: Custom webpage interaction with lex

I know to play with lambda and lex with inline chat interaction also with the channels like fb messenger, slack.

But I want to integrate lex with a web page, a web application.

Do anyonen have idea ?
Please help me.

  • 1 comment

  •   •   almost 9 years ago

    You can use the JavaScript SDK (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexRuntime.html ), and integrate any type of GUI that you want. It can be a something like:

    // Initialize the Amazon Cognito credentials provider
    AWS.config.region = 'us-east-1'; // Region
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'us-east-1:your-congnito-identity-pool-id',
    });

    var lexruntime = new AWS.LexRuntime();
    lexUserId = 'chatbot-demo' + Date.now();

    function pushChat() {

    // if there is text to be sent...
    var wisdomText = document.getElementById('wisdom');
    if (wisdomText && wisdomText.value && wisdomText.value.trim().length > 0) {

    // disable input to show we're sending it
    var wisdom = wisdomText.value.trim();
    wisdomText.value = '...';
    wisdomText.locked = true;

    // send it to the Lex runtime
    var params = {
    botAlias: '$LATEST',
    botName: 'YourBotName',
    inputText: wisdom,
    userId: lexUserId,
    sessionAttributes: {}
    };
    showRequest(wisdom);
    lexruntime.postText(params, function(err, data) {
    if (err) {
    console.log(err, err.stack);
    showError('Error: ' + err.message + ' (see console for details)')
    }
    if (data) {
    // show response and/or error/dialog status
    showResponse(data);
    }
    // re-enable input
    wisdomText.value = '';
    wisdomText.locked = false;
    });
    }
    // we always cancel form submission
    return false;
    }

Comments are closed.