Exemplo n.º 1
0
        /// <summary>
        /// Use this method to send point on the map. On success, the sent Message is returned.
        /// </summary>
        /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
        /// <param name="latitud">Latitude of location.</param>
        /// <param name="longitud">Longitude of location.</param>
        /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
        /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
        /// <returns></returns>
        public Message SendLocation(int chat_id, float latitud, float longitud, ForceReply reply_markup, int reply_to_message_id = -1)
        {
            string url = BaseUrl + "sendLocation?chat_id=" + chat_id + "&latitud=" + latitud + "&longitud=" + longitud;
            if (reply_to_message_id != -1)
                url += "&reply_to_message_id=" + reply_to_message_id;
            if (reply_markup != null)
                url += "&reply_markup=" + JsonConvert.SerializeObject(reply_markup, Formatting.None);

            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";

            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            return ParseResponseMessage(responseString);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Use this method to send text messages. On success, the sent Message is returned.
        /// </summary>
        /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
        /// <param name="text">Text of the message to be sent.</param>
        /// <param name="disable_web_page_preview">Disables link previews for links in this message.</param>
        /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
        /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
        /// <returns></returns>
        public Message SendMessage(int chat_id, string text, ForceReply reply_markup, bool disable_web_page_preview = false, int reply_to_message_id = -1)
        {
            string url = BaseUrl + "sendMessage?text=" + text + "&chat_id=" + chat_id;
            if (disable_web_page_preview)
                url += "&disable_web_page_preview=true";
            if (reply_to_message_id != -1)
                url += "&reply_to_message_id=" + reply_to_message_id;
            if (reply_markup != null)
                url += "&reply_markup=" + JsonConvert.SerializeObject(reply_markup, Formatting.None);

            Console.WriteLine(url);

            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";

            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            return ParseResponseMessage(responseString);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
 /// </summary>
 /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
 /// <param name="audio_path">Audio file to send. You can upload a new audio file using multipart/form-data.</param>
 /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
 /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
 /// <returns></returns>
 public Message SendAudio(int chat_id, string audio_path, ForceReply reply_markup, int reply_to_message_id = -1)
 {
     return SendMultimedia(chat_id, audio_path, MultimediaType.Audio, reply_markup, null, reply_to_message_id);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
 /// </summary>
 /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
 /// <param name="document_path">File to send. You can upload a new file using multipart/form-data.</param>
 /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
 /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
 /// <returns></returns>
 public Message SendDocument(int chat_id, string document_path, ForceReply reply_markup, int reply_to_message_id = -1)
 {
     return SendMultimedia(chat_id, document_path, MultimediaType.Document, reply_markup, null, reply_to_message_id);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
 /// </summary>
 /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
 /// <param name="video_id">Video file to send. You can pass a file_id as String to resend an video that is already on the Telegram servers.</param>
 /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
 /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
 /// <returns></returns>
 public Message ResendVideo(int chat_id, string video_id, ForceReply reply_markup, int reply_to_message_id = -1)
 {
     return ResendMultimedia(chat_id, video_id, MultimediaType.Video, reply_markup, null, reply_to_message_id);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Use this method to send .webp stickers. On success, the sent Message is returned.
 /// </summary>
 /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
 /// <param name="sticker_id">Sticker to send. You can pass a file_id as String to resend a sticker that is already on the Telegram servers.</param>
 /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
 /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
 /// <returns></returns>
 public Message ResendSticker(int chat_id, string sticker_id, ForceReply reply_markup, int reply_to_message_id = -1)
 {
     return ResendMultimedia(chat_id, sticker_id, MultimediaType.Sticker, reply_markup, null, reply_to_message_id);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Use this method to send photos. On success, the sent Message is returned.
 /// </summary>
 /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
 /// <param name="photo_id">Photo to send. You can pass a file_id as String to resend a photo that is already on the Telegram servers.</param>
 /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
 /// <param name="caption">Photo caption (may also be used when resending photos by file_id).</param>
 /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
 /// <returns></returns>
 public Message ResendPhoto(int chat_id, string photo_id, ForceReply reply_markup, string caption = null, int reply_to_message_id = -1)
 {
     return ResendMultimedia(chat_id, photo_id, MultimediaType.Photo, reply_markup, caption, reply_to_message_id);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Use this method to send multimedia files. On success, the sent Message is returned.
        /// </summary>
        /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
        /// <param name="photo_id">File to send. You can pass a file_id as String to resend a photo that is already on the Telegram servers.</param>
        /// <param name="type">Type of file to send.</param>
        /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
        /// <param name="caption">Photo caption (only use with Type.Photo).</param>
        /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
        /// <returns></returns>
        public Message ResendMultimedia(int chat_id, string photo_id, MultimediaType type, ForceReply reply_markup, string caption = null, int reply_to_message_id = -1)
        {
            string url = BaseUrl + "send" + type.ToString() + "?chat_id=" + chat_id + "&" + type.ToString().ToLower() + "=" + photo_id;
            if (!string.IsNullOrEmpty(caption) && type == MultimediaType.Photo)
                url += "&caption=" + caption;
            if (reply_to_message_id != -1)
                url += "&reply_to_message_id=" + reply_to_message_id;
            if (reply_markup != null)
                url += "&reply_markup=" + JsonConvert.SerializeObject(reply_markup, Formatting.None);

            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";

            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            return ParseResponseMessage(responseString);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Use this method to send multimedia files. On success, the sent Message is returned.
        /// </summary>
        /// <param name="chat_id">Unique identifier for the message recipient — User or GroupChat id.</param>
        /// <param name="file_path">File to send. You can upload a new file using multipart/form-data.</param>
        /// <param name="type">Type of file to send.</param>
        /// <param name="reply_markup">Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.</param>
        /// <param name="caption">Photo caption (only use with Type.Photo).</param>
        /// <param name="reply_to_message_id">If the message is a reply, ID of the original message.</param>
        /// <returns></returns>
        public Message SendMultimedia(int chat_id, string file_path, MultimediaType type, ForceReply reply_markup, string caption = null, int reply_to_message_id = -1)
        {
            string url = BaseUrl + "send" + type.ToString();

            byte[] file = null;
            using (var content = new MultipartFormDataContent("-------BotAPIDotNET"))
            {
                content.Add(new StringContent(string.Format("{0}", chat_id)), "chat_id");
                var fileStream = File.Open(file_path, FileMode.Open, FileAccess.Read);
                content.Add(new StreamContent(fileStream), type.ToString().ToLower(), file_path.Replace("\\", "/").Split('/').LastOrDefault());
                if (!string.IsNullOrEmpty(caption) && type == MultimediaType.Photo)
                    content.Add(new StringContent(caption), "caption");
                if (reply_to_message_id != -1)
                    content.Add(new StringContent(string.Format("{0}", reply_to_message_id)), "reply_to_message_id");
                if (reply_markup != null)
                    content.Add(new StringContent(JsonConvert.SerializeObject(reply_markup, Formatting.None)), "reply_markup");

                Stream multipart = content.ReadAsStreamAsync().Result;
                file = new byte[multipart.Length];
                multipart.Seek(0, SeekOrigin.Begin);
                multipart.Read(file, 0, (int)multipart.Length);
            }

            var request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = "multipart/form-data; boundary=\"-------BotAPIDotNET\"";
            request.Method = "POST";

            using (Stream writer = request.GetRequestStream())
            {
                writer.Write(file, 0, file.Length);
            }

            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            return ParseResponseMessage(responseString);
        }