Travel desk
A hotel's guests ask what the weather will be this weekend, whether shops are open on Thursday, what 100 euros are in złoty, and for a table at dinner. The bot answers from live data: the forecast from MET Norway summarized per day, the public holidays from the OpenHolidays API, the time at the hotel and the ECB's exchange rate. A table takes two clicks and a short form.
Guest: What's the weather this weekend? Anything closed?
Bot: Cold and grey, with sleet on Saturday afternoon. No public holidays
this weekend; Christmas Eve, the 24th, is one.
┌ Weather in Kraków ───────────────────────────────────┐
│ Sat 12 Dec Sleet 0° to 2°C 3.1 mm 4 m/s │
│ Sun 13 Dec Cloudy -3° to 0°C 0.4 mm 3 m/s │
│ Daily summaries based on data from MET Norway, CC BY │
└──────────────────────────────────────────────────────┘
Guest: Can we have dinner tomorrow?
Bot: Here are the free times on Saturday.
[ Saturday 12 Dec, 18:00 ] [ Saturday 12 Dec, 19:30 ]
[ Saturday 12 Dec, 21:00 ] [ Another day ]| Feature | Guide |
|---|---|
Tools that call public APIs from your server, with a cache and { error } when they're down | Tools |
| The weather and the holidays as cards, with their credit lines | Tools: cards, React: tool cards |
| The time at the hotel and the exchange rate: the demo site's own tools | site/tools.ts |
| The free tables as buttons | Reply options |
A form that books the table in onLead | Forms and leads |
The code is in site/recipes/travel-desk/, with a made-up hotel in Kraków in hotel.ts and its restaurant's tables in memory in restaurant.ts. Unlike the other recipes, the weather and the holidays are real APIs. Their tests run on fake responses, and nothing calls MET Norway or OpenHolidays until you deploy the recipe.
Before you deploy
- Accept MET Norway's terms. Someone in authority at your company reads and accepts the Terms of Service first. The data is under the NLOD 2.0 and CC BY 4.0, and commercial use is free. Don't use "Yr" in your service's name, or its logo. Changes to the terms are announced on the mailing list on the support page.
- Set
API_USER_AGENTto your app and a contact, for examplelinden-house.example/1.0 (+https://linden-house.example/contact)orlinden-desk/1.0 ops@linden-house.example. It has no default, so a copy of the recipe never sends someone else's contact. MET Norway answers a missing or genericUser-Agent(Node's own included) with a 403. - Check the holidays' country. The OpenHolidays API is free, allows commercial use and needs no key, but covers 36 countries, most of them in Europe (Make it yours has another source).
- Nothing about the guest goes to them. Your server calls both APIs, never the guest's browser, with the hotel's coordinates and the dates asked for.
1. The weather from MET Norway
metno.ts calls Locationforecast 2.0 and follows its terms in a few lines:
const ENDPOINT = 'https://api.met.no/weatherapi/locationforecast/2.0/compact';
/** At most 4 decimals, about 11 metres: MET Norway answers 5 or more with a 403. */
export const round4 = (value: number): number => Math.round(value * 10_000) / 10_000;
// …inside the client, for each request:
const lat = round4(place.lat);
const lon = round4(place.lon);
const key = `${lat},${lon}`;
let cached = cache.get(key);
// Never ask again before `Expires`.
if (!cached || now() >= cached.expires) {
const headers: Record<string, string> = {
'User-Agent': userAgent,
Accept: 'application/json',
};
if (cached?.lastModified) headers['If-Modified-Since'] = cached.lastModified;
const response = await get(`${ENDPOINT}?lat=${lat}&lon=${lon}`, {
headers,
signal: signal ?? null,
}).catch(() => undefined);
if (response?.status === 304 && cached) {
cached.expires = expiresAt(response, now());
} else if (response?.status === 403) {
once('403 Forbidden: check API_USER_AGENT, and that coordinates have at most 4 decimals.');
return { ok: false, reason: 'setup' };
} else if (response?.ok) {
// …keep the forecast with its Last-Modified and Expires
} else {
// A 429, a 5xx or no answer. An expired forecast isn't served.
return { ok: false, reason: 'unavailable' };
}
}- One request per forecast update. The forecast stays in memory until its
Expiresheader, and the next request sendsIf-Modified-Since: a304keeps the copy. On Vercel each instance keeps its own copy, still far below the 20 requests a second MET Norway allows a whole app. More than that needs an agreement with them. - A 403 is a setup error, logged once: the
User-Agentor the coordinates. A429, a5xxor no answer is an outage, and the tool says the forecast is unavailable. - The model gets a summary per day, not the hourly series:
dailySummariesturns it into the sky around noon, the lowest and highest temperature, the precipitation and the strongest wind, for up to 7 days in the hotel's time zone. The forecast is hourly for about two days, then in steps of 6 hours, so later days are rougher. A day without daytime data, such as the rest of today in the evening, is left out.
The tool and the credit
From tools.ts:
const userAgent = process.env.API_USER_AGENT ?? '';
const forecast = metnoForecast({ userAgent });
export const weather = defineTool({
name: 'get_weather',
description: `The weather forecast at ${HOTEL.name} in ${HOTEL.city}, one summary per day for up to 7 days: …`,
// No place to pick: the coordinates are the hotel's, never the model's.
input: z.object({}),
execute: async (_input, { signal }) => {
const result = await forecast(HOTEL, signal);
if (!result.ok) {
return {
error:
result.reason === 'setup'
? 'The weather service is not set up.'
: 'The forecast is unavailable right now.',
};
}
return { place: HOTEL.city, days: result.days, credit: METNO_CREDIT };
},
ui: (result) => ('days' in result ? { place: result.place, days: result.days } : undefined),
});The licence asks for a credit, and the summaries are your own work on MET Norway's data, so the credit says that: "Daily summaries based on data from MET Norway", with links to api.met.no and CC BY 4.0. The weather card in cards.tsx carries it under the days, and the page in page.tsx repeats it under the chat, with "MET Norway isn't responsible for them". In the script-tag widget, askdare's own iframe page draws no cards (Tools: cards): put the credits in your site's footer or on a page the chat links to.
2. Public holidays from OpenHolidays
holidays.ts asks for a whole year of one country's public holidays, keeps it for 24 hours, and filters it to the dates the model asked for:
const ENDPOINT = 'https://openholidaysapi.org/PublicHolidays';
// …inside the client, once per country and year:
const url = new URL(ENDPOINT);
url.searchParams.set('countryIsoCode', country);
url.searchParams.set('validFrom', `${year}-01-01`);
url.searchParams.set('validTo', `${year}-12-31`);
url.searchParams.set('languageIsoCode', 'EN');
const response = await get(url, {
headers: { 'User-Agent': userAgent, Accept: 'application/json' },
signal: signal ?? null,
}).catch(() => undefined);
if (!response?.ok) return undefined;A regional holiday keeps its regions as ISO 3166-2 codes (DE-BY), so the bot can say it applies only in some of the country. The tool takes the range from the model, at most 62 days, and the country from hotel.ts:
execute: async ({ from, to }, { signal }) => {
if (to < from || Date.parse(to) - Date.parse(from) > 62 * DAY) {
return { error: 'Ask for at most 62 days, the first day before the last.' };
}
const list = await holidays(HOTEL.country, from, to, signal);
// The weather still answers when the holidays are down.
if (!list) return { error: 'Holiday data is unavailable right now.' };
return { country: HOTEL.countryName, from, to, holidays: list, credit: HOLIDAYS_CREDIT };
},The data is under the ODbL, which asks for a credit: the holidays card says "Holiday data: OpenHolidays API, ODbL" with both links, and so does the page.
3. The time and the exchange rate
The demo site already has get_current_time and get_exchange_rate in site/tools.ts: the time in an IANA time zone, and the ECB's reference rate through Frankfurter, with no key. The recipe reuses them, and their cards from the site's components/tool-cards.tsx:
// tools.ts
export { currentTime, exchangeRate } from '@/tools';The bot's instructions say when they matter: get_current_time with the hotel's time zone before anything about "today", "tonight" or "this weekend", so the model knows the date at the hotel; get_exchange_rate for prices, which are in złoty, with a word that a bank charges more than the reference rate.
4. A table, as reply options and a form
Dinner has three seatings a day, and the restaurant takes bookings for the coming week. As in Booking a consultation, a click on an option is only a message and the model can't fill in a form, so both the tool and the form name a weekday and a seating, and nextDate in restaurant.ts turns them into the same date: today while that seating is still ahead at the hotel, else the next such weekday.
export const findTable = defineTool({
name: 'find_table',
description:
'Free dinner tables at the hotel restaurant on the next given weekday; today counts while a seating is still ahead. Use it before the booking form.',
input: z.object({ day: z.enum(WEEKDAYS).describe('The weekday') }),
execute: async ({ day }) => restaurant.freeSeatings(day),
replies: ({ seatings }) => [...seatings.map((seating) => seating.label), 'Another day'],
});The form in forms.ts has the name, the email, the day, the time, the number of guests and consent; the bot sees the day, the time and the number of guests, never the contact details. onLead in route.ts books it:
const onLead = async ({ form, values }: ChatLeadReport): Promise<void> => {
if (form !== 'table') return;
const { name, email, day, seating, guests } = values;
// askdare validated the values against the form: these checks only narrow the types.
if (typeof name !== 'string' || typeof email !== 'string') return;
if (!isWeekday(day) || !isSeating(seating) || typeof guests !== 'string') return;
const table = await restaurant.book(day, seating, { name, email, guests: Number(guests) });
await sendEmail(
table
? { to: email, subject: `Your table on ${table.label}`, text: `Hello ${name},\n\nyour table for ${guests} is booked for ${table.label}. …` }
: { to: email, subject: 'Your table', text: `Hello ${name},\n\nthat seating has just filled up. …` },
);
};onLead runs after the guest saw the form's "Thanks", so when the seating filled up in the meantime, the email says so.
Make it yours
| Replace | With | Guide |
|---|---|---|
HOTEL in hotel.ts | Your venue: coordinates, time zone, country and currency. For a travel agency, a list of destinations and a z.enum of their names in the tools' input, so the model picks one of yours and never sends coordinates | Tools: rules |
API_USER_AGENT | Your app's name and a contact, from your environment | MET Norway's terms |
The caches in metno.ts and holidays.ts | Your shared store (Redis, your database) when many instances call the API: one copy per forecast update for all of them | |
| OpenHolidays | For a country it doesn't cover, the date-holidays package (ISC, data under CC BY-SA 3.0, 207 countries), which needs no network; keep its credit | |
restaurant in restaurant.ts | Your table booking system's API: free tables per seating, and a booking that fails when the seating is full | |
sendEmail | Your mail provider, or let the booking system confirm | |
| The weekly grid | With tables that need a specific date, offer the booking through a tool with approval: the guest approves "Book a table for 2 on Saturday 12 Dec at 19:30", and the call runs with the arguments the server stored | Tools: approving a call |
| The cards | Your own components. Keep the credits where a guest can find them | React: tool cards |