protected override async Task OnEventActivityAsync(ITurnContext <IEventActivity> turnContext, CancellationToken cancellationToken) { var ev = turnContext.Activity.AsEventActivity(); var value = ev.Value?.ToString(); switch (ev.Name) { case Events.TimezoneEvent: { var state = await _stateAccessor.GetAsync(turnContext, () => new EmailSkillState()); state.UserInfo.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(value); break; } case Events.LocationEvent: { var state = await _stateAccessor.GetAsync(turnContext, () => new EmailSkillState()); var azureMapsClient = new AzureMapsClient(_settings); state.UserInfo.TimeZone = await azureMapsClient.GetTimeZoneInfoByCoordinates(value); break; } default: { await _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken); break; } } }
private async Task PopulateStateFromActivity(ITurnContext context) { var activity = context.Activity; var semanticAction = activity.SemanticAction; if (semanticAction != null && semanticAction.Entities.ContainsKey(StateProperties.TimeZone)) { var timezone = semanticAction.Entities[StateProperties.TimeZone]; var timezoneObj = timezone.Properties[StateProperties.TimeZone].ToObject <TimeZoneInfo>(); var state = await _stateAccessor.GetAsync(context, () => new EmailSkillState()); state.UserInfo.TimeZone = timezoneObj; } if (semanticAction != null && semanticAction.Entities.ContainsKey(StateProperties.Location)) { var location = semanticAction.Entities[StateProperties.Location]; var locationString = location.Properties[StateProperties.Location].ToString(); var state = await _stateAccessor.GetAsync(context, () => new EmailSkillState()); var azureMapsClient = new AzureMapsClient(_settings); var timezone = await azureMapsClient.GetTimeZoneInfoByCoordinates(locationString); state.UserInfo.TimeZone = timezone; } }
// Runs when a new event activity comes in. protected override async Task OnEventActivityAsync(DialogContext innerDc, CancellationToken cancellationToken = default) { var ev = innerDc.Context.Activity.AsEventActivity(); var value = ev.Value?.ToString(); switch (ev.Name) { case TokenEvents.TokenResponseEventName: { // Forward the token response activity to the dialog waiting on the stack. await innerDc.ContinueDialogAsync(); break; } case Events.TimezoneEvent: { var state = await _stateAccessor.GetAsync(innerDc.Context, () => new EmailSkillState()); state.UserInfo.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(value); break; } case Events.LocationEvent: { var state = await _stateAccessor.GetAsync(innerDc.Context, () => new EmailSkillState()); var azureMapsClient = new AzureMapsClient(_settings); state.UserInfo.TimeZone = await azureMapsClient.GetTimeZoneInfoByCoordinates(value); break; } default: { await innerDc.Context.SendActivityAsync(new Activity(type : ActivityTypes.Trace, text : $"Unknown Event '{ev.Name ?? "undefined"}' was received but not processed.")); break; } } }
private async Task PopulateStateFromSemanticAction(ITurnContext context) { var activity = context.Activity; var semanticAction = activity.SemanticAction; if (semanticAction != null && semanticAction.Entities.ContainsKey("timezone")) { var timezone = semanticAction.Entities["timezone"]; var timezoneObj = timezone.Properties["timezone"].ToObject <TimeZoneInfo>(); var state = await _stateAccessor.GetAsync(context, () => new CalendarSkillState()); // we have a timezone state.UserInfo.Timezone = timezoneObj; } if (semanticAction != null && semanticAction.Entities.ContainsKey("location")) { var location = semanticAction.Entities["location"]; var locationString = location.Properties["location"].ToString(); var state = await _stateAccessor.GetAsync(context, () => new CalendarSkillState()); var coords = locationString.Split(','); if (coords.Length == 2) { if (double.TryParse(coords[0], out var lat) && double.TryParse(coords[1], out var lng)) { state.UserInfo.Latitude = lat; state.UserInfo.Longitude = lng; } } var azureMapsClient = new AzureMapsClient(_settings); var timezone = await azureMapsClient.GetTimeZoneInfoByCoordinates(locationString); state.UserInfo.Timezone = timezone; } }