diff --git a/netlify/functions/voice/voice.ts b/netlify/functions/voice/voice.ts index 74086fd..e9754a2 100644 --- a/netlify/functions/voice/voice.ts +++ b/netlify/functions/voice/voice.ts @@ -1,9 +1,23 @@ import {Handler, HandlerContext, HandlerEvent} from "@netlify/functions"; +import axios from 'axios'; export const handler: Handler = async (event: HandlerEvent, context: HandlerContext) => { - // your server-side functionality - return { - statusCode: 200, - body: JSON.stringify({message: "Hello World"}), - }; + 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: process.env.VOICE_TOKEN}}); + + const data = await response.data; + return { + headers: {'Content-Type': 'application/json'}, + statusCode: 200, + body: JSON.stringify(data) + }; + + } catch (error) { + return { + statusCode: 500, + body: JSON.stringify(error) + } + } }; \ No newline at end of file