-1

I absolutely can't find my mistake. I'm trying to place a LexBot on a website hosted on AWS S3 but an error persists: The specified resource 'xxxx' does not exist. I am sure of my Bot's name as well as the IdentityPoolID.

    //set the focus to the input box
    document.getElementById("wisdom").focus();

Initialize the Amazon Cognito credentials provider

    AWS.config.update({
        region: "eu-west-1",
        credentials: new AWS.CognitoIdentityCredentials({
            IdentityPoolId: "eu-west-1:e67246ad-9f60-45fd-b8bd-6cdab757f4af"
        })
    });

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

    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: 'MoodleUlsterBotHelp',
                inputText: wisdom,
                userId: lexUserId,
                sessionAttributes: 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) {

capture the sessionAttributes for the next cycle

                    sessionAttributes = data.sessionAttributes;

show response and/or error/dialog status

                    showResponse(data);
                }

re-enable input

                wisdomText.value = '';
                wisdomText.locked = false;
            });
        }

we always cancel form submission

        return false;
    }

    function showRequest(daText) {

        var conversationDiv = document.getElementById('conversation');
        var requestPara = document.createElement("P");
        requestPara.className = 'userRequest';
        requestPara.appendChild(document.createTextNode(daText));
        conversationDiv.appendChild(requestPara);
        conversationDiv.scrollTop = conversationDiv.scrollHeight;
    }

    function showError(daText) {

        var conversationDiv = document.getElementById('conversation');
        var errorPara = document.createElement("P");
        errorPara.className = 'lexError';
        errorPara.appendChild(document.createTextNode(daText));
        conversationDiv.appendChild(errorPara);
        conversationDiv.scrollTop = conversationDiv.scrollHeight;
    }

    function showResponse(lexResponse) {

        var conversationDiv = document.getElementById('conversation');
        var responsePara = document.createElement("P");
        responsePara.className = 'lexResponse';
        if (lexResponse.message) {
            responsePara.appendChild(document.createTextNode(lexResponse.message));
            responsePara.appendChild(document.createElement('br'));
        }
        if (lexResponse.dialogState === 'ReadyForFulfillment') {
            responsePara.appendChild(document.createTextNode(
                'Ready for fulfillment'));
            // TODO:  show slot values
        } else {
            responsePara.appendChild(document.createTextNode(
                '(' + lexResponse.dialogState + ')'));
        }
        conversationDiv.appendChild(responsePara);
        conversationDiv.scrollTop = conversationDiv.scrollHeight;
    }

1 Answers1

0

I finally found the solution. I created the Amazon lex bot with the wrong version (v2). It works well with the first version