Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ClassTelegram
- {
- public string ApiToken { get; set; }
- public string ChatId { get; set; }
- public string Msg { get; set; }
- public string UrlString
- {
- get
- {
- string urlString = "https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}";
- return String.Format(urlString, ApiToken, ChatId, Msg);
- }
- }
- public string Send()
- {
- try
- {
- WebRequest request = WebRequest.Create(UrlString);
- Stream rs = request.GetResponse().GetResponseStream();
- StreamReader reader = new StreamReader(rs);
- string line = "";
- StringBuilder sb = new StringBuilder();
- while (line != null)
- {
- line = reader.ReadLine();
- if (line != null)
- sb.Append(line);
- }
- string response = sb.ToString();
- return response;
- }
- catch (Exception ex)
- {
- // Codice da eseguire in caso di eccezione.
- string errore;
- errore = "È avvenuta la seguente eccezione: " + System.Environment.NewLine;
- errore += ex.Message;
- return errore;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement