python-3.xamazon-web-servicesaws-lambdaaws-lex

AWS Lex Lambda return multiple lines with Python


I've been reading the AWS Lex / Lambda docs and looking at the examples. I don't see a way to return multiple lines.

I want to create an intent that when a user types 'Help' It gives me an output like below.

Options:
  Deploy new instance.
  Undeploy instance.
  List instances.

I've tried this:

def lambda_handler(event, context):
    logger.debug('event.bot.name={}'.format(event['bot']['name']))
    a = {
        "dialogAction": {
        "type": "Close",
        "fulfillmentState": "Fulfilled",
        "message": {
            "contentType": "PlainText",
            "content": "Options: \nDeploy instance.\nUndeploy instance."
        }
      }
    }
    return a

Solution

  • How a message is displayed to the user completely depends on the output Channel you are using.

    \n works well in Facebook and Slack that I know of.

    The Lex Console Test Chat has its own unique formatting for displaying the Lex output, so its not very reliable for testing the formatting of a message. Its really only good for quick tests to make sure your bot responds without errors. And for a glimpse at the Lex JSON response.

    Each output Channel will receive the Lex JSON response and display it in its own way, so the only reliable way to test message formatting, links, images, and response cards is to test it in the actual Channel.