public async Task PostMessageAsync()

in src/WebJobs.Extensions.OpenAI/Assistants/AssistantService.cs [179:209]


    public async Task<AssistantState> PostMessageAsync(AssistantPostAttribute attribute, CancellationToken cancellationToken)
    {
        // Validate inputs and prepare for processing
        DateTime timeFilter = DateTime.UtcNow;
        this.ValidateAttributes(attribute);

        this.logger.LogInformation("Posting message to assistant entity '{Id}'", attribute.Id);
        TableClient tableClient = this.GetOrCreateTableClient(attribute.ChatStorageConnectionSetting, attribute.CollectionName);

        // Load and validate chat state
        InternalChatState? chatState = await this.LoadChatStateAsync(attribute.Id, tableClient, cancellationToken);
        if (chatState is null || !chatState.Metadata.Exists)
        {
            return this.CreateNonExistentAssistantState(attribute.Id);
        }

        this.logger.LogInformation("[{Id}] Received message: {Text}", attribute.Id, attribute.UserMessage);

        // Process the conversation
        List<TableTransactionAction> batch = new();
        this.AddUserMessageToChat(attribute, chatState, batch);

        await this.ProcessConversationWithLLM(attribute, chatState, batch, cancellationToken);

        // Update state and persist changes
        this.UpdateAssistantState(chatState, batch);
        await tableClient.SubmitTransactionAsync(batch, cancellationToken);

        // Return results
        return this.CreateAssistantStateResponse(attribute.Id, chatState, timeFilter);
    }