Update routes/support.py
Browse files- routes/support.py +9 -14
routes/support.py
CHANGED
@@ -180,7 +180,7 @@ async def respond_ticket(
|
|
180 |
user_name = user_data[0].get("name", "user").strip()
|
181 |
first_name = user_name.split(" ")[0] if user_name else "user"
|
182 |
|
183 |
-
# 4. Pega o nome do atendente
|
184 |
async with aiohttp.ClientSession() as session:
|
185 |
async with session.get(
|
186 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{support_id}",
|
@@ -195,9 +195,9 @@ async def respond_ticket(
|
|
195 |
|
196 |
support_name = support_data[0].get("name", "Support Team")
|
197 |
|
198 |
-
# 5. Envia o e-mail com HTML
|
199 |
access_token = await get_gmail_access_token()
|
200 |
-
subject = f"
|
201 |
|
202 |
email_html = f"""\
|
203 |
<!DOCTYPE html>
|
@@ -211,17 +211,12 @@ async def respond_ticket(
|
|
211 |
<td align="center" style="padding:30px 10px;">
|
212 |
<table width="600" cellpadding="0" cellspacing="0" border="0" style="background:#ffffff;border:1px solid #ccc;border-radius:5px;">
|
213 |
<tr>
|
214 |
-
<td
|
215 |
-
<img src="https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/saa-s-cloud-file-management-dashboard-u57zo5/assets/5l30gd1xml6i/Frame_1.png" width="26" height="14" alt="Logo" />
|
216 |
-
</td>
|
217 |
-
</tr>
|
218 |
-
<tr>
|
219 |
-
<td style="padding:0 40px 40px;font-family:Arial,sans-serif;font-size:14px;line-height:1.6;color:#333;">
|
220 |
<p>Hello {first_name},</p>
|
221 |
|
222 |
{payload.content}
|
223 |
|
224 |
-
<p>Kind regards,<br>{support_name}<br>
|
225 |
</td>
|
226 |
</tr>
|
227 |
</table>
|
@@ -233,7 +228,7 @@ async def respond_ticket(
|
|
233 |
"""
|
234 |
|
235 |
raw_message = f"""To: {user_email}
|
236 |
-
From: "ClosetCoach" <
|
237 |
Subject: {subject}
|
238 |
Content-Type: text/html; charset="UTF-8"
|
239 |
|
@@ -253,10 +248,10 @@ Content-Type: text/html; charset="UTF-8"
|
|
253 |
) as gmail_resp:
|
254 |
if gmail_resp.status != 200:
|
255 |
error_detail = await gmail_resp.text()
|
256 |
-
raise HTTPException(status_code=500, detail=f"
|
257 |
gmail_data = await gmail_resp.json()
|
258 |
|
259 |
-
# 6.
|
260 |
message_payload = {
|
261 |
"user": support_id,
|
262 |
"content": payload.content,
|
@@ -272,7 +267,7 @@ Content-Type: text/html; charset="UTF-8"
|
|
272 |
) as msg_resp:
|
273 |
if msg_resp.status != 201:
|
274 |
error_detail = await msg_resp.text()
|
275 |
-
raise HTTPException(status_code=500, detail=f"
|
276 |
|
277 |
return {
|
278 |
"status": "response sent successfully",
|
|
|
180 |
user_name = user_data[0].get("name", "user").strip()
|
181 |
first_name = user_name.split(" ")[0] if user_name else "user"
|
182 |
|
183 |
+
# 4. Pega o nome do atendente
|
184 |
async with aiohttp.ClientSession() as session:
|
185 |
async with session.get(
|
186 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{support_id}",
|
|
|
195 |
|
196 |
support_name = support_data[0].get("name", "Support Team")
|
197 |
|
198 |
+
# 5. Envia o e-mail com HTML simplificado
|
199 |
access_token = await get_gmail_access_token()
|
200 |
+
subject = f"ClosetCoach Support – Case {payload.ticket_id}"
|
201 |
|
202 |
email_html = f"""\
|
203 |
<!DOCTYPE html>
|
|
|
211 |
<td align="center" style="padding:30px 10px;">
|
212 |
<table width="600" cellpadding="0" cellspacing="0" border="0" style="background:#ffffff;border:1px solid #ccc;border-radius:5px;">
|
213 |
<tr>
|
214 |
+
<td style="padding:20px;font-family:Arial,sans-serif;font-size:16px;line-height:1.6;color:#333;">
|
|
|
|
|
|
|
|
|
|
|
215 |
<p>Hello {first_name},</p>
|
216 |
|
217 |
{payload.content}
|
218 |
|
219 |
+
<p>Kind regards,<br>{support_name}<br>ClosetCoach Support</p>
|
220 |
</td>
|
221 |
</tr>
|
222 |
</table>
|
|
|
228 |
"""
|
229 |
|
230 |
raw_message = f"""To: {user_email}
|
231 |
+
From: "ClosetCoach Support" <support@closetcoach.com>
|
232 |
Subject: {subject}
|
233 |
Content-Type: text/html; charset="UTF-8"
|
234 |
|
|
|
248 |
) as gmail_resp:
|
249 |
if gmail_resp.status != 200:
|
250 |
error_detail = await gmail_resp.text()
|
251 |
+
raise HTTPException(status_code=500, detail=f"Error sending email: {error_detail}")
|
252 |
gmail_data = await gmail_resp.json()
|
253 |
|
254 |
+
# 6. Save response in messages_tickets
|
255 |
message_payload = {
|
256 |
"user": support_id,
|
257 |
"content": payload.content,
|
|
|
267 |
) as msg_resp:
|
268 |
if msg_resp.status != 201:
|
269 |
error_detail = await msg_resp.text()
|
270 |
+
raise HTTPException(status_code=500, detail=f"Error saving response: {error_detail}")
|
271 |
|
272 |
return {
|
273 |
"status": "response sent successfully",
|