12 lines
425 B
TypeScript
12 lines
425 B
TypeScript
export async function main(device: string, text: string) {
|
|
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 err = await res.json().catch(() => ({}));
|
|
throw new Error("alexa-api error " + res.status + ": " + JSON.stringify(err));
|
|
}
|
|
return await res.json();
|
|
} |