File size: 962 Bytes
2f37a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04ec209
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse
from py_mini_racer import py_mini_racer

app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")

@app.get("/")
async def index():
    # Create an instance of PyMiniRacer
    ctx = py_mini_racer.MiniRacer()

    # Read the JavaScript code
    with open("static/script.js", "r") as file:
        javascript_code = file.read()

    # Execute the JavaScript code
    ctx.execute(javascript_code)

    # Get the result of the JavaScript execution
    result = ctx.eval("window.voiceflow.chat.load({ verify: { projectID: '656181267913810007e3e0b5' }, url: 'https://general-runtime.voiceflow.com', versionID: 'production' });")

    # Return the result as HTML response
    return HTMLResponse(content=result, status_code=200)

#if __name__ == "__main__":
#    import uvicorn
#    uvicorn.run(app, host="0.0.0.0", port=8000)