/// <summary>
        /// Use this method to send text messages. See <see href="https://core.telegram.org/bots/api#sendmessage">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="text">Text of the message to be sent</param>
        /// <param name="parseMode">Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message</param>
        /// <param name="disableWebPagePreview">Disables link previews for links in this message</param>
        /// <param name="disableNotification">Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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>On success, the sent <see cref="SendMessageResult"/> is returned.</returns>
        public SendMessageResult SendMessage(object chatId, string text,
                                             ParseMode?parseMode        = null,
                                             bool?disableWebPagePreview = null,
                                             bool?disableNotification   = null,
                                             int?replyToMessageId       = null,
                                             IReplyMarkup replyMarkup   = null)
        {
            RestRequest request = NewRestRequest(mSendMessageUri);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("text", text);
            if (parseMode != null)
            {
                request.AddParameter("parse_mode", parseMode.Value);
            }
            if (disableWebPagePreview.HasValue)
            {
                request.AddParameter("disable_web_page_preview", disableWebPagePreview.Value);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId.HasValue)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId.Value);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
        /// <summary>
        /// Use this method to send information about a venue.
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="latitude">Latitude of the venue</param>
        /// <param name="longitude">Longitude of the venue</param>
        /// <param name="title">Name of the venue</param>
        /// <param name="address">Address of the venue</param>
        /// <param name="foursquareId">Foursquare identifier of the venue</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">Additional interface options. A JSON-serialized object for an
        /// inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.</param>
        /// <returns>On success, the sent <see cref="SendMessageResult"/> is returned</returns>
        public SendMessageResult SendVenue(object chatId, float latitude, float longitude, string title, string address,
                                           string foursquareId      = null,
                                           bool?disableNotification = null,
                                           int?replyToMessageId     = null,
                                           IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendVenueUri);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("latitude", latitude);
            request.AddParameter("longitude", longitude);
            request.AddParameter("title", title);
            request.AddParameter("address", address);

            if (!string.IsNullOrEmpty(foursquareId))
            {
                request.AddParameter("foursquare_id", foursquareId);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
        /// <summary>
        /// Use this method to send phone contacts. See <see href="https://core.telegram.org/bots/api#sendcontact">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="phoneNumber">Contact's phone number</param>
        /// <param name="firstName">Contact's first name</param>
        /// <param name="lastName">Contact's last name</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
        /// instructions to remove keyboard or to force a reply from the user.</param>
        /// <returns>On success, the sent <see cref="MessageInfo"/> is returned.</returns>
        public SendMessageResult SendContact(object chatId, string phoneNumber, string firstName,
                                             string lastName          = null,
                                             bool?disableNotification = null,
                                             int?replyToMessageId     = null,
                                             IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendContactUri);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("phone_number", phoneNumber);
            request.AddParameter("first_name", firstName);

            if (!string.IsNullOrEmpty(lastName))
            {
                request.AddParameter("last_name", lastName);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
        /// <summary>
        /// As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
        /// Use this method to send video messages.
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="videoNote">Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended)
        /// or upload a new video using multipart/form-data.
        /// Sending video notes by a URL is currently unsupported</param>
        /// <param name="duration">Optional. Duration of sent video in seconds</param>
        /// <param name="length">Optional. Video width and height</param>
        /// <param name="disableNotification">Optional. Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">Optional. If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">Optional. Additional interface options.
        /// A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.</param>
        /// <returns>On success, the sent <see cref="MessageInfo"/> is returned</returns>
        public SendMessageResult SendVideoNote(object chatId, IFile videoNote,
                                               int?duration             = null,
                                               int?length               = null,
                                               bool?disableNotification = null,
                                               int?replyToMessageId     = null,
                                               IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendVideoNoteUri);

            request.AddParameter("chat_id", chatId);
            request = AddFile(videoNote, request, "video_note");

            if (duration != null)
            {
                request.AddParameter("duration", duration);
            }
            if (length != null)
            {
                request.AddParameter("length", length);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
        /// <summary>
        /// Use this method to send point on the map.
        /// See <see href="https://core.telegram.org/bots/api#sendlocation">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="latitude">Latitude of location</param>
        /// <param name="longitude">Longitude of location</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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>On success, the sent <see cref="MessageInfo"/> is returned.</returns>
        public SendMessageResult SendLocation(object chatId, float latitude, float longitude,
                                              bool?disableNotification = null,
                                              int?replyToMessageId     = null,
                                              IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendLocationUri);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("latitude", latitude);
            request.AddParameter("longitude", longitude);

            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
        /// <summary>
        /// Use this method to send .webp stickers. See <see href="https://core.telegram.org/bots/api#sendsticker">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="sticker">Sticker to send. You can either pass a file_id as String to resend a sticker that is
        /// already on the Telegram servers, or upload a new sticker using multipart/form-data.</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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>On success, the sent <see cref="MessageInfo"/> is returned.</returns>
        public SendMessageResult SendSticker(object chatId, IFile sticker,
                                             bool?disableNotification = null,
                                             int?replyToMessageId     = null,
                                             IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendStickerUri);

            request.AddParameter("chat_id", chatId);
            request = AddFile(sticker, request, "sticker");

            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
        /// <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 Audio or Document).
        /// On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="voice">Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended),
        /// pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data</param>
        /// <param name="caption">Voice message caption, 0-200 characters </param>
        /// <param name="duration">Duration of the voice message in seconds </param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
        /// instructions to remove reply keyboard or to force a reply from the user.</param>
        /// <returns></returns>
        public SendMessageResult SendVoice(object chatId, IFile voice,
                                           string caption           = null,
                                           int?duration             = null,
                                           bool?disableNotification = null,
                                           int?replyToMessageId     = null,
                                           IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendVoiceUri);

            request.AddParameter("chat_id", chatId);
            request = AddFile(voice, request, "voice");

            if (!string.IsNullOrEmpty(caption))
            {
                request.AddParameter("caption", caption);
            }
            if (duration != null)
            {
                request.AddParameter("duration", duration);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
Example #8
0
        /// <summary>
        /// Use this method to send text messages. On success, the sent Message is returned.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="text">Text of the message to be sent</param>
        /// <param name="disableWebPagePreview">Disables link previews for links in this message</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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 SendMessageResult SendMessage(int chatId, string text,
                                             bool?disableWebPagePreview = null,
                                             int?replyToMessageId       = null,
                                             IReplyMarkup replyMarkup   = null)
        {
            var request = new RestRequest(string.Format(sendMessageUri, Token), Method.POST);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("text", text);
            if (disableWebPagePreview.HasValue)
            {
                request.AddParameter("disable_web_page_preview", disableWebPagePreview.Value);
            }
            if (replyToMessageId.HasValue)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId.Value);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }
            var response = restClient.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(new SendMessageResult(response.Content));
            }
            else
            {
                throw new Exception(response.StatusDescription);
            }
        }
Example #9
0
        /// <summary>
        /// Use this method to send point on the map. On success, the sent Message is returned.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="latitude">Latitude of location</param>
        /// <param name="longitude">Longitude of location</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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 SendMessageResult SendLocation(int chatId, float latitude, float longitude,
                                              int?replyToMessageId     = null,
                                              IReplyMarkup replyMarkup = null)
        {
            var request = new RestRequest(string.Format(sendLocationUri, Token), Method.POST);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("latitude", latitude);
            request.AddParameter("longitude", longitude);
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }
            var response = restClient.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(new SendMessageResult(response.Content));
            }
            else
            {
                throw new Exception(response.StatusDescription);
            }
        }
        //todo sendVoice (https://core.telegram.org/bots/api#sendvoice)
        //todo sendVideonote (https://core.telegram.org/bots/api#sendvideonote)

        /// <summary>
        /// Use this method to send point on the map.
        /// See <see href="https://core.telegram.org/bots/api#sendlocation">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="latitude">Latitude of location</param>
        /// <param name="longitude">Longitude of location</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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>On success, the sent <see cref="MessageInfo"/> is returned.</returns>
        /// <remarks>Test NetTelebot.Tests.TelegramMockBotClientTest.SendLocationTest()</remarks>
        public SendMessageResult SendLocation(object chatId, float latitude, float longitude,
                                              bool?disableNotification = null,
                                              int?replyToMessageId     = null,
                                              IReplyMarkup replyMarkup = null)
        {
            RestRequest request = new RestRequest(string.Format(sendLocationUri, Token), Method.POST);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("latitude", latitude);
            request.AddParameter("longitude", longitude);

            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            IRestResponse response = RestClient.Execute(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(new SendMessageResult(response.Content));
            }

            throw new Exception(response.StatusDescription);
        }
        /// <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.
        /// See <see href="https://core.telegram.org/bots/api#senddocument">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="document">File to send. You can either pass a file_id as String to resend a file that is already on the Telegram servers,
        /// or upload a new file using multipart/form-data.</param>
        /// <param name="caption">Document caption (may also be used when resending documents by file_id), 0-200 characters</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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>On success, the sent <see cref="MessageInfo"/> is returned.</returns>
        /// <remarks>Test NetTelebot.Tests.TelegramMockBotClientTest.SendDocumentTest()</remarks>
        public SendMessageResult SendDocument(object chatId, IFile document,
                                              string caption           = null,
                                              bool?disableNotification = null,
                                              int?replyToMessageId     = null,
                                              IReplyMarkup replyMarkup = null)
        {
            RestRequest request = new RestRequest(string.Format(sendDocumentUri, Token), Method.POST);

            request.AddParameter("chat_id", chatId);

            ExistingFile file = document as ExistingFile;

            if (file != null)
            {
                ExistingFile existingFile = file;
                request.AddParameter("document", existingFile.FileId);
            }
            else
            {
                NewFile newFile = (NewFile)document;
                request.AddFile("document", newFile.FileContent, newFile.FileName);
            }

            if (!string.IsNullOrEmpty(caption))
            {
                request.AddParameter("caption", caption);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            IRestResponse response = RestClient.Execute(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(new SendMessageResult(response.Content));
            }

            throw new Exception(response.StatusDescription);
        }
        /// <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).
        /// Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
        /// See <see href="https://core.telegram.org/bots/api#sendaudio">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="audio">Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers,
        /// or upload a new audio file using multipart/form-data.</param>
        /// <param name="caption">Audio caption, 0-200 characters</param>
        /// <param name="duration">Duration of the audio in seconds</param>
        /// <param name="performer">Duration of the audio in seconds</param>
        /// <param name="title">Track name</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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>On success, the sent <see cref="SendMessageResult"/> is returned.</returns>
        public SendMessageResult SendAudio(object chatId, IFile audio,
                                           string caption           = null,
                                           int?duration             = null,
                                           string performer         = null,
                                           string title             = null,
                                           bool?disableNotification = null,
                                           int?replyToMessageId     = null,
                                           IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendAudioUri);

            request.AddParameter("chat_id", chatId);
            request = AddFile(audio, request, "audio");

            if (!string.IsNullOrEmpty(caption))
            {
                request.AddParameter("caption", caption);
            }
            if (duration != null)
            {
                request.AddParameter("duration", duration);
            }
            if (!string.IsNullOrEmpty(performer))
            {
                request.AddParameter("performer", performer);
            }
            if (!string.IsNullOrEmpty(title))
            {
                request.AddParameter("title", title);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }
Example #13
0
        /// <summary>
        /// Use this method to send photos. On success, the sent Message is returned.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="photo">Photo to send. You can either pass a file_id as String to resend a photo that is already on the Telegram servers (using ExistingFile class), or upload a new photo using multipart/form-data. (Using NewFile class)</param>
        /// <param name="caption">Photo caption (may also be used when resending photos by file_id).</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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 SendMessageResult SendPhoto(int chatId, IFile photo,
                                           string caption           = null,
                                           int?replyToMessageId     = null,
                                           IReplyMarkup replyMarkup = null)
        {
            var request = new RestRequest(string.Format(sendPhotoUri, Token), Method.POST);

            request.AddParameter("chat_id", chatId);
            if (photo is ExistingFile)
            {
                var existingFile = (ExistingFile)photo;
                request.AddParameter("photo", existingFile.FileId);
            }
            else
            {
                var newFile = (NewFile)photo;
                request.AddFile("photo", newFile.FileContent, newFile.FileName);
            }
            if (!string.IsNullOrEmpty(caption))
            {
                request.AddParameter("caption", caption);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }
            var response = restClient.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(new SendMessageResult(response.Content));
            }
            else
            {
                throw new Exception(response.StatusDescription);
            }
        }
        /// <summary>
        /// Use this method to send text messages. See <see href="https://core.telegram.org/bots/api#sendmessage">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="text">Text of the message to be sent</param>
        /// <param name="parseMode">Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message</param>
        /// <param name="disableWebPagePreview">Disables link previews for links in this message</param>
        /// <param name="disableNotification">Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">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>On success, the sent <see cref="MessageInfo"/> is returned.</returns>
        /// <remarks>Test NetTelebot.Tests.TelegramMockBotClientTest.SendMessageTest()</remarks>
        public SendMessageResult SendMessage(object chatId, string text,
                                             ParseMode?parseMode        = null,
                                             bool?disableWebPagePreview = null,
                                             bool?disableNotification   = null,
                                             int?replyToMessageId       = null,
                                             IReplyMarkup replyMarkup   = null)
        {
            RestRequest request = new RestRequest(string.Format(sendMessageUri, Token), Method.POST);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("text", text);
            if (parseMode != null)
            {
                request.AddParameter("parse_mode", parseMode.Value);
            }
            if (disableWebPagePreview.HasValue)
            {
                request.AddParameter("disable_web_page_preview", disableWebPagePreview.Value);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId.HasValue)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId.Value);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            IRestResponse response = RestClient.Execute(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(new SendMessageResult(response.Content));
            }

            throw new Exception(response.StatusDescription);
        }
        //todo sendVenue (https://core.telegram.org/bots/api#sendvenue)

        /// <summary>
        /// Use this method to send phone contacts. See <see href="https://core.telegram.org/bots/api#sendcontact">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format @channelusername)</param>
        /// <param name="phoneNumber">Contact's phone number</param>
        /// <param name="firstName">Contact's first name</param>
        /// <param name="lastName">Contact's last name</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
        /// instructions to remove keyboard or to force a reply from the user.</param>
        /// <returns>On success, the sent <see cref="MessageInfo"/> is returned.</returns>
        /// <remarks>Test NetTelebot.Tests.TelegramMockBotClientTest.SendContactTest()</remarks>
        public SendMessageResult SendContact(object chatId, string phoneNumber, string firstName,
                                             string lastName          = null,
                                             bool?disableNotification = null,
                                             int?replyToMessageId     = null,
                                             IReplyMarkup replyMarkup = null)
        {
            RestRequest request = new RestRequest(string.Format(sendContactUri, Token), Method.POST);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("phone_number", phoneNumber);
            request.AddParameter("first_name", firstName);

            if (!string.IsNullOrEmpty(lastName))
            {
                request.AddParameter("last_name", lastName);
            }
            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            IRestResponse response = RestClient.Execute(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(new SendMessageResult(response.Content));
            }

            throw new Exception(response.StatusDescription);
        }
Example #16
0
        /// <summary>
        /// Use this method to send invoices.
        /// See <see href="https://core.telegram.org/bots/api#sendinvoice">API</see>
        /// </summary>
        /// <param name="chatId">Unique identifier for the target private chat</param>
        /// <param name="title">Product name, 1-32 characters</param>
        /// <param name="description">Product description, 1-255 characters</param>
        /// <param name="payload">Bot-defined invoice payload, 1-128 bytes.
        /// This will not be displayed to the user, use for your internal processes.</param>
        /// <param name="providerToken">Payments provider token, obtained via Botfather</param>
        /// <param name="startParameter">Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter</param>
        /// <param name="currency">Three-letter ISO 4217 currency code</param>
        /// <param name="labeledPrice">Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)</param>
        /// <param name="photoUrl">URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
        /// People like it better when they see what they are paying for.</param>
        /// <param name="photoSize">Photo size</param>
        /// <param name="photoWidth">Photo width</param>
        /// <param name="photoHeight">Photo height</param>
        /// <param name="needName">Pass True, if you require the user's full name to complete the order</param>
        /// <param name="needPhoneNumber">Pass True, if you require the user's phone number to complete the order</param>
        /// <param name="needEmail">Pass True, if you require the user's email to complete the order</param>
        /// <param name="needShippingAdress">Pass True, if you require the user's shipping address to complete the order</param>
        /// <param name="isFlexible">Pass True, if the final price depends on the shipping method</param>
        /// <param name="disableNotification">Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message</param>
        /// <param name="replyMarkup">A JSON-serialized object for an inline keyboard.
        /// If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.</param>
        /// <returns>On success, the sent <see cref="SendMessageResult"/> is returned.</returns>
        public SendMessageResult SendInvoice(string chatId,
                                             string title,
                                             string description,
                                             string payload,
                                             string providerToken,
                                             string startParameter,
                                             Currency currency,
                                             LabeledPriceInfo[] labeledPrice,
                                             string photoUrl          = null,
                                             int?photoSize            = null,
                                             int?photoWidth           = null,
                                             int?photoHeight          = null,
                                             bool?needName            = null,
                                             bool?needPhoneNumber     = null,
                                             bool?needEmail           = null,
                                             bool?needShippingAdress  = null,
                                             bool?isFlexible          = null,
                                             bool?disableNotification = null,
                                             int?replyToMessageId     = null,
                                             IReplyMarkup replyMarkup = null)
        {
            RestRequest request = NewRestRequest(mSendInvoiceUri);

            request.AddParameter("chat_id", chatId);
            request.AddParameter("title", title);
            request.AddParameter("description", description);
            request.AddParameter("payload", payload);
            request.AddParameter("provider_token", providerToken);
            request.AddParameter("start_parameter", startParameter);
            request.AddParameter("currency", currency.ToString());
            request.AddParameter("prices", LabeledPriceInfo.GetJsonArray(labeledPrice));

            if (photoUrl != null)
            {
                request.AddParameter("photo_url", photoUrl);
            }
            if (photoSize != null)
            {
                request.AddParameter("photo_size", photoSize);
            }
            if (photoWidth != null)
            {
                request.AddParameter("photo_width", photoWidth);
            }
            if (photoHeight != null)
            {
                request.AddParameter("photo_height", photoHeight);
            }

            request.AddParameter("need_name", needName ?? false);
            request.AddParameter("need_phone_number", needPhoneNumber ?? false);
            request.AddParameter("need_email", needEmail ?? false);
            request.AddParameter("need_shipping_address", needShippingAdress ?? false);
            request.AddParameter("is_flexible", isFlexible ?? false);

            if (disableNotification.HasValue)
            {
                request.AddParameter("disable_notification", disableNotification.Value);
            }
            if (replyToMessageId != null)
            {
                request.AddParameter("reply_to_message_id", replyToMessageId);
            }
            if (replyMarkup != null)
            {
                request.AddParameter("reply_markup", replyMarkup.GetJson());
            }

            return(ExecuteRequest <SendMessageResult>(request) as SendMessageResult);
        }