mirror of
https://github.com/System-End/nephthys.git
synced 2026-04-19 18:35:14 +00:00
assigned tickets on dashboard
This commit is contained in:
parent
fae7d1ad12
commit
6373be14c1
5 changed files with 133 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ from slack_sdk.web.async_client import AsyncWebClient
|
|||
|
||||
from nephthys.utils.env import env
|
||||
from nephthys.utils.logging import send_heartbeat
|
||||
from nephthys.views.home.assigned import get_assigned_tickets_view
|
||||
from nephthys.views.home.error import get_error_view
|
||||
from nephthys.views.home.helper import get_helper_view
|
||||
from nephthys.views.home.loading import get_loading_view
|
||||
|
|
@ -38,6 +39,8 @@ async def open_app_home(home_type: str, client: AsyncWebClient, user_id: str):
|
|||
match home_type:
|
||||
case "default" | "dashboard":
|
||||
view = await get_helper_view(user)
|
||||
case "assigned-tickets":
|
||||
view = await get_assigned_tickets_view(user)
|
||||
case "tags":
|
||||
view = await get_manage_tags_view(user)
|
||||
case "my-stats":
|
||||
|
|
|
|||
|
|
@ -136,9 +136,33 @@ async def on_message(event: Dict[str, Any], client: AsyncWebClient):
|
|||
unfurl_media=True,
|
||||
)
|
||||
|
||||
async with env.session.post(
|
||||
"https://ai.hackclub.com/chat/completions",
|
||||
json={
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a helpful assistant that helps organise tickets for Hack Club's support team. You're going to take in a message and give it a title. You will return no other content. Even if it's silly please summarise it. Use no more than 7 words, but as few as possible.",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"Here is a message from a user: {text}\n\nPlease give this ticket a title.",
|
||||
},
|
||||
]
|
||||
},
|
||||
) as res:
|
||||
if res.status != 200:
|
||||
await send_heartbeat(
|
||||
f"Failed to get AI response for ticket creation: {res.status} - {await res.text()}"
|
||||
)
|
||||
title = "No title provided by AI."
|
||||
else:
|
||||
data = await res.json()
|
||||
title = data["choices"][0]["message"]["content"].strip()
|
||||
|
||||
await env.db.ticket.create(
|
||||
{
|
||||
"title": f"New ticket from {user}",
|
||||
"title": title,
|
||||
"description": text,
|
||||
"msgTs": event["ts"],
|
||||
"ticketTs": ticket["ts"],
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ async def app_home_opened_handler(event: dict[str, Any], client: AsyncWebClient)
|
|||
|
||||
|
||||
@app.action("dashboard")
|
||||
@app.action("assigned-tickets")
|
||||
@app.action("tags")
|
||||
@app.action("my-stats")
|
||||
async def manage_home_switcher(ack: AsyncAck, body, client: AsyncWebClient):
|
||||
|
|
|
|||
94
nephthys/views/home/assigned.py
Normal file
94
nephthys/views/home/assigned.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import pytz
|
||||
|
||||
from nephthys.utils.env import env
|
||||
from nephthys.views.home.components.buttons import get_buttons
|
||||
from prisma.enums import TicketStatus
|
||||
from prisma.models import User
|
||||
|
||||
|
||||
async def get_assigned_tickets_view(user: User):
|
||||
btns = get_buttons(user, "assigned-tickets")
|
||||
|
||||
tickets = (
|
||||
await env.db.ticket.find_many(
|
||||
where={"assignedToId": user.id, "NOT": [{"status": TicketStatus.CLOSED}]},
|
||||
include={"openedBy": True},
|
||||
)
|
||||
or []
|
||||
)
|
||||
|
||||
if not tickets:
|
||||
return {
|
||||
"type": "home",
|
||||
"blocks": [
|
||||
{
|
||||
"type": "header",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": ":rac_cute: no assigned tickets",
|
||||
"emoji": True,
|
||||
},
|
||||
},
|
||||
btns,
|
||||
{"type": "divider"},
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": ":rac_believes_in_theory_about_green_lizards_and_space_lasers: you don't have any assigned tickets right now!",
|
||||
"emoji": True,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
ticket_blocks = []
|
||||
for ticket in tickets:
|
||||
unix_ts = int(ticket.createdAt.timestamp())
|
||||
time_ago_str = f"<!date^{unix_ts}^opened {{ago}}|at {ticket.createdAt.astimezone(pytz.timezone('Europe/London')).strftime('%H:%M %Z')}>"
|
||||
ticket_blocks.append(
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": f"*{ticket.title}*\n _from <@{ticket.openedBy.slackId}>. {time_ago_str}_",
|
||||
},
|
||||
"accessory": {
|
||||
"type": "button",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": ":rac_info: view ticket",
|
||||
"emoji": True,
|
||||
},
|
||||
"action_id": f"view-ticket-{ticket.msgTs}",
|
||||
"url": f"https://hackclub.slack.com/archives/{env.slack_help_channel}/p{ticket.msgTs.replace('.', '')}",
|
||||
"value": ticket.msgTs,
|
||||
},
|
||||
}
|
||||
)
|
||||
ticket_blocks.append({"type": "divider"})
|
||||
|
||||
return {
|
||||
"type": "home",
|
||||
"blocks": [
|
||||
{
|
||||
"type": "header",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": ":rac_cute: helper heidi",
|
||||
"emoji": True,
|
||||
},
|
||||
},
|
||||
btns,
|
||||
{"type": "divider"},
|
||||
{
|
||||
"type": "header",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": ":rac_cute: here are your assigned tickets <3",
|
||||
"emoji": True,
|
||||
},
|
||||
},
|
||||
*ticket_blocks,
|
||||
],
|
||||
}
|
||||
|
|
@ -12,7 +12,16 @@ def get_buttons(user: User, current: str = "dashboard"):
|
|||
**({"style": "primary"} if current != "dashboard" else {}),
|
||||
}
|
||||
)
|
||||
# if user.admin:
|
||||
|
||||
buttons.append(
|
||||
{
|
||||
"type": "button",
|
||||
"text": {"type": "plain_text", "text": "Assigned Tickets", "emoji": True},
|
||||
"action_id": "assigned-tickets",
|
||||
**({"style": "primary"} if current != "assigned-tickets" else {}),
|
||||
}
|
||||
)
|
||||
|
||||
buttons.append(
|
||||
{
|
||||
"type": "button",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue