30 lines
792 B
TypeScript
30 lines
792 B
TypeScript
export async function main(
|
|
device: string = "オフィスの右エコー",
|
|
prefix: string = "現在時刻は",
|
|
suffix: string = "です"
|
|
) {
|
|
const now = new Date();
|
|
const hhmm = new Intl.DateTimeFormat("ja-JP", {
|
|
timeZone: "Asia/Tokyo",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
hour12: false,
|
|
}).format(now); // 例: 09:30
|
|
|
|
const [h, m] = hhmm.split(":");
|
|
const text = `${prefix}${Number(h)}時${Number(m)}分${suffix}`;
|
|
|
|
const res = await fetch("http://alexa_api:3500/speak", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ device, text }),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const body = await res.text();
|
|
throw new Error(`alexa-api error ${res.status}: ${body}`);
|
|
}
|
|
|
|
return { ok: true, device, text };
|
|
}
|