2018-06-23 01:07:06 +03:00
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
2018-09-11 19:21:03 +03:00
|
|
|
|
using System;
|
|
|
|
|
|
2018-06-23 01:07:06 +03:00
|
|
|
|
namespace Microsoft.Bot.Builder
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-08-15 21:50:39 +03:00
|
|
|
|
/// Defines a state management object for conversation state.
|
2018-06-23 01:07:06 +03:00
|
|
|
|
/// </summary>
|
2019-08-15 21:50:39 +03:00
|
|
|
|
/// <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
|
2018-06-23 01:07:06 +03:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-07-18 04:11:13 +03:00
|
|
|
|
/// Initializes a new instance of the <see cref="ConversationState"/> class.
|
2018-06-23 01:07:06 +03:00
|
|
|
|
/// </summary>
|
2019-08-15 21:50:39 +03:00
|
|
|
|
/// <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-06-23 01:07:06 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-07-23 22:18:27 +03:00
|
|
|
|
|
2018-08-18 03:28:34 +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>
|
2018-08-18 03:28:34 +03:00
|
|
|
|
/// <returns>The storage key.</returns>
|
2019-08-15 21:50:39 +03:00
|
|
|
|
/// <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>
|
2018-09-11 19:21:03 +03:00
|
|
|
|
protected override string GetStorageKey(ITurnContext turnContext)
|
|
|
|
|
{
|
2020-06-25 06:02:33 +03:00
|
|
|
|
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");
|
2018-09-11 19:21:03 +03:00
|
|
|
|
return $"{channelId}/conversations/{conversationId}";
|
|
|
|
|
}
|
2018-06-23 01:07:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|