File size: 9,202 Bytes
abd17e2
 
 
de241f7
abd17e2
de241f7
abd17e2
de241f7
abd17e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de241f7
abd17e2
 
 
 
 
 
 
 
 
e8dca67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de241f7
 
 
 
 
 
 
 
 
abd17e2
 
 
 
de241f7
 
 
 
 
 
 
 
abd17e2
 
 
 
 
 
 
 
 
 
 
 
e8dca67
abd17e2
 
413f4ad
 
 
abd17e2
 
 
 
 
e8dca67
 
 
8e2d895
abd17e2
e8dca67
 
abd17e2
 
 
 
 
 
 
 
413f4ad
 
abd17e2
 
413f4ad
 
abd17e2
 
413f4ad
 
abd17e2
 
e8dca67
 
abd17e2
 
 
 
de241f7
 
 
32ddb83
 
de241f7
 
 
 
 
 
 
413f4ad
 
de241f7
 
413f4ad
 
de241f7
 
413f4ad
 
de241f7
 
 
 
 
32ddb83
de241f7
abd17e2
de241f7
abd17e2
 
 
de241f7
abd17e2
 
 
 
 
 
 
 
 
 
 
de241f7
413f4ad
de241f7
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import requests
import json
import os
import uuid
import streamlit as st
from azure.cosmos import CosmosClient
from datetime import datetime, timedelta
from ParamClasses import CreateParams, AppointmentDBItem, Attendee
from dotenv import load_dotenv

load_dotenv()

def create_meeting(input_params: CreateParams) -> dict:
    try:
        url = f"{os.environ.get('BASE_API')}/api/create-appointment"
        response = requests.post(url=url,data=input_params)
        response.raise_for_status()  
        return response.json()
    except Exception as e: 
        print(f"Fehler beim erstellen des Termins: {str(e)}")
        st.error("Something went wrong, please contact the site admin.", icon="🚨")

def get_summary(input_params) -> dict:
    print(input_params)
    try:
        url = f"{os.environ.get('BASE_API')}/api/create-interview-summary"
        response = requests.post(url=url,data=input_params)
        response.raise_for_status()  
        return response.json()
    except Exception as e: 
        print(f"Fehler beim erstellen des Termins: {str(e)}")
        st.error(f"Something went wrong: {str(e)}", icon="🚨")

def adjust_datetime(original_datetime_str, offset_option):
    # Konvertiere den originalen DateTime-String in ein datetime-Objekt
    original_datetime = datetime.strptime(original_datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ")

    # Überprüfe das Vorzeichen im Offset-String
    if offset_option.startswith('+'):
        # Wenn das Vorzeichen ein Pluszeichen ist, negiere den Offset
        offset_option = '-' + offset_option[1:]
    elif offset_option.startswith('-'):
        offset_option = '+' + offset_option[1:]
    else:
        # Wenn kein Vorzeichen vorhanden ist, füge ein Minuszeichen hinzu
        offset_option = '' + offset_option

    # Konvertiere die Offset-Option von String zu integer
    offset_hours = int(offset_option)

    # Erzeuge ein timedelta-Objekt mit dem entsprechenden Offset
    offset_delta = timedelta(hours=offset_hours)

    # Passe das ursprüngliche datetime-Objekt an
    adjusted_datetime = original_datetime + offset_delta

    # Formatieren und zurückgeben
    adjusted_datetime_str = adjusted_datetime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
    return adjusted_datetime_str

def write_appointment_db_object(interview_data: AppointmentDBItem):
    print("hitesttest")
    try:
        st.session_state["cosmos_db"].create_item(body=interview_data.model_dump())
    except Exception as e: 
        print(f"Fehler beim erstellen des DB items: {str(e)}")
        st.error("Something went wrong, please contact the site admin.", icon="🚨")


if "appointment_response" not in st.session_state:
    st.session_state["appointment_response"] = None
if "subject_input" not in st.session_state:
    st.session_state["subject_input"] = None
if "cosmos_db" not in st.session_state:
    # Cosmos DB Client erstellen
    client = CosmosClient(os.environ.get('DB_CONNECTION'), os.environ.get('DB_KEY'))

    # Datenbank und Container referenzieren
    database = client.get_database_client(os.environ.get('DB_NAME'))
    container = database.get_container_client(os.environ.get('DB_CONTAINER'))
    st.session_state["cosmos_db"] = container
    
col1, col2 = st.columns([2, 1])

col1.title("Appointment Tool")
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")

st.write("Please enter the date, time and duration for the appointment to be created.")

selected_date = st.date_input("Date of the appointment",format="DD/MM/YYYY")
now = datetime.now()
rounded_now = now + timedelta(minutes=30 - now.minute % 30)
selected_time = st.time_input("Starting time of the appointment", value=rounded_now)
time_zone = st.selectbox("Please select your time zone (based on UTC time)",options=["+10","+9","+8","+7","+6","+5","+4","+3","+2","+1","0","-1","-2","-3","-4","-5","-6","-7","-8","-9","-10"],index=10, key="time_option")
selected_duration = st.select_slider("Duration of the appointment in minutes",[15,30,45,60],value=30)
subject_input = st.text_input("Enter the subject of the meeting")
# recruiter_mail = st.text_input("Please enter the mail of the recruiter", key="recruiter_mail")
# client_mail = st.text_input("Please enter the mail of the client", key="client_mail")
# candidate_mail = st.text_input("Please enter the mail of the candidate", key="candidate_mail")

if not st.session_state["appointment_response"]:
    if st.button("Create appointment") or st.session_state["appointment_response"]:
        print("nach button appointment")
        if subject_input:
            start_date_utc_str = datetime.strptime(str(selected_date)+" "+str(selected_time),"%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%dT%H:%M:%S.%fZ")
            print(start_date_utc_str)
            start_date_str = adjust_datetime(start_date_utc_str, st.session_state["time_option"])
            print(start_date_str)
            end_date = datetime.strptime(str(selected_date)+" "+str(selected_time),"%Y-%m-%d %H:%M:%S") + timedelta(minutes=selected_duration)
            end_date_utc_str = end_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
            end_date_str = adjust_datetime(end_date_utc_str, st.session_state["time_option"])
            with st.spinner("Creating the appointment..."):
                request_params = json.dumps({
                    "appointment": {
                        "start_time": start_date_str,
                        "end_time": end_date_str
                    },
                    "subject": subject_input,
                    "recruiter": {
                        "email": "",#st.session_state["recruiter_mail"],
                        "name": ""#st.session_state["recruiter_mail"]
                    },
                    "client": {
                        "email": "",#st.session_state["client_mail"],
                        "name": ""#st.session_state["client_mail"]
                    },
                    "candidate": {
                        "email": "",#st.session_state["candidate_mail"],
                        "name": ""#st.session_state["candidate_mail"]
                    }
                })
                appointment_response = create_meeting(request_params)
                # appointment_response = False
                # st.write(appointment_response)
            if appointment_response:
                
                st.success("The appointment was created correctly.")
                st.write(appointment_response["zoom_meeting"]["start_url"])
                db_item = AppointmentDBItem(
                    id=str(uuid.uuid4()),
                    zoom_meeting_id=str(appointment_response["zoom_meeting"]["id"]),
                    process_id=str(uuid.uuid4()),
                    job_title=subject_input,
                    start_time=start_date_str,
                    end_time=end_date_str,
                    meeting_url=appointment_response["zoom_meeting"]["start_url"],
                    environment=str(["us"]),
                    process_status="interview_scheduled",
                    recruiter=Attendee(
                        email="",#str(st.session_state["recruiter_mail"]),
                        name=""#str(st.session_state["recruiter_mail"])
                    ),
                    client=Attendee(
                        email="",#str(st.session_state["client_mail"]),
                        name=""#str(st.session_state["client_mail"])
                    ),
                    candidate=Attendee(
                        email="",#str(st.session_state["candidate_mail"]),
                        name=""#str(st.session_state["candidate_mail"])
                    ),
                    summary_recruiter="",
                    summary_client="",
                    summary_candidate=""
                )
                write_appointment_db_object(db_item)
                st.info("Once you have attended the meeting and it has ended, please wait about 10 minutes before requesting the meeting recording as it will take time to become available ", icon="ℹ️")
                st.session_state["appointment_response"] = appointment_response
                print(appointment_response["zoom_meeting"]["id"])
                st.session_state["subject_input"] = subject_input
                if st.button("Create Interview Summary"):
                    print("please")
                    print(st.session_state["appointment_response"]["zoom_meeting"]["id"])
                    st.rerun()
                    # print("nach btn summary")
                    # with st.spinner("Creating the summary..."):
                    #     summary_response = get_summary({"interview_subject": subject_input})
                    # if summary_response:
                    #     st.write(summary_response)
                             
        else: 
            st.warning("Please enter the subject of the meeting")
else: 
    with st.spinner("Creating the summary..."):
        summary_response = get_summary(json.dumps({"meeting_id": str(st.session_state["appointment_response"]["zoom_meeting"]["id"])}))
        #summary_response = get_summary(json.dumps({"meeting_id": str(85662554678)}))
    st.write(summary_response)