Update bot messages
This commit is contained in:
@@ -17,6 +17,7 @@ public class UserController : BaseController
|
||||
{
|
||||
private IConfiguration _config;
|
||||
private readonly IJwtUtils _jwtUtils;
|
||||
private readonly IWebhookService _webhookService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserController"/> class.
|
||||
@@ -24,11 +25,13 @@ public class UserController : BaseController
|
||||
/// <param name="config">Configuration settings.</param>
|
||||
/// <param name="userService">Service for user-related operations.</param>
|
||||
/// <param name="jwtUtils">Utility for JWT token operations.</param>
|
||||
public UserController(IConfiguration config, IUserService userService, IJwtUtils jwtUtils)
|
||||
/// <param name="webhookService">Service for webhook operations.</param>
|
||||
public UserController(IConfiguration config, IUserService userService, IJwtUtils jwtUtils, IWebhookService webhookService)
|
||||
: base(userService)
|
||||
{
|
||||
_config = config;
|
||||
_jwtUtils = jwtUtils;
|
||||
_webhookService = webhookService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -98,7 +101,74 @@ public class UserController : BaseController
|
||||
{
|
||||
var user = await GetUser();
|
||||
var updatedUser = await _userService.UpdateTelegramChannel(user, telegramChannel);
|
||||
|
||||
// Send welcome message to the newly configured telegram channel
|
||||
if (!string.IsNullOrEmpty(telegramChannel))
|
||||
{
|
||||
try
|
||||
{
|
||||
var welcomeMessage = $"🎉 **Trading Bot - Welcome!**\n\n" +
|
||||
$"┌─────────────────────────────┐\n" +
|
||||
$"│ CHANNEL CONFIGURED ✅ │\n" +
|
||||
$"└─────────────────────────────┘\n\n" +
|
||||
$"🎯 **Agent:** {user.Name}\n" +
|
||||
$"📡 **Channel ID:** {telegramChannel}\n" +
|
||||
$"⏰ **Setup Time:** {DateTime.UtcNow:MMM dd, yyyy • HH:mm:ss} UTC\n\n" +
|
||||
$"🔔 **Notification Types:**\n" +
|
||||
$"• 📈 Position Opens & Closes\n" +
|
||||
$"• 🤖 Bot configuration changes\n\n" +
|
||||
$"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" +
|
||||
$"🚀 **Welcome aboard!** Your trading notifications are now live.";
|
||||
|
||||
await _webhookService.SendMessage(welcomeMessage, telegramChannel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log the error but don't fail the update operation
|
||||
Console.WriteLine($"Failed to send welcome message to telegram channel {telegramChannel}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(updatedUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the Telegram channel configuration by sending a test message.
|
||||
/// </summary>
|
||||
/// <returns>A message indicating the test result.</returns>
|
||||
[HttpPost("telegram-channel/test")]
|
||||
public async Task<ActionResult<string>> TestTelegramChannel()
|
||||
{
|
||||
var user = await GetUser();
|
||||
|
||||
if (string.IsNullOrEmpty(user.TelegramChannel))
|
||||
{
|
||||
return BadRequest("No Telegram channel configured for this user. Please set a Telegram channel first.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var testMessage = $"🚀 **Trading Bot - Channel Test**\n\n" +
|
||||
$"┌─────────────────────────────┐\n" +
|
||||
$"│ CONNECTION SUCCESSFUL ✅ │\n" +
|
||||
$"└─────────────────────────────┘\n\n" +
|
||||
$"🎯 **Agent:** {user.Name}\n" +
|
||||
$"📡 **Channel ID:** {user.TelegramChannel}\n" +
|
||||
$"⏰ **Test Time:** {DateTime.UtcNow:MMM dd, yyyy • HH:mm:ss} UTC\n\n" +
|
||||
$"🔔 **You will receive notifications for:**\n" +
|
||||
$"• 📈 Position Opens & Closes\n" +
|
||||
$"• 🤖 Bot configuration changes\n\n" +
|
||||
$"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" +
|
||||
$"🎉 **Ready to trade!** Your notifications are now active.";
|
||||
|
||||
await _webhookService.SendMessage(testMessage, user.TelegramChannel);
|
||||
|
||||
return Ok($"Test message sent successfully to Telegram channel {user.TelegramChannel}. Please check your Telegram to verify delivery.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Failed to send test message: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user