Esempio n. 1
0
        private void ReplyMessage(long chatId, string mensagem)
        {
            string URL = "https://api.telegram.org/bot" + TelegramBotController.GetBotToken() +
                         "/sendMessage?chat_id=" + chatId + "&text=" + mensagem;

            var getUpdates = WebRequest.Create(URL) as HttpWebRequest;

            getUpdates.Method = "GET";

            object responseItems = new object();

            try
            {
                string respBody = null;
                using (var resp = getUpdates.GetResponse().GetResponseStream())
                {
                    var respR = new StreamReader(resp);
                    respBody = respR.ReadToEnd();
                }

                responseItems = new JavaScriptSerializer().Deserialize <object>(respBody);
            }
            catch
            {
                throw new Exception("Error sending the message! chatId: " + chatId);
            }
        }
Esempio n. 2
0
        public TelegramUpdate GetUpdates()
        {
            string URL = "https://api.telegram.org/bot" + TelegramBotController.GetBotToken() + "/getUpdates";

            var getUpdates = WebRequest.Create(URL) as HttpWebRequest;

            getUpdates.Method = "GET";

            object responseItems = new object();

            try
            {
                string respBody = null;
                using (var resp = getUpdates.GetResponse().GetResponseStream())
                {
                    var respR = new StreamReader(resp);
                    respBody = respR.ReadToEnd();
                }

                responseItems = new JavaScriptSerializer().Deserialize <object>(respBody);
            }
            catch
            {
                throw new Exception("Error getting updates from Telegram!");
            }

            return(AdjustResponse(responseItems));
        }