added implementation of voice token.

This commit is contained in:
Michael Mainguy 2023-08-10 12:24:37 -05:00
parent 00dac7f4ec
commit b714ffb025
3 changed files with 18 additions and 4 deletions

View File

@ -1,4 +0,0 @@
export const onRequest: PagesFunction = async (context) => {
const response = new Response('Hello World!');
return response;
}

View File

@ -2,6 +2,7 @@
"compilerOptions": { "compilerOptions": {
"target": "esnext", "target": "esnext",
"module": "esnext", "module": "esnext",
"moduleResolution": "Node",
"lib": [ "lib": [
"esnext" "esnext"
], ],

17
functions/voice/token.ts Normal file
View File

@ -0,0 +1,17 @@
import axios from 'axios';
interface Env {
VOICE_TOKEN: string;
}
export const onRequest: PagesFunction<Env> = 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});
}
}