0
votes

I made a project in AWS Mobile Hub and am trying to deploy a Lex conversational bot into the app. I am using Android Studio. I am having an issue with one of the bots. This bot is a simple FAQ chat bot that uses Lambda code hook fulfillment to post answers to user questions.

The bot works perfectly in the Lex console as well as on a Slack channel. However in the sample app it only works in the voice to voice demo. When I try the text to text demo the bot never responds to user inputs and often the app crashes.

I downloaded and tested several sample apps with different bots integrated. All the bots that don't have lambda code hooks work perfectly in both the text and speech demos. However the bots that have lambda code hooks only work in the speech demo.

Edit: I tried again and found that bots w/ lambda code hooks do respond, but only if the response is delegated to Lex and comes from configurations set in the console or if the responses comes from a Lambda input validation code hook. It doesn't respond when the response is expected to come from a Lambda fulfillment code hook (using PostContent runtime API operation).

I thought maybe I wrote my Lambda function wrong so I also tested using the sample OrderFlowers bot and its sample code hook and got the same result.

Note the Lambda functions are not throwing invocation errors, all of the invocations are being handled successfully but the response doesn't appear.

Any ideas on how I can successfully get a text fulfillment response working?

2
Zahra, Are you able to reproduce this with the sample app created by Mobile Hub or just in your app?KevinR
@KevinR Both. I'm able to recreate the issue with a sample app created by Mobile Hub using the sample OrderFlowers bot and its corresponding sample Lambda functions. Same issue when I use my own bot + Lambda functions in a sample app.Zahra Amin
I forgot to ask, are you doing this on a real device or in the simulator. I just tried with the sim and it is working OK for me. So all you are doing is to create a new project, adding an order flowers bot, then downloading the sample, compiling it and running it?KevinR
Yup that's what I'm doing. Simulator not real device. So you were able to get the final confirmation response?Zahra Amin
Just tried again, I ended up with the following: ""OrderFlowersFlowerType":"roses","OrderFlowersPickupDate":"2017-08-10","OrderFlowersPickupTime":"13:00"}. Do you get the conversation going back and forth up to the final "Does this sound okay?" and then say yes and get nothing back?KevinR

2 Answers

1
votes

I was able to get my FAQ bot working in the text portion of the sample app by doing the following:

I followed KevinR's suggestion of updating promptUserToRespond in ConversationBotTextFragment.java to the following (rewriting so the full answer is in one place):

    public void promptUserToRespond(Response response,
                                    LexServiceContinuation continuation) {

        if(!DialogState.ReadyForFulfillment.toString().equals(response.getDialogState())
                && !DialogState.Fulfilled.toString().equals(response.getDialogState())) {
            addMessage(new TextMessage(response.getTextResponse(), "rx", getCurrentTimeStamp()));

            readUserText(continuation);
        }
        else if(DialogState.Fulfilled.toString().equals(response.getDialogState())) {
            addMessage(new TextMessage(response.getTextResponse(), "rx", getCurrentTimeStamp()));

            inConversation = false;
        }
    }

After doing this I was successfully able to get responses from my bot but each time a new user question was inputted, the previous text would disappear. I think the reason I was experiencing this issue is that my FAQ bot would give answers to the user by posting a close message to the user through a Lambda fulfillment hook. When a close message is posted, the conversation has ended and the startNewConversation() method is invoked, clearing all messages from the previous conversation.

To combat this I did the following:

I created a new method in ConversationBotTextFragment.java (the method is identical to the startNewConversation() method except it doesn't clear the conversation). This is said method:

private void ContinueConversationAfterFulfillment() {
    Log.d(TAG, "Starting new conversation");
    inConversation = false;
    clearTextInput();
}

and replaced the startNewConversation() invocation in textEntered() to an invocation of ContinueConversationAfterFulfillment().

0
votes

Try updating promptUserToRespond in ConversationalBotTextFragment.java to the following:

public void promptUserToRespond(Response response, LexServiceContinuation continuation) {

    if(!DialogState.ReadyForFulfillment.toString().equals(response.getDialogState()) && !DialogState.Fulfilled.toString().equals(response.getDialogState())) {
        addMessage(new TextMessage(response.getTextResponse(), "rx", getCurrentTimeStamp()));

        readUserText(continuation);
    }
    else if(DialogState.Fulfilled.toString().equals(response.getDialogState())) {
        addMessage(new TextMessage(response.getTextResponse(), "rx", getCurrentTimeStamp()));

        inConversation = false;
    }
}

The crash was probably because inConversation was not set to false and this method was not printing anything out for the "Fulfilled" state. We are discussing a better way to do this in the SDK but this should work for now.

Kevin