<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 async def set_name_endpoint(request: web.Request) -> web.Response: """ Set the name of the robot. Request with POST /server/name {"name": new_name} Responds with 200 OK {"hostname": new_name, "prettyname": pretty_name} or 400 Bad Request In general, the new pretty name will be the specified name. The true hostname will be capped to 53 letters, and have any characters other than ascii letters or dashes replaced with dashes to fit the requirements here https://www.freedesktop.org/software/systemd/man/hostname.html#. """


    def build_400(msg: str) -> web.Response:
        return web.json_response(
            data={'message': msg},
            status=400)

    body = await request.json()
    if 'name' not in body or not isinstance(body['name'], str):
        return build_400('Body has no "name" key with a string')

    new_name = await set_name(body['name'])
    request.app[DEVICE_NAME_VARNAME] = new_name

    return web.json_response(data={'name': new_name},
                             status=200)