AWS Lex Lambda return multiple lines with Python

夙愿已清 提交于 2020-07-09 05:25:32

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/53633654/aws-lex-lambda-return-multiple-lines-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!