diff --git a/functions/voice/token.ts b/functions/voice/token.ts index f56c2c9..fa6c596 100644 --- a/functions/voice/token.ts +++ b/functions/voice/token.ts @@ -1,16 +1,16 @@ -import axios from 'axios'; - interface Env { VOICE_TOKEN: string; } - export const onRequest: PagesFunction = async (context) => { try { - const response = await axios.post('https://api.assemblyai.com/v2/realtime/token', // use account token to get a temp user token - {expires_in: 3600}, // can set a TTL timer in seconds. - {headers: {authorization: context.env.VOICE_TOKEN}}); - const {data} = response; - return new Response(JSON.stringify(data), {status: 200}); + const res = await fetch('https://api.assemblyai.com/v2/realtime/token', + { + method: 'POST', + body: JSON.stringify({expires_in: 3600}), + headers: {authorization: context.env.VOICE_TOKEN} + }); + const response = await res.json(); + return new Response(JSON.stringify(response), {status: 200}); } catch (error) { return new Response(error.message, {status: 500}); }