-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTelegramService.cs
71 lines (65 loc) · 1.97 KB
/
TelegramService.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
66
67
68
69
70
71
using MSC;
using MSC.Brute;
namespace MSC
{
public class TelegramService
{
public enum ParseMode
{
Markdown,
HTML,
None
}
private string Token;
private string ID;
Requester Rer;
public Logger CoreLogger()
{
return Rer.GetCoreLogger();
}
public Logger BaseLogger()
{
return Rer.GetBaseLogger();
}
public TelegramService(string BotToken, string UserID)
{
Token = BotToken;
ID = UserID;
Rer = new Requester();
}
public void SendMessage(string text, ParseMode mode = ParseMode.None)
{
Config config = new Config();
Account ac = new Account();
ac.Username = ID;
ac.Password = Token;
text = EncodeText(text);
string pst = "https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=<ID>&text=<TEXT>";
config.DataSet = "<ID>*<TOKEN>";
pst = Rer.ReplaceAccount(ac, pst, config);
pst = pst.Replace("<TEXT>", text);
string modetext = "";
switch (mode)
{
case ParseMode.HTML:
modetext = ParseMode.HTML.ToString();
break;
case ParseMode.Markdown:
modetext = ParseMode.Markdown.ToString();
break;
case ParseMode.None:
modetext = "";
break;
}
pst += "&parse_mode=" + modetext;
config.LoginURL = pst;
config.AllowAutoRedirect = true;
RequestManage send = Rer.GETData(config);
}
private static string EncodeText(string text)
{
text = text.Replace("&", "%26");
return text;
}
}
}