botbuilder-dotnet/libraries/Microsoft.Bot.Builder/ConversationState.cs

46 строки
2.0 KiB
C#
Исходник Обычный вид История

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace Microsoft.Bot.Builder
{
/// <summary>
/// Defines a state management object for conversation state.
/// </summary>
/// <remarks>
/// Conversation state is available in any turn in a specific conversation, regardless of user,
/// such as in a group conversation.
/// </remarks>
2018-07-17 06:09:35 +03:00
public class ConversationState : BotState
{
/// <summary>
2018-07-18 04:11:13 +03:00
/// Initializes a new instance of the <see cref="ConversationState"/> class.
/// </summary>
/// <param name="storage">The storage layer to use.</param>
2018-07-17 06:09:35 +03:00
public ConversationState(IStorage storage)
2018-07-23 22:18:27 +03:00
: base(storage, nameof(ConversationState))
{
}
2018-07-23 22:18:27 +03:00
/// <summary>
/// Gets the key to use when reading and writing state to and from storage.
/// </summary>
2018-08-23 04:43:11 +03:00
/// <param name="turnContext">The context object for this turn.</param>
/// <returns>The storage key.</returns>
/// <remarks>
/// Conversation state includes the channel ID and conversation ID as part of its storage key.
/// </remarks>
/// <exception cref="ArgumentNullException">The <see cref="ITurnContext.Activity"/> for the
/// current turn is missing <see cref="Schema.Activity.ChannelId"/> or
/// <see cref="Schema.Activity.Conversation"/> information, or the conversation's
/// <see cref="Schema.ConversationAccount.Id"/> is missing.</exception>
protected override string GetStorageKey(ITurnContext turnContext)
{
var channelId = turnContext.Activity.ChannelId ?? throw new InvalidOperationException("invalid activity-missing channelId");
var conversationId = turnContext.Activity.Conversation?.Id ?? throw new InvalidOperationException("invalid activity-missing Conversation.Id");
return $"{channelId}/conversations/{conversationId}";
}
}
}