-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelegramBot.cs
65 lines (57 loc) · 2.48 KB
/
TelegramBot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Newtonsoft.Json;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace MindMate
{
public class TelegramBot
{
private static TelegramBotClient client { get; set; }
public static TelegramBotClient GetTelegramBot()
{
string bot_key = DotNetEnv.Env.GetString("TG_BOT");
client = new TelegramBotClient(bot_key);
return client;
}
public static async Task<Message> SendMessage(long chatId, string userMessage, ParseMode mode) =>
await client.SendTextMessageAsync( chatId: chatId, text: userMessage, parseMode: mode);
public static async Task UpdateMessage(long chatId, Message message, string userMessage, ParseMode mode) =>
await client.EditMessageTextAsync(chatId: chatId, messageId: message.MessageId, text: userMessage, parseMode: mode);
public static async Task DeleteMessage(long chatId, Message message) =>
await client.DeleteMessageAsync(chatId: chatId, messageId: message.MessageId);
public static async Task<EvaluationResult> GetEvaluationResult (string address)
{
string apiUrl = $"{DotNetEnv.Env.GetString("API_URL")}tron/check_address/" + address;
try
{
using (HttpClient httpClient = new HttpClient())
{
HttpResponseMessage response = await httpClient.GetAsync(apiUrl);
if (response.IsSuccessStatusCode)
{
string jsonResponse = await response.Content.ReadAsStringAsync();
EvaluationResult result = JsonConvert.DeserializeObject<EvaluationResult>(jsonResponse);
return result;
}
else
{
Console.WriteLine($"Error: {response.StatusCode} - {response.ReasonPhrase}");
return null;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}");
return null;
}
}
public static string GenerateOrderNumber()
{
DateTime now = DateTime.UtcNow;
long unixTimestamp = ((DateTimeOffset)now).ToUnixTimeSeconds();
string orderNumber = unixTimestamp.ToString().Substring(3); // Removing the first three digits
return orderNumber;
}
}
}