diff --git a/functions/src/voiceServer.ts b/functions/src/voiceServer.ts deleted file mode 100644 index 1933e39..0000000 --- a/functions/src/voiceServer.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const onRequest: PagesFunction = async (context) => { - const response = new Response('Hello World!'); - return response; -} \ No newline at end of file diff --git a/functions/tsconfig.json b/functions/tsconfig.json index 034c8ba..42a26dc 100644 --- a/functions/tsconfig.json +++ b/functions/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "esnext", "module": "esnext", + "moduleResolution": "Node", "lib": [ "esnext" ], diff --git a/functions/voice/token.ts b/functions/voice/token.ts new file mode 100644 index 0000000..f56c2c9 --- /dev/null +++ b/functions/voice/token.ts @@ -0,0 +1,17 @@ +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}); + } catch (error) { + return new Response(error.message, {status: 500}); + } +}