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 async Task InputCommentAsync(ContextState contextState, MessageEvent ev) { if (ev.Message.Type == EventMessageType.Text) { var locationLog = await LocationLog.GetLocationLogByUserIdAsync(contextState.StateStoreTable, ev.Source.UserId); if (locationLog == null) { await ReplyUnknownMessageAsync(contextState, ev); return; } locationLog.Comment = ((TextEventMessage)ev.Message).Text; await LocationLog.InsertOrReplaceAsync(contextState.StateStoreTable, locationLog); await FinishInputAsync(contextState, ev, locationLog); SetNextCallMethod(nameof(InitializeAsync)); } else if (ev.Message.Type == EventMessageType.Audio) { var locationLog = await LocationLog.GetLocationLogByUserIdAsync(contextState.StateStoreTable, ev.Source.UserId); if (locationLog == null) { await ReplyUnknownMessageAsync(contextState, ev); return; } using (var audio = await contextState.Client.GetContentStreamAsync(ev.Message.Id)) { var blob = await contextState.Binder.BindAsync <CloudBlockBlob>(new BlobAttribute($"files/{ev.Source.UserId}/{ev.Message.Id}{GetFileExtension(audio.ContentHeaders.ContentType.MediaType)}", FileAccess.Write)); await blob.UploadFromStreamAsync(audio); locationLog.AudioCommentUrl = blob.Uri.ToString(); } await LocationLog.InsertOrReplaceAsync(contextState.StateStoreTable, locationLog); await FinishInputAsync(contextState, ev, locationLog); SetNextCallMethod(nameof(InitializeAsync)); } else { await ReplyUnknownMessageAsync(contextState, ev); } }
private async Task FinishInputAsync(ContextState contextState, MessageEvent ev, LocationLog locationLog = null) { locationLog = locationLog ?? await LocationLog.GetLocationLogByUserIdAsync(contextState.StateStoreTable, ev.Source.UserId); if (locationLog == null) { await ReplyUnknownMessageAsync(contextState, ev); return; } await contextState.Client.ReplyMessageAsync(ev.ReplyToken, LineMessages.GetFinishInputMessage(contextState.Settings, locationLog)); SetNextCallMethod(nameof(InitializeAsync)); }