private async Task <InvokeResponse> ProcessActivityAsync(string authHeader, Activity activity, BotCallbackHandler callback, CancellationToken cancellationToken) { MoMoBotAssert.NotNull(activity); using (var context = new TurnContext(activity)) { //context.TurnState.Add<IIdentity>(BotIdentityKey, identity); await callback?.Invoke(context, cancellationToken); if (activity.Type == ActivityTypes.Invoke) { var activityInvokeResponse = context.TurnState.Get <Activity>(InvokeReponseKey); if (activityInvokeResponse == null) { return(new InvokeResponse { Status = (int)HttpStatusCode.NotImplemented }); } else { return((InvokeResponse)activityInvokeResponse.Value); } } return(null); } }
public BotState(IStorage storage, string contextServiceKey) { MoMoBotAssert.NotNull(storage); MoMoBotAssert.NotNull(contextServiceKey); _storage = storage; _contextServiceKey = contextServiceKey; }
public Task DeleteAsync(string[] keys, CancellationToken cancellationToken = default) { MoMoBotAssert.NotNull(keys); lock (_synclock) { foreach (var key in keys) { _memory.Remove(key); } } return(Task.CompletedTask); }
public async Task <DialogContext> CreateContextAsync(TurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { MoMoBotAssert.NotNull(turnContext); // ToDo: Component Dialog doesn't call this code path. This needs to be cleaned up in 4.1. if (_dialogState == null) { // Note: This shouldn't ever trigger, as the _dialogState is set in the constructor and validated there. throw new InvalidOperationException($"DialogSet.CreateContextAsync(): DialogSet created with a null IStatePropertyAccessor."); } // Load/initialize dialog state var state = await _dialogState.GetAsync(turnContext, () => { return(new DialogState()); }, cancellationToken).ConfigureAwait(false); // Create and return context return(new DialogContext(this, turnContext, state)); }
public Task <IDictionary <string, object> > ReadAsync(string[] keys, CancellationToken cancellationToken = default) { MoMoBotAssert.NotNull(keys); var storeItems = new Dictionary <string, object>(keys.Length); lock (_synclock) { foreach (var key in keys) { if (_memory.TryGetValue(key, out var state)) { if (state != null) { storeItems.Add(key, state.ToObject <object>(StateJsonSerializer)); } } } } return(Task.FromResult <IDictionary <string, object> >(storeItems)); }
public void Add(BotState botState) { MoMoBotAssert.NotNull(botState); BotStates.Add(botState); }