Beispiel #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);
            }
        }
Beispiel #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));
        }
Beispiel #3
0
        private void SaveIdLastMessageReplied(long messageId)
        {
            XDocument xmlDoc             = XDocument.Load(Properties.Resources.ADDRESS_UPDATECONTROLS);
            long      lastIdMessageSaved = TelegramBotController.GetLastMessageId();

            if (messageId < lastIdMessageSaved)
            {
                throw new Exception("Error! The messageId cannot be less than the last message ID saved!");
            }

            xmlDoc.Root.Element("LastMessageId").Remove();

            XElement root = xmlDoc.Element("Controls");

            root.Add(new XElement("LastMessageId", messageId));
            xmlDoc.Save(Properties.Resources.ADDRESS_UPDATECONTROLS);
        }