Repository navigation
feat(map): reemplaza Google Maps por OpenStreetMap sin API key - #792
Merged
Merged
Conversation
- geocoding con Nominatim y respaldo en Photon - mapa estático propio: 3x3 tiles OSM, recorte 600x400 y pin rojo - imagen servida por el bot en /map/:id.png (TTL 30 min) - timeout configurable (HUBOT_MAP_TIMEOUT_MS) y errores reales al usuario - cache de geocoding (10 min) y tiles (7 días) - 13 tests nuevos con nock
- estilos alternativos sin key: osmfr (default) y hot, con fallback a osm/osmde - zoom calculado con el bounding box del resultado, acotado por tipo de lugar - dirección queda en 17, ciudad en 10, región en 6-8 - marcador más grande - tests: fallback de proveedor y bbox anómalo (Valparaíso)
Si existe HUBOT_MAP_STADIA_KEY se pide una sola imagen a Stadia (Static Maps, estilo outdoors por defecto). Si no, HUBOT_MAP_GEOAPIFY_KEY usa Geoapify (osm-bright). Sin llaves se mantiene el cosido de tiles OSM. La key nunca se envía a Slack: el bot descarga la imagen y la sirve en /map/:id.png. Tests con nock para ambos caminos y para el fallo de Stadia.
HUBOT_MAP_CITY_PROVIDER/HUBOT_MAP_CITY_STYLE permiten usar otro estilo (o incluso otro proveedor) cuando el zoom es <= HUBOT_MAP_CITY_MAX_ZOOM (default 13). Ejemplo: Stadia outdoors para direcciones y Geoapify klokantech-basic para ciudad. Si el proveedor de ciudad no tiene key, se usa el default.
Compone el logo (public/images/huemul-watermark.png) arriba a la derecha con fondo blanco translucido, sin tapar la atribucion del proveedor. Se desactiva con HUBOT_MAP_WATERMARK=off o se cambia con otra ruta.
Cada 'map' genera un id de 8 caracteres guardado en el brain (mapShares,
TTL 180 dias, maximo 500) y responde con https://<bot>/m/<id>.
GET /m/<id> pagina HTML con la imagen, coordenadas, boton Copiar link,
enlace a OpenStreetMap y metadatos og:title/og:image para
que Slack y WhatsApp muestren tarjeta al pegarlo.
GET /m/<id>.png imagen del mapa generada desde las coordenadas guardadas.
Sin base de datos nueva ni almacenamiento de binarios: el brain ya persiste
en Mongo y la imagen se cachea en memoria.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Descripción
Reemplaza el script
map(Google Maps) por una implementación con OpenStreetMap y sin API keys. El script anterior ejecutaba pero ya no funcionaba: Google devolvíaREQUEST_DENIEDpara cualquier dirección y elcatchmostraba siempre "no retorna resultados".https://huemul.devschile.cl/map/<id>.png(TTL 30 min).osmfrpor defecto yhotdisponible conHUBOT_MAP_PROVIDER; si un estilo falla se usa el siguiente (tiles.openstreetmap.org,tile.openstreetmap.de).boundingboxdel resultado (log2 para que quepa en 600×400) y se acota por tipo de lugar. Dirección queda en 17, ciudad en 10, región en 6-8. El tope evita bboxes anómalos: Valparaíso trae un bbox del tamaño de la región y quedaba en zoom 6.HUBOT_MAP_TIMEOUT_MS(default 8s).© OpenStreetMap contributorsen el footer del mensaje.msg.send(mantiene el hilo) en vez de llamar al adapter.Nuevas variables de entorno opcionales:
HUBOT_MAP_PUBLIC_URL,HUBOT_MAP_TIMEOUT_MS,HUBOT_MAP_PROVIDER. Al desplegar se puede borrarGOOGLE_MAPS_API_KEY: ya no se usa.Ejemplo de comportamiento
Tests
yarn test test/map.test.js→ 16 tests: éxito con pin, fallback a Photon, sin resultados, HTTP 429, HTTP 500, JSON inválido, timeout, error de red, todos los tiles caídos (se entrega igual el link), fallback de proveedor de tiles, cache, zoom por bounding box, bbox anómalo, limpieza del texto de entrada y "no usa APIs de Google".yarn test→ 292 tests passed.eslint scripts/map.js test/map.test.jssin errores.