Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 21 additions & 33 deletions Bot/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from fastapi import FastAPI, Depends, HTTPException
from apscheduler.schedulers.background import BackgroundScheduler
import requests
import datetime
import os
import time
import threading
from google_auth_oauthlib.flow import Flow
from google.auth.transport.requests import Request as GoogleRequest
from google.oauth2.credentials import Credentials
import requests
from pydantic import BaseModel
from fastapi import FastAPI, Depends, HTTPException, Request
from fastapi.security import OAuth2AuthorizationCodeBearer
from starlette.middleware.cors import CORSMiddleware
from apscheduler.schedulers.background import BackgroundScheduler
from google_auth_oauthlib.flow import Flow, InstalledAppFlow
from google.auth.transport.requests import Request as GoogleRequest
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from selenium import webdriver
from selenium.webdriver.common.by import By
Expand All @@ -17,21 +19,18 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import datetime
from pydantic import BaseModel
from helper import monitor_meeting, google_login
from config import config
from fastapi import FastAPI, Depends, HTTPException, Request
from fastapi.security import OAuth2AuthorizationCodeBearer
from google.auth.transport.requests import Request as GoogleRequest
from google.oauth2.credentials import Credentials
from starlette.middleware.cors import CORSMiddleware
from google_auth_oauthlib.flow import Flow
from googleapiclient.discovery import build
import datetime
import os
import time
from app.log_config import logger
from app.core.config import (
SCOPES,
CLIENT_SECRETS_FILE,
REDIRECT_URI,
OAUTH2_SCHEME,
SCHEDULE_JOIN_BOT_URL,
JOIN_MEETING_URL,
BOT_SERVER_HOST,
BOT_SERVER_PORT
)

# app = FastAPI()
# SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
Expand Down Expand Up @@ -91,18 +90,7 @@ class ScheduleBotRequest(BaseModel):
allow_headers=["*"], # Allows all headers
)

SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
CLIENT_SECRETS_FILE = 'credentials.json'
#REDIRECT_URI = "http://localhost:8000/auth/google/callback"
REDIRECT_URI = os.getenv("REDIRECT_URIS")
SCHEDULE_JOIN_BOT_URL = os.getenv("SCHEDULE_JOIN_BOT_URL")
JOIN_MEETING_URL=os.getenv("JOIN_MEETING_URL")

# OAuth setup
OAUTH2_SCHEME = OAuth2AuthorizationCodeBearer(
tokenUrl="",
authorizationUrl="https://accounts.google.com/o/oauth2/auth"
)
# OAuth setup - using config from app.core.config

scheduler = BackgroundScheduler()
scheduler.start()
Expand Down Expand Up @@ -267,4 +255,4 @@ def join_meeting_with_retry():

if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)
uvicorn.run(app, host=BOT_SERVER_HOST, port=BOT_SERVER_PORT)
32 changes: 16 additions & 16 deletions Bot/app/api/meetings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from pydantic import BaseModel
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from app.core.config import OAUTH2_SCHEME
from app.core.config import (
OAUTH2_SCHEME,
CLIENT_ID,
CLIENT_SECRET,
TOKEN_URI,
REDIS_HOST,
REDIS_PORT,
REDIS_DB,
LINGO_API_URL,
GET_MEETING_URL,
SCHEDULE_JOIN_BOT_URL,
WEBHOOK_ADDR
)
import datetime
import requests
from app.helper.generate_presigned_url import generate_presigned_url, extract_file_url
Expand All @@ -12,23 +24,11 @@
import redis
from uuid import uuid4
import json
from app.core import config
import os

# Now you can access the values like this:
CLIENT_ID = os.getenv("CLIENT_ID")
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
TOKEN_URI = os.getenv("TOKEN_URI")
REDIRECT_URIS = os.getenv("REDIRECT_URIS")

redis_client = redis.Redis(host='redis', port=6379, db=0, decode_responses=True)
redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, decode_responses=True)

router = APIRouter(prefix="/meetings", tags=["Meetings"])

LINGO_API_URL = os.getenv("LINGO_API_URL")
GET_MEETING_URL=os.getenv("GET_MEETING_URL")
SCHEDULE_JOIN_BOT_URL=os.getenv("SCHEDULE_JOIN_BOT_URL")

class LingoRequest(BaseModel):
key: str

Expand Down Expand Up @@ -115,7 +115,7 @@ def get_meetings(body: ScheduleMeeting, token: str = Depends(OAUTH2_SCHEME)):
@router.post("/call-to-lingo")
def call_to_lingo(request: LingoRequest):
# import pdb; pdb.set_trace()
logger.info(f"Call Recieved for {request.key}")
logger.info(f"Call Received for {request.key}")
presigned_url = generate_presigned_url(request.key)

if not presigned_url:
Expand Down Expand Up @@ -170,7 +170,7 @@ def watch_calendar(token: str = Depends(OAUTH2_SCHEME), refresh_token: str = Bod
body = {
"id": channel_id,
"type": "web_hook",
"address": config.WEBHOOK_ADDR, # your webhook receiver
"address": WEBHOOK_ADDR, # your webhook receiver
"params": {
"ttl": "604800"
},
Expand Down
3 changes: 1 addition & 2 deletions Bot/app/api/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from app.core.scheduler import scheduler
from app.helper.bot_actions import join_meeting_with_retry
from app.models.schemas import ScheduleBotRequest
from app.core.config import JOIN_MEETING_URL
import requests
import time
import threading
from app.log_config import logger
import os

router = APIRouter(prefix="/scheduler", tags=["Scheduler"])
JOIN_MEETING_URL = os.getenv("JOIN_MEETING_URL")


def background_join_meeting(meeting_url, bot_name):
Expand Down
51 changes: 51 additions & 0 deletions Bot/app/core/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
from fastapi.security import OAuth2AuthorizationCodeBearer

# Google OAuth Configuration
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
CLIENT_SECRETS_FILE = 'credentials.json'
REDIRECT_URI = os.getenv("REDIRECT_URIS")

# OAuth2 Scheme
OAUTH2_SCHEME = OAuth2AuthorizationCodeBearer(
tokenUrl="",
authorizationUrl="https://accounts.google.com/o/oauth2/auth"
)

# API URLs
SCHEDULE_JOIN_BOT_URL = os.getenv("SCHEDULE_JOIN_BOT_URL")
JOIN_MEETING_URL = os.getenv("JOIN_MEETING_URL")
LINGO_API_URL = os.getenv("LINGO_API_URL")
GET_MEETING_URL = os.getenv("GET_MEETING_URL")
LINGO_CALLBACK_URL = os.getenv("LINGO_CALLBACK_URL")
LINGO_SAVE_TRANSCRIPTION_URL = os.getenv("LINGO_SAVE_TRANSCRIPTION_URL", "https://lingo.ai.joshsoftware.com/api/transcribe/save")

# Redis Configuration with safe defaults
REDIS_HOST = os.getenv("REDIS_HOST", "redis")
try:
REDIS_PORT = int(os.getenv("REDIS_PORT", "6379"))
except (ValueError, TypeError):
REDIS_PORT = 6379

try:
REDIS_DB = int(os.getenv("REDIS_DB", "0"))
except (ValueError, TypeError):
REDIS_DB = 0

# Server Configuration with safe defaults
BOT_SERVER_HOST = os.getenv("BOT_SERVER_HOST", "0.0.0.0")
try:
BOT_SERVER_PORT = int(os.getenv("BOT_SERVER_PORT", "8001"))
except (ValueError, TypeError):
BOT_SERVER_PORT = 8001

# Google OAuth Credentials
CLIENT_ID = os.getenv("CLIENT_ID")
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
TOKEN_URI = os.getenv("TOKEN_URI")

# Webhook Configuration
WEBHOOK_ADDR = os.getenv("WEBHOOK_ADDR")

# User Configuration
USER_ID = os.getenv("USER_ID")
2 changes: 1 addition & 1 deletion Bot/app/helper/bot_actions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import requests
import time
import os
from app.core.config import JOIN_MEETING_URL

def join_meeting_with_retry(meeting_url: str, bot_name: str):
attendee_api_key = os.getenv("ATTENDEE_API_KEY")
JOIN_MEETING_URL=os.getenv("JOIN_MEETING_URL")
headers={
"Authorization": f"Token {attendee_api_key}",
"Content-Type": "application/json"
Expand Down
9 changes: 3 additions & 6 deletions Bot/app/helper/save_transaction.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import requests
import app.core.config as config
from app.core.config import USER_ID, LINGO_SAVE_TRANSCRIPTION_URL

def save_transcription(response, document_url, document_name):
# Prepare the payload
# import pdb; pdb.set_trace()
payload = {
"documentUrl": document_url,
"userID": config.USER_ID,
"userID": USER_ID,
"documentName": document_name,
"summary": response["summary"],
"translation": response["translation"],
"audioDuration": response.get("audioDuration", 0), # Assuming you might add this later
"segments": response["segments"]
}

# API endpoint
endpoint = "https://lingo.ai.joshsoftware.com/api/transcribe/save"

# Send the POST request
try:
res = requests.post(endpoint, json=payload)
res = requests.post(LINGO_SAVE_TRANSCRIPTION_URL, json=payload)
res.raise_for_status() # Raise an exception for HTTP errors (4xx, 5xx)
return res.json()
except requests.exceptions.RequestException as e:
Expand Down
14 changes: 13 additions & 1 deletion Bot/env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ CLIENT_ID=
CLIENT_SECRET=
TOKEN_URI=
REDIRECT_URIS=
LINGO_API_URL=
LINGO_API_URL=
SCHEDULE_JOIN_BOT_URL=
JOIN_MEETING_URL=
GET_MEETING_URL=
LINGO_CALLBACK_URL=
LINGO_SAVE_TRANSCRIPTION_URL=https://lingo.ai.joshsoftware.com/api/transcribe/save
WEBHOOK_ADDR=
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=0
BOT_SERVER_HOST=0.0.0.0
BOT_SERVER_PORT=8001
USER_ID=
8 changes: 7 additions & 1 deletion Bot/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import uvicorn
import os

if __name__ == "__main__":
uvicorn.run("app.main:app", host="0.0.0.0", port=8001, reload=True)
host = os.getenv("BOT_SERVER_HOST", "0.0.0.0")
try:
port = int(os.getenv("BOT_SERVER_PORT", "8001"))
except (ValueError, TypeError):
port = 8001
uvicorn.run("app.main:app", host=host, port=port, reload=True)
2 changes: 1 addition & 1 deletion attendee/bots/bot_controller/bot_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

class BotController:
def call_lingo_callback(self, file_key):
url = "http://lingo-bot:8001/meetings/call-to-lingo"
url = os.environ.get("LINGO_CALLBACK_URL", "http://lingo-bot:8001/meetings/call-to-lingo")
logger.info(os.environ.get('AWS_RECORDING_STORAGE_BUCKET_NAME'))
payload = {"key": f"s3://{os.environ.get('AWS_RECORDING_STORAGE_BUCKET_NAME')}/{file_key}"}

Expand Down
4 changes: 3 additions & 1 deletion attendee/env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ DJANGO_SECRET_KEY=
AWS_RECORDING_STORAGE_BUCKET_NAME=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
AWS_REGION=
# Lingo API callback URL
LINGO_CALLBACK_URL=http://lingo-bot:8001/meetings/call-to-lingo