diff --git a/contract/openapi.json b/contract/openapi.json index 7961b6d..b7014d7 100644 --- a/contract/openapi.json +++ b/contract/openapi.json @@ -3,7 +3,7 @@ "info": { "title": "Wego API", "description": "Wego's travel API: places, flights, hotels and fares. Please see https://agents.wego.com for more details.", - "version": "0.19.5" + "version": "0.19.6" }, "tags": [ { @@ -6270,11 +6270,10 @@ "name": "cityCode", "schema": { "type": "string", - "pattern": "^[A-Z]{3}$", "example": "BKK" }, "required": true, - "description": "City code the link searches, e.g. BKK. Take it from a places result's code or cityCode, never its numeric id. A lat/lng pair cannot be shared: wego.com serves no coordinate search URL. To link one hotel instead of a search, use the pageUrl that hotel carries." + "description": "Use three uppercase letters (BKK) or 1 to 9 digits, optionally followed by a hyphen and 1 to 9 more digits (8283 or 1293-74). Take the code from the Places result's code or cityCode, never its id. The website has no coordinate search URL. To link one hotel instead, use its pageUrl." }, { "in": "query", diff --git a/integration/fixtures/places-makkah.json b/integration/fixtures/places-makkah.json new file mode 100644 index 0000000..da409e5 --- /dev/null +++ b/integration/fixtures/places-makkah.json @@ -0,0 +1,23 @@ +{ + "op": "getPlaces", + "status": 200, + "body": { + "results": [ + { + "id": 16907, + "code": "8283", + "name": "Makkah", + "type": "city", + "cityCode": "8283", + "latitude": 21.3891, + "longitude": 39.8579 + } + ], + "metadata": { + "resultCount": 1, + "totalCandidates": 1, + "hasMore": false, + "hasAmbiguity": false + } + } +} diff --git a/integration/hotels.test.ts b/integration/hotels.test.ts index 33b3224..48da8b7 100644 --- a/integration/hotels.test.ts +++ b/integration/hotels.test.ts @@ -390,11 +390,6 @@ describe("hotels usage errors: exit 2, no request", () => { ["hotels", "share", "BKK", ...DATES, "--rooms", "two"], "--rooms", ], - [ - "share: a hotelId, naming the city code as the way through", - ["hotels", "share", "710862", ...DATES], - "city code", - ], [ "share: lat,lng", ["hotels", "share", "13.75,100.5", ...DATES], @@ -457,6 +452,25 @@ describe("hotels search", () => { expect(createBody(fake)).not.toHaveProperty("hotelId"); }); + // Makkah as Places returns it: its id (16907) differs from its code. + it("searches Makkah by its code 8283, never its Places id", async () => { + signIn(s.home); + const fake = s.fake({ + routes: [ + route("places-makkah"), + route("hotels-search-create"), + route("hotels-search-results"), + ], + }); + const result = await s.run(["hotels", "search", "8283", ...DATES]); + + expect(result.code).toBe(0); + expect(fake.requests("getPlaces")[0]?.query.get("query")).toBe("8283"); + expect(createBody(fake)).toMatchObject({ cityCode: "8283" }); + expect(createBody(fake)).not.toHaveProperty("hotelId"); + expect(JSON.stringify(createBody(fake))).not.toContain("16907"); + }); + it("keeps an all-digit location that Places lists as no city a hotelId", async () => { signIn(s.home); const fake = s.fake({ @@ -1372,6 +1386,19 @@ describe("hotels share", () => { ); }); + it.each(["8283", "1293-74"])("shares a city with code %s", async (code) => { + signIn(s.home); + const fake = s.fake({ + routes: [ + route("hotels-search-link"), + ...placesKnowing({ [code]: "city" }), + ], + }); + const result = await s.run(["hotels", "share", code, ...DATES]); + expect(result.code).toBe(0); + expect(query(fake, "getHotelSearchLink").cityCode).toBe(code); + }); + it("sends --rooms, the same occupancy vocabulary as hotels search", async () => { signIn(s.home); const fake = s.fake({ diff --git a/skills/wego/references/cli.md b/skills/wego/references/cli.md index d467d27..b23fbc6 100644 --- a/skills/wego/references/cli.md +++ b/skills/wego/references/cli.md @@ -99,7 +99,7 @@ wego places "" [--types ] [--locale en `--types` narrows the candidates; omit it to resolve every place type (`city`, `airport`, `state`, `district`, `hotel`). Match the filter to the vertical – do not carry a flights-only filter into a hotel lookup. -- For flights, resolve each endpoint to an airport or city IATA code; narrow with `--types city,airport` when you want only those. Record whether the selected result is a `city` or `airport`; the booking-link command needs `--from-city` or `--to-city` when the original flight search used a city code. +- For flights, resolve each endpoint to an airport or city IATA code; narrow with `--types city,airport` when you want only those. Record whether the selected result is a `city` or `airport`; the booking-link command needs `--from-city` or `--to-city` when the original flight search used a city code. **A city whose `code` is not 3 uppercase letters (Makkah `8283`) has no airport of its own, so it is not a flight endpoint.** Run `wego info airports-near ,` with that city row's coordinates. If the row has no `latitude` and `longitude`, do not pass the numeric code instead, because `airports-near` refuses it: tell the user the nearby airports cannot be found from that row, and ask which airport they want. Otherwise pick the nearest airport it returns that the user did not rule out (for Makkah, `JED`, or `TIF` if the user rules out Jeddah). Read each row's `name` first, because some rows are train stations (`MKX` is Makkah Train Station). Search that one airport, and tell the user which airport you chose. Give its distance from the city only when the row has `latitude` and `longitude` to compute it from, and otherwise say the distance is unknown. Search a second airport only when the user asks to compare. - For hotels, pass an uppercase three-letter city code, a numeric hotel ID, or `lat,lng`. Leave `--types` off (or pass `city,district,hotel`) so hotel, district, and landmark candidates are not filtered out. Use coordinates for a district, landmark, or nearby search when no suitable city code or hotel ID represents the request. - If `metadata.hasAmbiguity` is true, use `disambiguationHint` and the candidates to clarify before proceeding. - Reuse resolved values during the same conversation instead of resolving them repeatedly. @@ -522,9 +522,9 @@ wego hotels share \ No prior search needed. Pass the same `--site`, `--currency` and `--locale` the search used, so the recipient opens it in the same market; the link runs live, so they see current prices, not this conversation's. -**Never hand-build a wego.com hotels URL, and never put a `places` `id` in one.** Only a `code` addresses a city there; a numeric id silently loads a different country. This command is the only supported way to make a hotel link that keeps working. +**Use the `code` from `wego places "" --types city`, never its `id` or a `hotelId`.** `hotels share` requires Places to return a city with that exact code. An ID can also happen to be a different city's code, so the lookup cannot tell which city you meant. Use `hotels share` rather than building the URL yourself. -It refuses what a search URL cannot carry, each an exit 2 before any call: anything that is not an uppercase 3-letter city code, **a hotelId, a coordinate or a city name** (share the city instead and name the hotel in your message, taking the code from `wego places "" --types city`), and **`--children` above 0 without `--children-ages`** (elsewhere a missing age is priced at 8; here that guess reaches someone who cannot correct it). +A city code has three uppercase letters (BKK) or is numeric (Makkah `8283`, Cannes `1293-74`). Coordinates and city names are refused before the lookup. To share a search and mention a specific hotel, share the city and name the hotel in your message. Pass `--children-ages` whenever `--children` is above 0; a durable link cannot guess the ages. Pass `--rooms N` for a stay that needs more than one room, the same flag `hotels search` takes. Rooms are 1-4 and never more than `--adults`, which defaults to 2, so send `--adults` alongside any `--rooms` above 2 or the link is refused. The guests spread evenly with the earlier rooms filled first, so the link opens the same occupancy the search priced. diff --git a/src/commands.ts b/src/commands.ts index 0294f47..66956a7 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -2403,9 +2403,9 @@ export function parseHotelsShareArgs( throw new Error(`Unexpected argument: ${extra[0]}\n${HOTELS_SHARE_USAGE}`); } // Not `locationFields`: its message names hotelId and lat,lng, the two shapes this command refuses. - if (!/^[A-Z]{3}$/.test(location)) { + if (!/^([A-Z]{3}|\d{1,9}(-\d{1,9})?)$/.test(location)) { throw new Error( - `A durable link needs a city, so "${location}" cannot be shared: wego.com serves no hotel-level or coordinate search URL. Pass an uppercase 3-letter city code, which \`${PROG} places --types city\` reports as code.`, + `A durable link needs a city, so "${location}" cannot be shared: wego.com serves no hotel-level or coordinate search URL. Pass a city code from \`${PROG} places --types city\`: 3 uppercase letters (BKK), or the numeric code a city without an airport carries (Makkah is 8283).`, ); } const query: WireQueryValues<"getHotelSearchLink"> = { diff --git a/src/hotels.test.ts b/src/hotels.test.ts index ec4a613..d150b69 100644 --- a/src/hotels.test.ts +++ b/src/hotels.test.ts @@ -1,5 +1,10 @@ import { describe, expect, it } from "bun:test"; -import { numericCityCode, parseRoomsArgs, settleRates } from "./commands"; +import { + numericCityCode, + parseHotelsShareArgs, + parseRoomsArgs, + settleRates, +} from "./commands"; import { HOTELS } from "./verticals"; /** @@ -192,6 +197,24 @@ describe("HOTELS empty-page note", () => { }); }); +describe("parseHotelsShareArgs", () => { + const DATES = ["2027-01-20", "2027-01-22"]; + + it("accepts a 3-letter code and the numeric code of a city without an airport", () => { + for (const code of ["BKK", "8283", "1293-74"]) { + expect(parseHotelsShareArgs([code, ...DATES]).cityCode).toBe(code); + } + }); + + it("refuses a code a search URL cannot carry, pointing at places --types city", () => { + for (const code of ["bkk", "Makkah", "21.42,39.82", "8283x", "1293-"]) { + expect(() => parseHotelsShareArgs([code, ...DATES])).toThrow( + /city code from `.+ places --types city`: 3 uppercase letters \(BKK\), or the numeric code/, + ); + } + }); +}); + describe("numericCityCode", () => { const places = (results: unknown[]) => (async () => ({ results, metadata: {} })) as unknown as Parameters<