fix: 문의 폼 제출과 텔레그램 추적 로그 개선
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger mb-3"></div>
|
<div asp-validation-summary="ModelOnly" class="text-danger mb-3"></div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using TaxBaik.Application.Services;
|
using TaxBaik.Application.Services;
|
||||||
|
|
||||||
namespace TaxBaik.Web.Services;
|
namespace TaxBaik.Web.Services;
|
||||||
@@ -60,13 +61,14 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await client.PostAsJsonAsync(url, payload, ct);
|
var response = await client.PostAsJsonAsync(url, payload, ct);
|
||||||
|
var responseBody = await response.Content.ReadAsStringAsync(ct);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("텔레그램 알림 전송 실패: {StatusCode}", response.StatusCode);
|
_logger.LogWarning("텔레그램 알림 전송 실패: {StatusCode} {ResponseBody}", response.StatusCode, Truncate(responseBody));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogInformation("텔레그램 새 문의 알림 전송 성공: #{InquiryId}", inquiryId);
|
_logger.LogInformation("텔레그램 새 문의 알림 전송 성공: #{InquiryId}, message_id={MessageId}", inquiryId, TryGetMessageId(responseBody));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -111,13 +113,14 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await client.PostAsJsonAsync(url, payload, ct);
|
var response = await client.PostAsJsonAsync(url, payload, ct);
|
||||||
|
var responseBody = await response.Content.ReadAsStringAsync(ct);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("텔레그램 상태 변경 알림 실패: {StatusCode}", response.StatusCode);
|
_logger.LogWarning("텔레그램 상태 변경 알림 실패: {StatusCode} {ResponseBody}", response.StatusCode, Truncate(responseBody));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogInformation("텔레그램 상태 변경 알림 전송 성공: #{InquiryId}", inquiryId);
|
_logger.LogInformation("텔레그램 상태 변경 알림 전송 성공: #{InquiryId}, message_id={MessageId}", inquiryId, TryGetMessageId(responseBody));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -133,4 +136,26 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
|||||||
"completed" => "완료",
|
"completed" => "완료",
|
||||||
_ => status
|
_ => status
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static string TryGetMessageId(string responseBody)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var document = JsonDocument.Parse(responseBody);
|
||||||
|
if (document.RootElement.TryGetProperty("result", out var result)
|
||||||
|
&& result.TryGetProperty("message_id", out var messageId))
|
||||||
|
{
|
||||||
|
return messageId.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JsonException)
|
||||||
|
{
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Truncate(string value)
|
||||||
|
=> value.Length <= 500 ? value : value[..500] + "...";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user