TelegramNotificationApi

mail@pastecode.io avatar
unknown
csharp
2 years ago
924 B
3
Indexable
Never
public  class TelegramNotificationApi
    {
        string api_token;

        public TelegramNotificationApi(string api_token)
        {
            this.api_token = api_token;
        }

        public void TelegramSendMessage(string destID, string subject, string message)
        {
            if(this.api_token !=null && this.api_token.Length > 0)
            {
                if (message != null)
                {
                    if(subject!=null && subject.Length > 0)
                    {
                        message = subject + "\n" + message;
                    }
                    string urlString = $"https://api.telegram.org/bot{this.api_token}/sendMessage?chat_id={destID}&text={message}";
                    WebClient webclient = new WebClient();
                    webclient.DownloadString(urlString);
                }
                
            }
        }
    }