public async Task <string> FindLocale(IActivity activity, CancellationToken token) { if (string.IsNullOrEmpty(this.locale)) { var resumptionData = await this.resumptionContext.LoadDataAsync(token); if (resumptionData != null && resumptionData.IsTrustedServiceUrl) { MicrosoftAppCredentials.TrustServiceUrl(this.conversationReference.ServiceUrl); } this.locale = (activity as IMessageActivity)?.Locale; // if locale is null or whitespace in the incoming request, // try to set it from the ResumptionContext if (string.IsNullOrWhiteSpace(this.locale)) { this.locale = resumptionData?.Locale; } // persist resumptionData with updated information var data = new ResumptionData { Locale = this.locale, IsTrustedServiceUrl = MicrosoftAppCredentials.IsTrustedServiceUrl(this.conversationReference.ServiceUrl) }; await this.resumptionContext.SaveDataAsync(data, token); } return(this.locale); }
/// <summary> /// Save the <paramref name="data"/> in <see cref="botDataBag"/>. /// </summary> /// <param name="data"> The <see cref="ResumptionData"/>.</param> /// <param name="token"> The cancellation token.</param> public async Task SaveDataAsync(ResumptionData data, CancellationToken token) { var clonedData = new ResumptionData { Locale = data.Locale, IsTrustedServiceUrl = data.IsTrustedServiceUrl }; botDataBag.Value.SetValue(ResumptionContext.RESUMPTION_CONTEXT_KEY, clonedData); }