Add customer communication system
This commit is contained in:
109
LittleShop/Areas/Admin/Views/Bots/Create.cshtml
Normal file
109
LittleShop/Areas/Admin/Views/Bots/Create.cshtml
Normal file
@@ -0,0 +1,109 @@
|
||||
@model LittleShop.DTOs.BotRegistrationDto
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Register New Bot";
|
||||
}
|
||||
|
||||
<h1>Register New Bot</h1>
|
||||
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<form action="/Admin/Bots/Create" method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
@if (ViewData.ModelState.IsValid == false)
|
||||
{
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach (var error in ViewData.ModelState.Values.SelectMany(v => v.Errors))
|
||||
{
|
||||
<li>@error.ErrorMessage</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="Name" class="form-label">Bot Name</label>
|
||||
<input name="Name" id="Name" class="form-control" placeholder="e.g., Customer Service Bot" required />
|
||||
<span class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="Description" class="form-label">Description</label>
|
||||
<textarea name="Description" id="Description" class="form-control" rows="3"
|
||||
placeholder="Brief description of what this bot does"></textarea>
|
||||
<span class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="Type" class="form-label">Bot Type</label>
|
||||
<select name="Type" id="Type" class="form-select">
|
||||
<option value="0">Telegram</option>
|
||||
<option value="1">Discord</option>
|
||||
<option value="2">WhatsApp</option>
|
||||
<option value="3">Signal</option>
|
||||
<option value="4">Matrix</option>
|
||||
<option value="5">IRC</option>
|
||||
<option value="99">Custom</option>
|
||||
</select>
|
||||
<span class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="Version" class="form-label">Bot Version</label>
|
||||
<input name="Version" id="Version" class="form-control" placeholder="e.g., 1.0.0" />
|
||||
<span class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Initial Settings (Optional)</label>
|
||||
<div class="alert alert-info">
|
||||
<small>You can configure detailed settings after registration.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary">Register Bot</button>
|
||||
<a href="/Admin/Bots" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Registration Information</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p>After registering your bot, you will receive:</p>
|
||||
<ul>
|
||||
<li><strong>Bot ID:</strong> Unique identifier for your bot</li>
|
||||
<li><strong>API Key:</strong> Secret key for authentication (save this securely!)</li>
|
||||
<li><strong>Configuration:</strong> Access to manage bot settings</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
|
||||
<h6>Bot Types:</h6>
|
||||
<ul class="small">
|
||||
<li><strong>Telegram:</strong> Telegram messenger bot</li>
|
||||
<li><strong>Discord:</strong> Discord server bot</li>
|
||||
<li><strong>WhatsApp:</strong> WhatsApp Business API</li>
|
||||
<li><strong>Signal:</strong> Signal messenger bot</li>
|
||||
<li><strong>Matrix:</strong> Matrix protocol bot</li>
|
||||
<li><strong>IRC:</strong> Internet Relay Chat bot</li>
|
||||
<li><strong>Custom:</strong> Custom implementation</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.12/jquery.validate.unobtrusive.min.js"></script>
|
||||
}
|
||||
295
LittleShop/Areas/Admin/Views/Bots/Details.cshtml
Normal file
295
LittleShop/Areas/Admin/Views/Bots/Details.cshtml
Normal file
@@ -0,0 +1,295 @@
|
||||
@model LittleShop.DTOs.BotDto
|
||||
@{
|
||||
ViewData["Title"] = $"Bot Details - {Model.Name}";
|
||||
var metricsSummary = ViewData["MetricsSummary"] as LittleShop.DTOs.BotMetricsSummaryDto;
|
||||
var activeSessions = ViewData["ActiveSessions"] as IEnumerable<LittleShop.DTOs.BotSessionDto>;
|
||||
}
|
||||
|
||||
<h1>Bot Details</h1>
|
||||
|
||||
@if (TempData["Success"] != null)
|
||||
{
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
@TempData["Success"]
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (TempData["BotKey"] != null)
|
||||
{
|
||||
<div class="alert alert-warning">
|
||||
<strong>Important!</strong> Save this API key securely. It will not be shown again:
|
||||
<div class="mt-2">
|
||||
<code class="bg-dark text-white p-2 d-block">@TempData["BotKey"]</code>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Bot Information</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">Name</dt>
|
||||
<dd class="col-sm-9">@Model.Name</dd>
|
||||
|
||||
<dt class="col-sm-3">Description</dt>
|
||||
<dd class="col-sm-9">@(string.IsNullOrEmpty(Model.Description) ? "N/A" : Model.Description)</dd>
|
||||
|
||||
<dt class="col-sm-3">Type</dt>
|
||||
<dd class="col-sm-9"><span class="badge bg-info">@Model.Type</span></dd>
|
||||
|
||||
<dt class="col-sm-3">Platform Info</dt>
|
||||
<dd class="col-sm-9">
|
||||
@if (!string.IsNullOrEmpty(Model.PlatformUsername))
|
||||
{
|
||||
<div>
|
||||
<strong>@@@Model.PlatformUsername</strong>
|
||||
@if (!string.IsNullOrEmpty(Model.PlatformDisplayName))
|
||||
{
|
||||
<br />
|
||||
<span class="text-muted">@Model.PlatformDisplayName</span>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(Model.PlatformId))
|
||||
{
|
||||
<br />
|
||||
<small><code>ID: @Model.PlatformId</code></small>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">Not configured - platform info will be auto-detected on first connection</span>
|
||||
}
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-3">Status</dt>
|
||||
<dd class="col-sm-9">
|
||||
@switch (Model.Status)
|
||||
{
|
||||
case LittleShop.Enums.BotStatus.Active:
|
||||
<span class="badge bg-success">Active</span>
|
||||
break;
|
||||
case LittleShop.Enums.BotStatus.Inactive:
|
||||
<span class="badge bg-secondary">Inactive</span>
|
||||
break;
|
||||
case LittleShop.Enums.BotStatus.Suspended:
|
||||
<span class="badge bg-warning">Suspended</span>
|
||||
break;
|
||||
default:
|
||||
<span class="badge bg-dark">@Model.Status</span>
|
||||
break;
|
||||
}
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-3">Bot ID</dt>
|
||||
<dd class="col-sm-9"><code>@Model.Id</code></dd>
|
||||
|
||||
<dt class="col-sm-3">Version</dt>
|
||||
<dd class="col-sm-9">@(string.IsNullOrEmpty(Model.Version) ? "N/A" : Model.Version)</dd>
|
||||
|
||||
<dt class="col-sm-3">IP Address</dt>
|
||||
<dd class="col-sm-9">@(string.IsNullOrEmpty(Model.IpAddress) ? "N/A" : Model.IpAddress)</dd>
|
||||
|
||||
<dt class="col-sm-3">Created</dt>
|
||||
<dd class="col-sm-9">@Model.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss")</dd>
|
||||
|
||||
<dt class="col-sm-3">Last Seen</dt>
|
||||
<dd class="col-sm-9">
|
||||
@if (Model.LastSeenAt.HasValue)
|
||||
{
|
||||
@Model.LastSeenAt.Value.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
@if ((DateTime.UtcNow - Model.LastSeenAt.Value).TotalMinutes < 5)
|
||||
{
|
||||
<span class="badge bg-success ms-2">Online</span>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">Never</span>
|
||||
}
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-3">Config Synced</dt>
|
||||
<dd class="col-sm-9">
|
||||
@if (Model.LastConfigSyncAt.HasValue)
|
||||
{
|
||||
@Model.LastConfigSyncAt.Value.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">Never</span>
|
||||
}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">30-Day Metrics Summary</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (metricsSummary != null)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="text-center">
|
||||
<h3>@metricsSummary.TotalSessions</h3>
|
||||
<p class="text-muted">Total Sessions</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="text-center">
|
||||
<h3>@metricsSummary.TotalOrders</h3>
|
||||
<p class="text-muted">Total Orders</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="text-center">
|
||||
<h3>$@metricsSummary.TotalRevenue.ToString("F2")</h3>
|
||||
<p class="text-muted">Total Revenue</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="text-center">
|
||||
<h3>@metricsSummary.TotalErrors</h3>
|
||||
<p class="text-muted">Total Errors</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (metricsSummary.UptimePercentage > 0)
|
||||
{
|
||||
<div class="progress mt-3">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: @metricsSummary.UptimePercentage%"
|
||||
aria-valuenow="@metricsSummary.UptimePercentage" aria-valuemin="0" aria-valuemax="100">
|
||||
Uptime: @metricsSummary.UptimePercentage.ToString("F1")%
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-muted">No metrics available</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Active Sessions</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (activeSessions != null && activeSessions.Any())
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Session ID</th>
|
||||
<th>Platform</th>
|
||||
<th>Started</th>
|
||||
<th>Messages</th>
|
||||
<th>Orders</th>
|
||||
<th>Spent</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var session in activeSessions.Take(10))
|
||||
{
|
||||
<tr>
|
||||
<td><small>@session.Id.ToString().Substring(0, 8)...</small></td>
|
||||
<td>@session.Platform</td>
|
||||
<td>@session.StartedAt.ToString("HH:mm:ss")</td>
|
||||
<td>@session.MessageCount</td>
|
||||
<td>@session.OrderCount</td>
|
||||
<td>$@session.TotalSpent.ToString("F2")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-muted">No active sessions</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Actions</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="d-grid gap-2">
|
||||
<a href="/Admin/Bots/Edit/@Model.Id" class="btn btn-primary">
|
||||
<i class="bi bi-pencil"></i> Edit Settings
|
||||
</a>
|
||||
<a href="/Admin/Bots/Metrics/@Model.Id" class="btn btn-success">
|
||||
<i class="bi bi-graph-up"></i> View Detailed Metrics
|
||||
</a>
|
||||
|
||||
@if (Model.Status == LittleShop.Enums.BotStatus.Active)
|
||||
{
|
||||
<form action="/Admin/Bots/Suspend/@Model.Id" method="post">
|
||||
<button type="submit" class="btn btn-warning w-100"
|
||||
onclick="return confirm('Are you sure you want to suspend this bot?')">
|
||||
<i class="bi bi-pause-circle"></i> Suspend Bot
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
else if (Model.Status == LittleShop.Enums.BotStatus.Suspended)
|
||||
{
|
||||
<form action="/Admin/Bots/Activate/@Model.Id" method="post">
|
||||
<button type="submit" class="btn btn-success w-100">
|
||||
<i class="bi bi-play-circle"></i> Activate Bot
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
|
||||
<hr />
|
||||
|
||||
<form action="/Admin/Bots/Delete/@Model.Id" method="post">
|
||||
<button type="submit" class="btn btn-danger w-100"
|
||||
onclick="return confirm('Are you sure you want to delete this bot? This action cannot be undone.')">
|
||||
<i class="bi bi-trash"></i> Delete Bot
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Quick Stats</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled mb-0">
|
||||
<li>
|
||||
<strong>Total Sessions:</strong> @Model.TotalSessions
|
||||
</li>
|
||||
<li>
|
||||
<strong>Active Sessions:</strong> @Model.ActiveSessions
|
||||
</li>
|
||||
<li>
|
||||
<strong>Total Orders:</strong> @Model.TotalOrders
|
||||
</li>
|
||||
<li>
|
||||
<strong>Total Revenue:</strong> $@Model.TotalRevenue.ToString("F2")
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<a href="/Admin/Bots" class="btn btn-secondary">Back to List</a>
|
||||
</div>
|
||||
135
LittleShop/Areas/Admin/Views/Bots/Edit.cshtml
Normal file
135
LittleShop/Areas/Admin/Views/Bots/Edit.cshtml
Normal file
@@ -0,0 +1,135 @@
|
||||
@model LittleShop.DTOs.BotDto
|
||||
|
||||
@{
|
||||
ViewData["Title"] = $"Edit Bot - {Model.Name}";
|
||||
var settingsJson = ViewData["BotSettings"] as string ?? "{}";
|
||||
}
|
||||
|
||||
<h1>Edit Bot Settings</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
@if (TempData["Error"] != null)
|
||||
{
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
@TempData["Error"]
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<form asp-action="Edit" method="post">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Bot Information</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">Name</dt>
|
||||
<dd class="col-sm-9">@Model.Name</dd>
|
||||
|
||||
<dt class="col-sm-3">Type</dt>
|
||||
<dd class="col-sm-9">@Model.Type</dd>
|
||||
|
||||
<dt class="col-sm-3">Bot ID</dt>
|
||||
<dd class="col-sm-9"><code>@Model.Id</code></dd>
|
||||
</dl>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="status" class="form-label">Status</label>
|
||||
<select name="status" id="status" class="form-select">
|
||||
<option value="1" selected="@(Model.Status == LittleShop.Enums.BotStatus.Active)">Active</option>
|
||||
<option value="2" selected="@(Model.Status == LittleShop.Enums.BotStatus.Inactive)">Inactive</option>
|
||||
<option value="3" selected="@(Model.Status == LittleShop.Enums.BotStatus.Suspended)">Suspended</option>
|
||||
<option value="4" selected="@(Model.Status == LittleShop.Enums.BotStatus.Maintenance)">Maintenance</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Bot Configuration (JSON)</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label for="settingsJson" class="form-label">Settings</label>
|
||||
<textarea name="settingsJson" id="settingsJson" class="form-control font-monospace" rows="20">@settingsJson</textarea>
|
||||
<small class="text-muted">Edit the JSON configuration for this bot. Be careful to maintain valid JSON format.</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Configuration Template</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="small">Example configuration structure:</p>
|
||||
<pre class="bg-light p-2 small"><code>{
|
||||
"Telegram": {
|
||||
"BotToken": "YOUR_BOT_TOKEN",
|
||||
"WebhookUrl": "",
|
||||
"AdminChatId": ""
|
||||
},
|
||||
"Privacy": {
|
||||
"Mode": "strict",
|
||||
"RequirePGP": false,
|
||||
"EnableTor": false
|
||||
},
|
||||
"Features": {
|
||||
"EnableQRCodes": true,
|
||||
"EnableVoiceSearch": false
|
||||
},
|
||||
"Cryptocurrencies": [
|
||||
"BTC", "XMR", "USDT"
|
||||
]
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Actions</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<button type="submit" class="btn btn-primary w-100 mb-2">
|
||||
<i class="bi bi-save"></i> Save Changes
|
||||
</button>
|
||||
<a asp-action="Details" asp-route-id="@Model.Id" class="btn btn-secondary w-100">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
// Pretty print JSON on load
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var textarea = document.getElementById('settingsJson');
|
||||
try {
|
||||
var json = JSON.parse(textarea.value);
|
||||
textarea.value = JSON.stringify(json, null, 2);
|
||||
} catch (e) {
|
||||
console.error('Invalid JSON:', e);
|
||||
}
|
||||
});
|
||||
|
||||
// Validate JSON before submit
|
||||
document.querySelector('form').addEventListener('submit', function(e) {
|
||||
var textarea = document.getElementById('settingsJson');
|
||||
try {
|
||||
JSON.parse(textarea.value);
|
||||
} catch (error) {
|
||||
e.preventDefault();
|
||||
alert('Invalid JSON format: ' + error.message);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
150
LittleShop/Areas/Admin/Views/Bots/Index.cshtml
Normal file
150
LittleShop/Areas/Admin/Views/Bots/Index.cshtml
Normal file
@@ -0,0 +1,150 @@
|
||||
@model IEnumerable<LittleShop.DTOs.BotDto>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Bot Management";
|
||||
}
|
||||
|
||||
<h1>Bot Management</h1>
|
||||
|
||||
<p>
|
||||
<a href="/Admin/Bots/Wizard" class="btn btn-primary">
|
||||
<i class="fas fa-magic"></i> Create Telegram Bot (Wizard)
|
||||
</a>
|
||||
<a href="/Admin/Bots/Create" class="btn btn-outline-secondary">
|
||||
<i class="fas fa-plus"></i> Manual Registration
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@if (TempData["Success"] != null)
|
||||
{
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
@TempData["Success"]
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (TempData["Error"] != null)
|
||||
{
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
@TempData["Error"]
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Platform Info</th>
|
||||
<th>Status</th>
|
||||
<th>Active Sessions</th>
|
||||
<th>Total Revenue</th>
|
||||
<th>Last Seen</th>
|
||||
<th>Created</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var bot in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<strong>@bot.Name</strong>
|
||||
@if (!string.IsNullOrEmpty(bot.PersonalityName))
|
||||
{
|
||||
<span class="badge bg-secondary ms-2">@bot.PersonalityName</span>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(bot.Description))
|
||||
{
|
||||
<br />
|
||||
<small class="text-muted">@bot.Description</small>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-info">@bot.Type</span>
|
||||
</td>
|
||||
<td>
|
||||
@if (!string.IsNullOrEmpty(bot.PlatformUsername))
|
||||
{
|
||||
<div>
|
||||
<strong>@@@bot.PlatformUsername</strong>
|
||||
@if (!string.IsNullOrEmpty(bot.PlatformDisplayName))
|
||||
{
|
||||
<br />
|
||||
<small class="text-muted">@bot.PlatformDisplayName</small>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">Not configured</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@switch (bot.Status)
|
||||
{
|
||||
case LittleShop.Enums.BotStatus.Active:
|
||||
<span class="badge bg-success">Active</span>
|
||||
break;
|
||||
case LittleShop.Enums.BotStatus.Inactive:
|
||||
<span class="badge bg-secondary">Inactive</span>
|
||||
break;
|
||||
case LittleShop.Enums.BotStatus.Suspended:
|
||||
<span class="badge bg-warning">Suspended</span>
|
||||
break;
|
||||
case LittleShop.Enums.BotStatus.Maintenance:
|
||||
<span class="badge bg-info">Maintenance</span>
|
||||
break;
|
||||
default:
|
||||
<span class="badge bg-dark">@bot.Status</span>
|
||||
break;
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-primary">@bot.ActiveSessions</span>
|
||||
</td>
|
||||
<td>$@bot.TotalRevenue.ToString("F2")</td>
|
||||
<td>
|
||||
@if (bot.LastSeenAt.HasValue)
|
||||
{
|
||||
<span title="@bot.LastSeenAt.Value.ToString("yyyy-MM-dd HH:mm:ss")">
|
||||
@((DateTime.UtcNow - bot.LastSeenAt.Value).TotalMinutes < 5 ? "Online" : bot.LastSeenAt.Value.ToString("yyyy-MM-dd HH:mm"))
|
||||
</span>
|
||||
@if ((DateTime.UtcNow - bot.LastSeenAt.Value).TotalMinutes < 5)
|
||||
{
|
||||
<span class="text-success">●</span>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">Never</span>
|
||||
}
|
||||
</td>
|
||||
<td>@bot.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
<a href="/Admin/Bots/Details/@bot.Id" class="btn btn-outline-info" title="View Details">
|
||||
<i class="bi bi-eye"></i>
|
||||
</a>
|
||||
<a href="/Admin/Bots/Edit/@bot.Id" class="btn btn-outline-primary" title="Edit">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</a>
|
||||
<a href="/Admin/Bots/Metrics/@bot.Id" class="btn btn-outline-success" title="View Metrics">
|
||||
<i class="bi bi-graph-up"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@if (!Model.Any())
|
||||
{
|
||||
<div class="alert alert-info">
|
||||
No bots have been registered yet. <a asp-action="Create">Register your first bot</a>.
|
||||
</div>
|
||||
}
|
||||
284
LittleShop/Areas/Admin/Views/Bots/Metrics.cshtml
Normal file
284
LittleShop/Areas/Admin/Views/Bots/Metrics.cshtml
Normal file
@@ -0,0 +1,284 @@
|
||||
@model LittleShop.DTOs.BotMetricsSummaryDto
|
||||
@{
|
||||
ViewData["Title"] = $"Bot Metrics - {Model.BotName}";
|
||||
var bot = ViewData["Bot"] as LittleShop.DTOs.BotDto;
|
||||
var sessionSummary = ViewData["SessionSummary"] as LittleShop.DTOs.BotSessionSummaryDto;
|
||||
var startDate = (DateTime)ViewData["StartDate"]!;
|
||||
var endDate = (DateTime)ViewData["EndDate"]!;
|
||||
}
|
||||
|
||||
<h1>Bot Metrics</h1>
|
||||
<h3>@Model.BotName</h3>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-12">
|
||||
<form method="get" class="row g-3">
|
||||
<div class="col-auto">
|
||||
<label for="startDate" class="col-form-label">Start Date:</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input type="date" id="startDate" name="startDate" class="form-control" value="@startDate.ToString("yyyy-MM-dd")" />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label for="endDate" class="col-form-label">End Date:</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input type="date" id="endDate" name="endDate" class="form-control" value="@endDate.ToString("yyyy-MM-dd")" />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="submit" class="btn btn-primary">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="text-primary">@Model.TotalSessions</h2>
|
||||
<p class="text-muted">Total Sessions</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="text-success">@Model.TotalOrders</h2>
|
||||
<p class="text-muted">Total Orders</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="text-info">$@Model.TotalRevenue.ToString("F2")</h2>
|
||||
<p class="text-muted">Total Revenue</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="text-warning">@Model.TotalMessages</h2>
|
||||
<p class="text-muted">Total Messages</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Performance Metrics</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row">
|
||||
<dt class="col-sm-6">Average Response Time:</dt>
|
||||
<dd class="col-sm-6">@Model.AverageResponseTime.ToString("F2") ms</dd>
|
||||
|
||||
<dt class="col-sm-6">Uptime Percentage:</dt>
|
||||
<dd class="col-sm-6">
|
||||
@if (Model.UptimePercentage > 0)
|
||||
{
|
||||
<span class="badge bg-success">@Model.UptimePercentage.ToString("F1")%</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">N/A</span>
|
||||
}
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-6">Total Errors:</dt>
|
||||
<dd class="col-sm-6">
|
||||
@if (Model.TotalErrors > 0)
|
||||
{
|
||||
<span class="text-danger">@Model.TotalErrors</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-success">0</span>
|
||||
}
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-6">Unique Sessions:</dt>
|
||||
<dd class="col-sm-6">@Model.UniqueSessions</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Session Statistics</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (sessionSummary != null)
|
||||
{
|
||||
<dl class="row">
|
||||
<dt class="col-sm-6">Active Sessions:</dt>
|
||||
<dd class="col-sm-6">@sessionSummary.ActiveSessions</dd>
|
||||
|
||||
<dt class="col-sm-6">Completed Sessions:</dt>
|
||||
<dd class="col-sm-6">@sessionSummary.CompletedSessions</dd>
|
||||
|
||||
<dt class="col-sm-6">Avg Session Duration:</dt>
|
||||
<dd class="col-sm-6">@sessionSummary.AverageSessionDuration.ToString("F1") min</dd>
|
||||
|
||||
<dt class="col-sm-6">Avg Orders/Session:</dt>
|
||||
<dd class="col-sm-6">@sessionSummary.AverageOrdersPerSession.ToString("F2")</dd>
|
||||
|
||||
<dt class="col-sm-6">Avg Spend/Session:</dt>
|
||||
<dd class="col-sm-6">$@sessionSummary.AverageSpendPerSession.ToString("F2")</dd>
|
||||
</dl>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-muted">No session data available</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.MetricsByType.Any())
|
||||
{
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Metrics by Type</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Metric Type</th>
|
||||
<th>Total Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var metric in Model.MetricsByType.OrderByDescending(m => m.Value))
|
||||
{
|
||||
<tr>
|
||||
<td>@metric.Key</td>
|
||||
<td>@metric.Value.ToString("F0")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (sessionSummary != null)
|
||||
{
|
||||
<div class="row">
|
||||
@if (sessionSummary.SessionsByPlatform.Any())
|
||||
{
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Sessions by Platform</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled">
|
||||
@foreach (var platform in sessionSummary.SessionsByPlatform)
|
||||
{
|
||||
<li>@platform.Key: <strong>@platform.Value</strong></li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (sessionSummary.SessionsByCountry.Any())
|
||||
{
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Sessions by Country</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled">
|
||||
@foreach (var country in sessionSummary.SessionsByCountry.Take(5))
|
||||
{
|
||||
<li>@country.Key: <strong>@country.Value</strong></li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (sessionSummary.SessionsByLanguage.Any())
|
||||
{
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Sessions by Language</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled">
|
||||
@foreach (var language in sessionSummary.SessionsByLanguage)
|
||||
{
|
||||
<li>@language.Key: <strong>@language.Value</strong></li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (Model.TimeSeries.Any())
|
||||
{
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Activity Timeline</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<canvas id="metricsChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="mt-3">
|
||||
<a asp-action="Details" asp-route-id="@Model.BotId" class="btn btn-secondary">Back to Details</a>
|
||||
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@if (Model.TimeSeries.Any())
|
||||
{
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
const ctx = document.getElementById('metricsChart').getContext('2d');
|
||||
const chart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [@Html.Raw(string.Join(",", Model.TimeSeries.Select(t => $"'{t.Label}'")))],
|
||||
datasets: [{
|
||||
label: 'Activity',
|
||||
data: [@string.Join(",", Model.TimeSeries.Select(t => t.Value))],
|
||||
borderColor: 'rgb(75, 192, 192)',
|
||||
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
||||
tension: 0.1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
}
|
||||
230
LittleShop/Areas/Admin/Views/Bots/Wizard.cshtml
Normal file
230
LittleShop/Areas/Admin/Views/Bots/Wizard.cshtml
Normal file
@@ -0,0 +1,230 @@
|
||||
@model LittleShop.DTOs.BotWizardDto
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Telegram Bot Creation Wizard";
|
||||
var showCommands = ViewData["ShowCommands"] as bool? ?? false;
|
||||
var commands = ViewData["BotFatherCommands"] as string ?? "";
|
||||
}
|
||||
|
||||
<h1>Telegram Bot Creation Wizard</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
@if (!showCommands)
|
||||
{
|
||||
<!-- Step 1: Basic Info -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Step 1: Bot Information</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form asp-area="Admin" asp-controller="Bots" asp-action="Wizard" method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="BotName" class="form-label">Bot Display Name</label>
|
||||
<input asp-for="BotName" class="form-control"
|
||||
placeholder="e.g., LittleShop Electronics Bot" required />
|
||||
<span asp-validation-for="BotName" class="text-danger"></span>
|
||||
<small class="text-muted">This is the name users will see</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="BotUsername" class="form-label">Bot Username</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">@@</span>
|
||||
<input asp-for="BotUsername" class="form-control"
|
||||
placeholder="littleshop_bot" required />
|
||||
</div>
|
||||
<span asp-validation-for="BotUsername" class="text-danger"></span>
|
||||
<small class="text-muted">Must end with 'bot' and be unique on Telegram</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="PersonalityName" class="form-label">Personality</label>
|
||||
<select asp-for="PersonalityName" class="form-select">
|
||||
<option value="">Auto-assign (recommended)</option>
|
||||
<option value="Alan" @(Model.PersonalityName == "Alan" ? "selected" : "")>Alan (Professional)</option>
|
||||
<option value="Dave" @(Model.PersonalityName == "Dave" ? "selected" : "")>Dave (Casual)</option>
|
||||
<option value="Sarah" @(Model.PersonalityName == "Sarah" ? "selected" : "")>Sarah (Helpful)</option>
|
||||
<option value="Mike" @(Model.PersonalityName == "Mike" ? "selected" : "")>Mike (Direct)</option>
|
||||
<option value="Emma" @(Model.PersonalityName == "Emma" ? "selected" : "")>Emma (Friendly)</option>
|
||||
<option value="Tom" @(Model.PersonalityName == "Tom" ? "selected" : "")>Tom (Efficient)</option>
|
||||
</select>
|
||||
<small class="text-muted">Bot conversation style (can be changed later)</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="Description" class="form-label">Description (Optional)</label>
|
||||
<textarea asp-for="Description" class="form-control" rows="2"
|
||||
placeholder="Brief description of what this bot does"></textarea>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Generate BotFather Commands" class="btn btn-primary" />
|
||||
<a href="/Admin/Bots" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<!-- Step 2: BotFather Commands & Token -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h5 class="mb-0">Step 2: Create Bot with BotFather</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info">
|
||||
<strong>Follow these steps in Telegram:</strong>
|
||||
</div>
|
||||
|
||||
<div class="bg-light p-3 rounded">
|
||||
<pre class="mb-0">@commands</pre>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<button class="btn btn-sm btn-outline-secondary" onclick="copyCommands()">
|
||||
<i class="fas fa-copy"></i> Copy Instructions
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Step 3: Complete Bot Setup</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="/Admin/Bots/CompleteWizard" method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<!-- Hidden fields to preserve data -->
|
||||
<input type="hidden" name="BotName" value="@Model.BotName" />
|
||||
<input type="hidden" name="BotUsername" value="@Model.BotUsername" />
|
||||
<input type="hidden" name="Description" value="@Model.Description" />
|
||||
<input type="hidden" name="PersonalityName" value="@Model.PersonalityName" />
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="BotToken" class="form-label">Bot Token from BotFather</label>
|
||||
<input name="BotToken" id="BotToken" class="form-control font-monospace"
|
||||
value="@Model.BotToken" placeholder="123456789:ABCdefGHIjklMNOpqrsTUVwxyz" required />
|
||||
<span asp-validation-for="BotToken" class="text-danger"></span>
|
||||
<small class="text-muted">Paste the token you received from @@BotFather</small>
|
||||
</div>
|
||||
|
||||
<div class="d-grid gap-2 d-md-flex">
|
||||
<button type="submit" class="btn btn-success me-md-2">
|
||||
<i class="fas fa-check"></i> Create Bot & Validate Token
|
||||
</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="history.back()">
|
||||
<i class="fas fa-arrow-left"></i> Back to Edit Info
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Wizard Progress</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled">
|
||||
<li class="@(!showCommands ? "text-primary fw-bold" : "text-success")">
|
||||
<i class="fas fa-@(!showCommands ? "edit" : "check")"></i>
|
||||
1. Bot Information
|
||||
</li>
|
||||
<li class="@(showCommands && string.IsNullOrEmpty(Model.BotToken) ? "text-primary fw-bold" : showCommands ? "text-success" : "text-muted")">
|
||||
<i class="fas fa-@(showCommands && string.IsNullOrEmpty(Model.BotToken) ? "robot" : showCommands ? "check" : "circle")"></i>
|
||||
2. Create with BotFather
|
||||
</li>
|
||||
<li class="@(!string.IsNullOrEmpty(Model.BotToken) ? "text-primary fw-bold" : "text-muted")">
|
||||
<i class="fas fa-@(!string.IsNullOrEmpty(Model.BotToken) ? "key" : "circle")"></i>
|
||||
3. Complete Setup
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (showCommands)
|
||||
{
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Quick Tips</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="small">
|
||||
<li>BotFather responds instantly</li>
|
||||
<li>Username must end with 'bot'</li>
|
||||
<li>Keep your token secure</li>
|
||||
<li>Token starts with numbers followed by colon</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Personality Preview</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="small">
|
||||
@if (!string.IsNullOrEmpty(Model.PersonalityName))
|
||||
{
|
||||
<strong>@Model.PersonalityName</strong><text> personality selected</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>Auto-assigned personality based on bot name</text>
|
||||
}
|
||||
</p>
|
||||
|
||||
<p class="small text-muted">
|
||||
Personalities affect how your bot communicates with customers.
|
||||
This can be customized later in bot settings.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<partial name="_ValidationScriptsPartial" />
|
||||
<script>
|
||||
// Test if JavaScript is working
|
||||
console.log('Wizard page scripts loaded');
|
||||
|
||||
function copyCommands() {
|
||||
const commands = `@Html.Raw(commands)`;
|
||||
navigator.clipboard.writeText(commands).then(() => {
|
||||
alert('Commands copied to clipboard!');
|
||||
});
|
||||
}
|
||||
|
||||
// Auto-generate username from bot name
|
||||
$(document).ready(function() {
|
||||
console.log('Document ready, setting up auto-generation');
|
||||
|
||||
$('#BotName').on('input', function() {
|
||||
try {
|
||||
const name = $(this).val().toLowerCase()
|
||||
.replace(/[^a-z0-9]/g, '_')
|
||||
.replace(/_+/g, '_')
|
||||
.replace(/^_|_$/g, '');
|
||||
|
||||
if (name && !name.endsWith('_bot')) {
|
||||
$('#BotUsername').val(name + '_bot');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error in auto-generation:', err);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -10,6 +10,12 @@
|
||||
<p class="text-muted">Order ID: @Model.Id</p>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
@if (Model.Customer != null)
|
||||
{
|
||||
<button class="btn btn-success" onclick="showMessageModal('@Model.Id', '@Model.Customer.DisplayName')">
|
||||
<i class="fas fa-comment"></i> Message Customer
|
||||
</button>
|
||||
}
|
||||
<a href="@Url.Action("Edit", new { id = Model.Id })" class="btn btn-primary">
|
||||
<i class="fas fa-edit"></i> Edit Order
|
||||
</a>
|
||||
@@ -28,7 +34,28 @@
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<p><strong>Identity Reference:</strong> @Model.IdentityReference</p>
|
||||
@if (Model.Customer != null)
|
||||
{
|
||||
<p><strong>Customer:</strong> @Model.Customer.DisplayName
|
||||
@if (!string.IsNullOrEmpty(Model.Customer.TelegramUsername))
|
||||
{
|
||||
<span class="text-muted">(@@@Model.Customer.TelegramUsername)</span>
|
||||
}
|
||||
</p>
|
||||
<p><strong>Customer Type:</strong> <span class="badge bg-info">@Model.Customer.CustomerType</span></p>
|
||||
@if (Model.Customer.RiskScore > 0)
|
||||
{
|
||||
<p><strong>Risk Score:</strong>
|
||||
<span class="badge @(Model.Customer.RiskScore > 50 ? "bg-danger" : Model.Customer.RiskScore > 25 ? "bg-warning" : "bg-success")">
|
||||
@Model.Customer.RiskScore/100
|
||||
</span>
|
||||
</p>
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(Model.IdentityReference))
|
||||
{
|
||||
<p><strong>Identity Reference:</strong> @Model.IdentityReference</p>
|
||||
}
|
||||
<p><strong>Status:</strong>
|
||||
@{
|
||||
var badgeClass = Model.Status switch
|
||||
@@ -192,4 +219,126 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.Customer != null)
|
||||
{
|
||||
<!-- Customer Messaging Modal -->
|
||||
<div class="modal fade" id="messageModal" tabindex="-1" aria-labelledby="messageModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="messageModalLabel">
|
||||
<i class="fas fa-comment"></i> Message Customer: <span id="customerName"></span>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="messageForm">
|
||||
<input type="hidden" id="orderId" name="orderId" />
|
||||
<input type="hidden" id="customerId" name="customerId" value="@Model.Customer.Id" />
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="messageType" class="form-label">Message Type</label>
|
||||
<select class="form-select" id="messageType" name="messageType" required>
|
||||
<option value="0">Order Update</option>
|
||||
<option value="1">Payment Reminder</option>
|
||||
<option value="2">Shipping Information</option>
|
||||
<option value="3">Customer Service</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="messageSubject" class="form-label">Subject</label>
|
||||
<input type="text" class="form-control" id="messageSubject" name="subject" required
|
||||
placeholder="Brief subject line..." maxlength="100">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="messageContent" class="form-label">Message</label>
|
||||
<textarea class="form-control" id="messageContent" name="content" rows="4" required
|
||||
placeholder="Type your message to the customer..." maxlength="1000"></textarea>
|
||||
<div class="form-text">Message will be delivered via Telegram</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="isUrgent" name="isUrgent">
|
||||
<label class="form-check-label" for="isUrgent">
|
||||
Mark as urgent (higher priority delivery)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" onclick="sendMessage()">
|
||||
<i class="fas fa-paper-plane"></i> Send Message
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<script>
|
||||
function showMessageModal(orderId, customerName) {
|
||||
document.getElementById('orderId').value = orderId;
|
||||
document.getElementById('customerName').textContent = customerName;
|
||||
|
||||
// Clear previous form data
|
||||
document.getElementById('messageForm').reset();
|
||||
document.getElementById('orderId').value = orderId; // Reset cleared this
|
||||
|
||||
// Show modal
|
||||
var modal = new bootstrap.Modal(document.getElementById('messageModal'));
|
||||
modal.show();
|
||||
}
|
||||
|
||||
function sendMessage() {
|
||||
const form = document.getElementById('messageForm');
|
||||
const formData = new FormData(form);
|
||||
|
||||
const messageData = {
|
||||
customerId: formData.get('customerId'),
|
||||
orderId: formData.get('orderId'),
|
||||
type: parseInt(formData.get('messageType')),
|
||||
subject: formData.get('subject'),
|
||||
content: formData.get('content'),
|
||||
isUrgent: formData.get('isUrgent') === 'on',
|
||||
priority: formData.get('isUrgent') === 'on' ? 1 : 5
|
||||
};
|
||||
|
||||
// Send message via API
|
||||
fetch('/api/messages', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + sessionStorage.getItem('authToken')
|
||||
},
|
||||
body: JSON.stringify(messageData)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
// Close modal and show success
|
||||
var modal = bootstrap.Modal.getInstance(document.getElementById('messageModal'));
|
||||
modal.hide();
|
||||
|
||||
// Show success message
|
||||
alert('Message sent successfully! The customer will receive it via Telegram.');
|
||||
|
||||
// Optionally refresh the page to show updated communication history
|
||||
window.location.reload();
|
||||
} else {
|
||||
response.text().then(error => {
|
||||
alert('Failed to send message: ' + error);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error sending message:', error);
|
||||
alert('Error sending message. Please try again.');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@@ -37,7 +37,27 @@
|
||||
{
|
||||
<tr>
|
||||
<td><code>@order.Id.ToString().Substring(0, 8)...</code></td>
|
||||
<td>@order.ShippingName</td>
|
||||
<td>
|
||||
@if (order.Customer != null)
|
||||
{
|
||||
<div>
|
||||
<strong>@order.Customer.DisplayName</strong>
|
||||
@if (!string.IsNullOrEmpty(order.Customer.TelegramUsername))
|
||||
{
|
||||
<br><small class="text-muted">@@@order.Customer.TelegramUsername</small>
|
||||
}
|
||||
<br><small class="badge bg-info">@order.Customer.CustomerType</small>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">@order.ShippingName</span>
|
||||
@if (!string.IsNullOrEmpty(order.IdentityReference))
|
||||
{
|
||||
<br><small class="text-muted">(@order.IdentityReference)</small>
|
||||
}
|
||||
}
|
||||
</td>
|
||||
<td>@order.ShippingCity, @order.ShippingCountry</td>
|
||||
<td>
|
||||
@{
|
||||
@@ -60,6 +80,12 @@
|
||||
<a href="@Url.Action("Details", new { id = order.Id })" class="btn btn-sm btn-outline-primary">
|
||||
<i class="fas fa-eye"></i> View
|
||||
</a>
|
||||
@if (order.Customer != null)
|
||||
{
|
||||
<a href="@Url.Action("Details", new { id = order.Id })" class="btn btn-sm btn-success ms-1" title="Message Customer">
|
||||
<i class="fas fa-comment"></i>
|
||||
</a>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<title>@ViewData["Title"] - LittleShop Admin</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
@@ -49,6 +50,11 @@
|
||||
<i class="fas fa-users"></i> Users
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="@Url.Action("Index", "Bots", new { area = "Admin" })">
|
||||
<i class="fas fa-robot"></i> Bots
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item dropdown">
|
||||
@@ -76,6 +82,7 @@
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@* Client-side validation scripts *@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.12/jquery.validate.unobtrusive.min.js"></script>
|
||||
Reference in New Issue
Block a user