Skip to main content

insert_page_context_message_if_changed

Function insert_page_context_message_if_changed 

Source
pub async fn insert_page_context_message_if_changed(
    conn: &mut PgConnection,
    conversation_id: Uuid,
    page: &PageChatbotContext,
    course_name: Option<&str>,
) -> ChatbotResult<()>
Expand description

Records what the learner is looking at as a developer message in the conversation, so that it survives a history rebuild instead of being prepended in memory on every request.

Writes nothing when the conversation’s newest page context already says the same thing. course_name is the name of the course the chatbot belongs to.

Must be called inside the transaction that took the conversation lock: whether this context repeats the newest one is decided from the conversation, so two requests reading it before either writes would both conclude it changed and both write.