Example #1
0
        public static IList <ISendMessage> GetFinishInputMessage(MessagingChatSettings settings, LocationLog locationLog)
        {
            string createBodyMessage()
            {
                if (string.IsNullOrEmpty(locationLog.Comment) && string.IsNullOrEmpty(locationLog.AudioCommentUrl))
                {
                    return($@"「{settings.YourName}は今{ (string.IsNullOrEmpty(locationLog.Name) ? locationLog.Address : locationLog.Name)}にいます。」");
                }

                return($@"🔊「{settings.YourName}は今{ (string.IsNullOrEmpty(locationLog.Name) ? locationLog.Address : locationLog.Name)}にいます。
また、{settings.YourName}からメッセージをもらっています。『{(string.IsNullOrEmpty(locationLog.Comment) ? "(送った音声メッセージが流れます)" : locationLog.Comment)}』」");
            }

            var message = $@"登録が完了しました。
Clova に話しかけたら以下のように答えます。

{createBodyMessage()}

情報の更新は下のリッチメニューからどうぞ 💁";

            return(new List <ISendMessage>
            {
                new TextMessage(message),
            });
        }
Example #2
0
        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));
            }
        }
Example #3
0
        private static void AddHistory(MessagingChatSettings settings)
        {
            var histories = JsonConvert.DeserializeObject <List <DateTimeOffset> >(settings.HistoryJson ?? "[]");

            histories.Add(DateTimeOffset.UtcNow);
            while (histories.Count > 10)
            {
                histories.RemoveAt(0);
            }
            settings.HistoryJson = JsonConvert.SerializeObject(histories);
        }
Example #4
0
        private async Task RestoreStateAsync(string userId)
        {
            var r = await Task.WhenAll(
                StateStoreTable.ExecuteAsync(TableOperation.Retrieve <MessagingChatSettings>(nameof(MessagingChatSettings), userId)),
                StateStoreTable.ExecuteAsync(TableOperation.Retrieve <MessagingSessionData>(nameof(MessagingSessionData), userId)));

            if (r[0].HttpStatusCode != 200)
            {
                MessagingChatSettings = new MessagingChatSettings
                {
                    RowKey = userId,
                };
            }
            else
            {
                MessagingChatSettings = (MessagingChatSettings)r[0].Result;
            }

            if (r[1].HttpStatusCode != 200)
            {
                MessagingSessionData = new MessagingSessionData
                {
                    RowKey = userId,
                };
            }
            else
            {
                MessagingSessionData = (MessagingSessionData)r[1].Result;
                if (MessagingSessionData.Timestamp <= DateTimeOffset.UtcNow - TimeSpan.FromMinutes(15))
                {
                    MessagingSessionData = new MessagingSessionData
                    {
                        RowKey = userId,
                    };
                }
            }
        }
Example #5
0
 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)),
     });
 }