Update zulip message

This commit is contained in:
2024-09-06 16:09:44 +02:00
parent db714f6390
commit 6d976044d0
8 changed files with 166 additions and 15 deletions

View File

@@ -16,6 +16,11 @@ from reflector.db.transcripts import (
from reflector.processors.types import Transcript as ProcessorTranscript
from reflector.processors.types import Word
from reflector.settings import settings
from reflector.zulip import (
get_zulip_message,
send_message_to_zulip,
update_zulip_message,
)
router = APIRouter()
@@ -323,3 +328,28 @@ async def transcript_get_topics_with_words_per_speaker(
# convert to GetTranscriptTopicWithWordsPerSpeaker
return GetTranscriptTopicWithWordsPerSpeaker.from_transcript_topic(topic)
@router.post("/transcripts/{transcript_id}/zulip")
async def transcript_post_to_zulip(
transcript_id: str,
stream: str,
topic: str,
include_topics: bool,
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
):
user_id = user["sub"] if user else None
transcript = await transcripts_controller.get_by_id_for_http(
transcript_id, user_id=user_id
)
if not transcript:
raise HTTPException(status_code=404, detail="Transcript not found")
content = get_zulip_message(transcript, include_topics)
if transcript.zulip_message_id:
update_zulip_message(transcript.zulip_message_id, stream, topic, content)
else:
response = send_message_to_zulip(stream, topic, content)
await transcripts_controller.update(
transcript, {"zulip_message_id": response["id"]}
)