private async Task <Response> GetText(Request request, string startText, string textKey = null) { var response = new Response(); if (string.IsNullOrEmpty(textKey)) { _cache.TryGet($"Texts-{request.Source}", out string[] texts); if (texts?.Any() != true && !_cache.TryGet("Texts", out texts)) { response.Text = "Что-то у меня не нашлось никаких текстов..."; return(response); } textKey = GetTextKey(request, texts); } var eventName = $"event:{textKey}"; var dialog = await _dialogflowService.GetResponseAsync(eventName, request.SessionId, textKey); var textName = dialog?.GetParameters("text-name")?.FirstOrDefault(); var text = $"{startText} {textName} {dialog?.Response}"; response.Text = text; response.Buttons = dialog?.Buttons; response.ScopeKey = dialog?.ScopeKey; return(response); }
private Image GetImage(int year, int monthNumber, string imageTitleFormat, string description) { if (!_cache.TryGet($"Calendar:{year}:images:{monthNumber}", out string imageId)) { return(null); } var image = new Image { ImageId = imageId, Title = new DateTime(year, monthNumber, 1).ToString(imageTitleFormat ?? "MMMM"), Description = description }; return(image); }
protected override Models.Request Before(Request input) { var request = base.Before(input); var userStateCacheKey = GetCacheKey(request.UserHash); _cache.TryGet(userStateCacheKey, out Models.UserState userState); request.IsOldUser = userState?.IsOldUser ?? false; request.NextTextIndex = Convert.ToInt32(userState?.NextTextIndex ?? 0); var contexts = GetContexts(input); request.RequiredContexts.AddRange(contexts); request.SessionId = TryGetSessionIdAsync(request.NewSession, request.UserHash); return(request); }
public bool TryGet(string invocationKey, out string scopeKey) { var cacheKey = GetCacheKey(invocationKey); return(_cache.TryGet(cacheKey, out scopeKey)); }