private static async Task <IActionResult> ExecuteLaunchRequestAsync(CEKRequest request, CloudTable locationLogs, AppConfiguration config) { var response = new CEKResponse(); var taskForSettings = MessagingChatSettings.GetSettingsByUserIdAsync(locationLogs, request.Session.User.UserId); var taskForLocationLog = LocationLog.GetLocationLogByUserIdAsync(locationLogs, request.Session.User.UserId); await Task.WhenAll(taskForSettings, taskForLocationLog); var settings = taskForSettings.Result ?? new MessagingChatSettings { RowKey = request.Session.User.UserId }; var locationLog = taskForLocationLog.Result; try { if (!settings.IsLineFrend) { response.AddText(ClovaMessages.GetAddingLineFrendMessage()); return(new OkObjectResult(response)); } AddHistory(settings); response.AddText(ClovaMessages.GetGuideMessage(settings.YourName)); if (locationLog == null || !DateTimeOffsetUtils.IsToday(locationLog.Timestamp)) { // データが無い response.AddText(ClovaMessages.GetNoLogMessage(settings.YourName)); await AskCurrentLocationAsync(request, config, settings); return(new OkObjectResult(response)); } if (DateTimeOffsetUtils.IsBefore(locationLog.Timestamp, TimeSpan.Parse(config.Cek.IsBeforeThreshold ?? Clova.IsBeforeThresholdDefaultValue))) { // 古いデータ response.AddText(ClovaMessages.GetOldLocationMessage(settings.YourName, locationLog)); await AskCurrentLocationAsync(request, config, settings); return(new OkObjectResult(response)); } // データがある response.AddText(ClovaMessages.GetLocationMessage(settings.YourName, locationLog)); if (!string.IsNullOrEmpty(locationLog.Comment)) { response.AddText(ClovaMessages.GetCommentMessage(settings.YourName, locationLog)); } else if (!string.IsNullOrEmpty(locationLog.AudioCommentUrl)) { response.AddText(ClovaMessages.GetVoiceMessagePrefixMessage(settings.YourName)); response.AddUrl(locationLog.AudioCommentUrl); } return(new OkObjectResult(response)); } finally { await locationLogs.ExecuteAsync(TableOperation.InsertOrReplace(settings)); } }
private static async Task AskCurrentLocationAsync(CEKRequest request, AppConfiguration config, MessagingChatSettings settings) { await LineMessagingClientFactory.GetLineMessagingClient(config.MessagingApi.AccessToken).PushMessageAsync( request.Session.User.UserId, new List <ISendMessage> { new TextMessage(ClovaMessages.GetAskLocationMessage(settings.YourName)), }); }