added implementation of voice token.
This commit is contained in:
parent
00dac7f4ec
commit
b714ffb025
@ -1,4 +0,0 @@
|
||||
export const onRequest: PagesFunction = async (context) => {
|
||||
const response = new Response('Hello World!');
|
||||
return response;
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "Node",
|
||||
"lib": [
|
||||
"esnext"
|
||||
],
|
||||
|
||||
17
functions/voice/token.ts
Normal file
17
functions/voice/token.ts
Normal 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});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user