-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelegramMessage.cs
34 lines (29 loc) · 1.1 KB
/
TelegramMessage.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
using System.Text;
using System.Text.Json;
namespace JLOrdaz.TelegramBotMessage
{
internal class TelegramMessage
{
HttpClient http;
Uri apiUrl;
internal TelegramMessage(string tokenBot)
{
apiUrl = new Uri(uriString: $"https://api.telegram.org/bot{tokenBot}/sendMessage");
http = new HttpClient();
http.Timeout = new TimeSpan(0,0,10);
}
internal async Task<string> SendMessage(string chatId, string message)
{
message = message.Replace("_", "");
RequestMessage requestMessage = new RequestMessage()
{
chat_id = chatId,
text = message + System.Environment.NewLine + DateTime.Now.ToString(),
parse_mode = "HTML"//"markdown"
};
StringContent content = new StringContent(JsonSerializer.Serialize(requestMessage),Encoding.UTF8,"application/json");
var response = await http.PostAsync(apiUrl.AbsoluteUri, content);
return await response.Content.ReadAsStringAsync();
}
}
}