**Fixes Applied:** 1. **Order Deletion Authorization (HTTP 401)** - Added [AllowAnonymous] to CancelOrder endpoint - Allows customers to cancel orders using IdentityReference - File: LittleShop/Controllers/OrdersController.cs:160 2. **Bot Activity Tracking Hostname** - Changed littleshop-admin:8080 → littleshop:5000 - Fixed DNS resolution errors in production - Files: TeleBot/appsettings.json, BotActivityTracker.cs, docker-compose.hostinger.yml 3. **Tor Proxy Investigation** - Analyzed SOCKS connection failures - Tor is working correctly, API blocks exit nodes (expected) - Fallback to default currencies working as designed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Telegram.Bot.Types;
|
|
using LittleShop.Client.Models;
|
|
|
|
namespace TeleBot.Services
|
|
{
|
|
public interface IBotActivityTracker
|
|
{
|
|
Task TrackActivityAsync(
|
|
Chat chat,
|
|
string activityType,
|
|
string description,
|
|
Product? product = null,
|
|
decimal? value = null,
|
|
int? quantity = null);
|
|
}
|
|
|
|
public class BotActivityTracker : IBotActivityTracker
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ILogger<BotActivityTracker> _logger;
|
|
private readonly string _littleShopUrl;
|
|
|
|
public BotActivityTracker(
|
|
HttpClient httpClient,
|
|
IConfiguration configuration,
|
|
ILogger<BotActivityTracker> logger)
|
|
{
|
|
_httpClient = httpClient;
|
|
_configuration = configuration;
|
|
_logger = logger;
|
|
_littleShopUrl = configuration["LittleShop:BaseUrl"] ?? "http://littleshop:5000";
|
|
}
|
|
|
|
public async Task TrackActivityAsync(
|
|
Chat chat,
|
|
string activityType,
|
|
string description,
|
|
Product? product = null,
|
|
decimal? value = null,
|
|
int? quantity = null)
|
|
{
|
|
try
|
|
{
|
|
var activity = new
|
|
{
|
|
SessionIdentifier = $"telegram_{chat.Id}",
|
|
UserDisplayName = chat.Username ?? $"{chat.FirstName} {chat.LastName}".Trim(),
|
|
ActivityType = activityType,
|
|
ActivityDescription = description,
|
|
ProductId = product?.Id,
|
|
ProductName = product?.Name,
|
|
CategoryName = product?.CategoryName,
|
|
Value = value,
|
|
Quantity = quantity,
|
|
Platform = "Telegram",
|
|
Location = "Unknown",
|
|
Timestamp = DateTime.UtcNow
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(activity);
|
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var response = await _httpClient.PostAsync(
|
|
$"{_littleShopUrl}/api/bot/activity",
|
|
content);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
_logger.LogWarning("Failed to track activity: {StatusCode}", response.StatusCode);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Don't let tracking errors break the main flow
|
|
_logger.LogError(ex, "Error tracking bot activity");
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ActivityTypes
|
|
{
|
|
public const string Browse = "Browse";
|
|
public const string ViewProduct = "ViewProduct";
|
|
public const string AddToCart = "AddToCart";
|
|
public const string RemoveFromCart = "RemoveFromCart";
|
|
public const string ViewCart = "ViewCart";
|
|
public const string Checkout = "Checkout";
|
|
public const string SelectVariant = "SelectVariant";
|
|
public const string ViewOrders = "ViewOrders";
|
|
public const string Search = "Search";
|
|
public const string Help = "Help";
|
|
public const string Start = "Start";
|
|
}
|
|
} |