def _handle_alexa(handler, path_match, data):
    _LOGGER.debug('Received Alexa request: %s', data)

    req = data.get('request')

    if req is None:
        _LOGGER.error('Received invalid data from Alexa: %s', data)
        handler.write_json_message(
            "Invalid value received for port", HTTP_UNPROCESSABLE_ENTITY)
        return

    req_type = req['type']

    if req_type == 'SessionEndedRequest':
        handler.send_response(HTTP_OK)
        handler.end_headers()
        return

    intent = req.get('intent')
    response = AlexaResponse(handler.server.hass, intent)

    if req_type == 'LaunchRequest':
        response.add_speech(
            SpeechType.plaintext,
            "Hello, and welcome to the future. How may I help?")
        handler.write_json(response.as_dict())
        return

    if req_type != 'IntentRequest':
        _LOGGER.warning('Received unsupported request: %s', req_type)
        return

    intent_name = intent['name']
    config = _CONFIG.get(intent_name)

    if config is None:
        _LOGGER.warning('Received unknown intent %s', intent_name)
        response.add_speech(
            SpeechType.plaintext,
            "This intent is not yet configured within Home Assistant.")
        handler.write_json(response.as_dict())
        return

    speech = config.get(CONF_SPEECH)
    card = config.get(CONF_CARD)
    action = config.get(CONF_ACTION)

    # pylint: disable=unsubscriptable-object
    if speech is not None:
        response.add_speech(SpeechType[speech['type']], speech['text'])

    if card is not None:
        response.add_card(CardType[card['type']], card['title'],
                          card['content'])

    if action is not None:
        action.run(response.variables)

    handler.write_json(response.as_dict())
Handle Alexa.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/alexa.py/_handle_alexa