fix: 문의 폼 제출과 텔레그램 추적 로그 개선
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using TaxBaik.Application.Services;
|
||||
|
||||
namespace TaxBaik.Web.Services;
|
||||
@@ -60,13 +61,14 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
||||
try
|
||||
{
|
||||
var response = await client.PostAsJsonAsync(url, payload, ct);
|
||||
var responseBody = await response.Content.ReadAsStringAsync(ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogWarning("텔레그램 알림 전송 실패: {StatusCode}", response.StatusCode);
|
||||
_logger.LogWarning("텔레그램 알림 전송 실패: {StatusCode} {ResponseBody}", response.StatusCode, Truncate(responseBody));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("텔레그램 새 문의 알림 전송 성공: #{InquiryId}", inquiryId);
|
||||
_logger.LogInformation("텔레그램 새 문의 알림 전송 성공: #{InquiryId}, message_id={MessageId}", inquiryId, TryGetMessageId(responseBody));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -111,13 +113,14 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
||||
try
|
||||
{
|
||||
var response = await client.PostAsJsonAsync(url, payload, ct);
|
||||
var responseBody = await response.Content.ReadAsStringAsync(ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogWarning("텔레그램 상태 변경 알림 실패: {StatusCode}", response.StatusCode);
|
||||
_logger.LogWarning("텔레그램 상태 변경 알림 실패: {StatusCode} {ResponseBody}", response.StatusCode, Truncate(responseBody));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("텔레그램 상태 변경 알림 전송 성공: #{InquiryId}", inquiryId);
|
||||
_logger.LogInformation("텔레그램 상태 변경 알림 전송 성공: #{InquiryId}, message_id={MessageId}", inquiryId, TryGetMessageId(responseBody));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -133,4 +136,26 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
||||
"completed" => "완료",
|
||||
_ => 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