-
Notifications
You must be signed in to change notification settings - Fork 0
/
meeting-email
191 lines (169 loc) · 6.84 KB
/
meeting-email
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
187
188
189
190
191
import json
import os
import boto3
from botocore.exceptions import ClientError
from datetime import datetime, timedelta
import threading
import time
import urllib
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
DB = boto3.resource(
'dynamodb',
)
table_name = "meeting-details"
mutex = threading.Lock()
def lambda_handler(event, context):
# TODO implement
print(event)
meeting_id = event['headers']["meetingid"]
#meeting_id = "RIPSKPNUG"
print(meeting_id)
meeting_details = lookup_data({'meetingID': meeting_id})
email_data = ""
trs_data = ""
transcriptUrl = "https://cvc-meeting-recordings.s3.amazonaws.com/" + meeting_id + "/" + meeting_id + "_cgpt_analysis.txt"
transcriptS3Url = transcriptUrl
try:
response = urllib.request.urlopen(transcriptS3Url)
transcript = response.read().decode('utf-8')
trs_data += "Transcript of chat GPT: " + transcript + '\n'
transcriptS3Url = "https://cvc-meeting-recordings.s3.amazonaws.com/" + meeting_id + "/" + meeting_id + "_english_transcript.txt"
response = urllib.request.urlopen(transcriptS3Url)
transcript = response.read().decode('utf-8')
trs_data += "Transcript in English: " + transcript + '\n'
transcriptS3Url = "https://cvc-meeting-recordings.s3.amazonaws.com/" + meeting_id + "/" + meeting_id + "_german_transcript.txt"
response = urllib.request.urlopen(transcriptS3Url)
transcript = response.read().decode('utf-8')
trs_data += "Transcript in German: " + transcript + '\n'
transcriptS3Url = "https://cvc-meeting-recordings.s3.amazonaws.com/" + meeting_id + "/" + meeting_id + "_hindi_transcript.txt"
response = urllib.request.urlopen(transcriptS3Url)
transcript = response.read().decode('utf-8')
trs_data += "Transcript in Hindi: " + transcript + '\n'
transcriptS3Url = "https://cvc-meeting-recordings.s3.amazonaws.com/" + meeting_id + "/" + meeting_id + "_chinese_transcript.txt"
response = urllib.request.urlopen(transcriptS3Url)
transcript = response.read().decode('utf-8')
trs_data += "Transcript in Chinese: " + transcript + '\n'
transcriptS3Url = "https://cvc-meeting-recordings.s3.amazonaws.com/" + meeting_id + "/" + meeting_id + "_spanish_transcript.txt"
response = urllib.request.urlopen(transcriptS3Url)
transcript = response.read().decode('utf-8')
trs_data += "Transcript in Spanish: " + transcript + '\n'
videoUrl = "https://cvc-meeting-recordings.s3.amazonaws.com/" + meeting_id + "/" + meeting_id + ".mp4"
trs_data += "Video Link: " + videoUrl + '\n'
except Exception as e:
trs_data = "Recording not analysed yet"
print(e)
trs_data += '\n\n'
print(trs_data)
email_data += trs_data
for participant in meeting_details["participants"]:
participant_details = lookup_data({'userId': participant}, table = "meeting-analysis")
try:
available_sessions = participant_details["available"]
if participant not in available_sessions:
available_sessions.append(meeting_id)
except:
available_sessions = [meeting_id]
mutex.acquire()
try:
update_item({'userId': participant}, 'available', available_sessions, table = "meeting-analysis")
finally:
mutex.release()
for meeting in participant_details["meetings"]:
if meeting_id == meeting["meetingId"]:
dets = lookup_data({'userId': participant}, table = "email_data")
if meeting_details["host"] != participant:
print(dets["email"])
print("inside")
send_email(dets["email"], trs_data + dets["email"] + '\n' + str(meeting))
email_data += dets["email"] + '\n' + str(meeting) + '\n\n'
break
dets = lookup_data({'userId': meeting_details["host"]}, table = "email_data")
print(dets["email"])
print(email_data)
send_email(dets["email"], str(email_data))
headers = {
"Access-Control-Allow-Origin": "*", # Replace * with your allowed origin(s)
"Access-Control-Allow-Headers": "Content-Type, meetingid", # Include allowed headers
"Access-Control-Allow-Methods": "OPTIONS,POST,GET" # Include allowed methods
}
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!'),
'headers': headers
}
def insert_data(data, db=None, table=table_name):
if not db:
db = DB
table = db.Table(table)
with table.batch_writer() as batch:
# overwrite if the same index is provided
response = table.put_item(Item=data)
return response
def lookup_data(key, db=None, table=table_name):
if not db:
db = DB
table = db.Table(table)
try:
response = table.get_item(Key=key)
except ClientError as e:
print('Error', e.response['Error']['Message'])
else:
try:
return response['Item']
except:
return "Error"
def update_item(key, feature_key, feature_value, db=None, table=table_name):
if not db:
db = DB
table = db.Table(table)
# change student location
response = table.update_item(
Key=key,
UpdateExpression="set #feature=:f",
ExpressionAttributeValues={
':f': feature_value
},
ExpressionAttributeNames={
"#feature": feature_key
},
ReturnValues="UPDATED_NEW"
)
return response
def delete_item(key, db=None, table=table_name):
if not db:
db = DB
table = db.Table(table)
try:
response = table.delete_item(Key=key)
except ClientError as e:
print('Error', e.response['Error']['Message'])
else:
return response
def send_email(recipient_email, body):
CHARSET = "utf-8"
client = boto3.client('ses')
Sender = "ag4797@columbia.edu"
msg = MIMEMultipart('mixed')
msg['Subject'] = "Meeting details"
msg['From'] = Sender
msg['To'] = recipient_email
msg_body = MIMEMultipart('alternative')
textpart = MIMEText(body.encode(CHARSET), 'plain', CHARSET)
msg_body.attach(textpart)
msg.attach(msg_body)
try:
response = client.send_raw_email(
Source=Sender,
Destinations=[
recipient_email
],
RawMessage={
'Data':msg.as_string(),
})
except ClientError as e:
print(e.response['Error']['Message'])
else:
print("Email sent! Message ID:"),
print(response['MessageId'])