/// <summary> /// Edits captions of the message with the provided identifier sent by the bot or via the bot (for /// inline bots). /// </summary> /// <param name="chatId"> /// Unique identifier for the target chat or username of the target channel (in the format /// @channelusername). /// </param> /// <param name="messageId">Unique identifier of the sent message.</param> /// <param name="caption">New caption of the message.</param> /// <param name="replyMarkup"> /// An <see cref="InlineKeyboardMarkup" /> object for a custom reply keyboard. /// </param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. On success the task results contains the edited /// Message is returned. /// </returns> public Task <Message> EditMessageCaptionAsync([NotNull] string chatId, long messageId, [NotNull] string caption, InlineKeyboardMarkup replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsureNotNull(chatId, nameof(chatId)); Contracts.EnsurePositiveNumber(messageId, nameof(messageId)); return(this.EditMessageCaptionAsync(chatId, messageId, null, caption, replyMarkup, cancellationToken)); }
/// <summary> /// Edits text messages sent by the bot or via the bot (for inline bots). /// </summary> /// <param name="chatId"> /// Unique identifier for the target chat or username of the target channel (in the format /// @channelusername). /// </param> /// <param name="messageId">Unique identifier of the sent message.</param> /// <param name="text">New text of the message</param> /// <param name="parseMode"> /// A value from <see cref="ParseMode" /> enum indicates the way that the Telegram should parse the /// sent message. Send <see cref="ParseMode.Markdown" />, 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="replyMarkup"> /// An <see cref="InlineKeyboardMarkup" /> object for a custom reply keyboard. /// </param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. The task results contains the edited /// <see cref="Message" /> on success. /// </returns> public Task <Message> EditMessageTextAsync([NotNull] string chatId, long messageId, [NotNull] string text, ParseMode parseMode = ParseMode.Normal, bool disableWebPagePreview = false, InlineKeyboardMarkup replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsureNotNull(chatId, nameof(chatId)); Contracts.EnsurePositiveNumber(messageId, nameof(messageId)); return(this.EditMessageTextAsync(chatId, messageId, null, text, parseMode, disableWebPagePreview, replyMarkup, cancellationToken)); }
/// <summary> /// Use this method to get information about a member of a chat. /// </summary> /// <param name="chatId"> /// Unique identifier for the target chat or username of the target supergroup or channel (in the format /// @channelusername) /// </param> /// <param name="userId">Unique identifier of the target user.</param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. The task results contains <c>ChatMember</c> object on /// success. /// </returns> /// <exception cref="System.ArgumentNullException">chatId cannot be null.</exception> /// <exception cref="System.ArgumentException">userId must be a number greater than zero.</exception> public Task <ChatMember> GetChatMemberAsync([NotNull] string chatId, long userId, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsureNotNull(chatId, nameof(chatId)); Contracts.EnsurePositiveNumber(userId, nameof(userId)); var parameters = new NameValueCollection { { "chat_id", chatId }, { "user_id", userId } }; return(this.CallTelegramMethodAsync <ChatMember>(cancellationToken, "getChatMember", parameters)); }
/// <summary>Gets a list of profile pictures for a user.</summary> /// <param name="userId">Unique identifier of the target user.</param> /// <param name="offset"> /// Sequential number of the first photo to be returned. By default, all photos are returned. /// </param> /// <param name="limit"> /// Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100. /// </param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of /// cancellation. /// </param> /// <returns> /// On success, returns the sent <see cref="UserProfilePhotos" />. /// </returns> public Task <UserProfilePhotos> GetUserProfilePhotosAsync(long userId, int offset = -1, int limit = 100, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(userId, nameof(userId)); var builder = new StringBuilder(); builder.AppendFormat("getUserProfilePhotos?user_id={0}&limit={1}", userId, limit); if (offset >= 0) { builder.AppendFormat("offset={0}", offset); } return(this.CallTelegramMethodAsync <UserProfilePhotos>(cancellationToken, builder.ToString())); }
/// <summary> /// Sends answers to callback queries sent from inline keyboards. The answer will be displayed to the /// user as a notification at the top of the chat screen or as an alert. /// </summary> /// <param name="callbackQueryId">Unique identifier for the query to be answered.</param> /// <param name="text"> /// Text of the notification. If not specified, nothing will be shown to the user. /// </param> /// <param name="showAlert"> /// If <c>true</c>, an alert will be shown by the client instead of a notification at the top of the /// chat screen. Defaults to <c>false</c>. /// </param> /// <param name="url"> /// URL that will be opened by the user's client. If you have created a Game and accepted the conditions /// via <c>@Botfather</c>, specify the URL that opens your game – note that this will only work if the query /// comes from a <c>callback_game</c> button. /// <para> /// Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter. /// </para> /// </param> /// <param name="cacheTime"> /// The maximum amount of time in seconds that the result of the callback query may be cached client-side. /// Telegram apps will support caching starting in version 3.14. Defaults to 0. /// </param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. The task results contains <c>true</c> on /// success; otherwise <c>false</c>. /// </returns> /// <exception cref="System.ArgumentNullException"></exception> public Task <bool> AnswerCallbackQueryAsync([NotNull] string callbackQueryId, string text = null, bool showAlert = false, string url = null, int cacheTime = 0, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsureNotNull(callbackQueryId, nameof(callbackQueryId)); Contracts.EnsurePositiveNumber(cacheTime, nameof(cacheTime)); var parameters = new NameValueCollection { { "callback_query_id", callbackQueryId }, { "show_alert", showAlert.ToString() } }; parameters.AddIf(!string.IsNullOrWhiteSpace(text), "text", text); parameters.AddIf(!string.IsNullOrWhiteSpace(url), "url", url); parameters.AddIf(cacheTime != 0, "cache_time", cacheTime); return(this.CallTelegramMethodAsync <bool>(cancellationToken, "answerCallbackQuery", parameters)); }
/// <summary> /// Sends a video file. /// </summary> /// <param name="chatId">Unique identifier for the message recipient.</param> /// <param name="videoId">A file id as string to resend a video that is already on the Telegram servers.</param> /// <param name="duration">Duration of sent video in seconds.</param> /// <param name="caption">Video caption.</param> /// <param name="disableNotification">If set to <c>true</c> 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. An <see cref="Types.IReply" /> object for a custom reply keyboard, /// instructions to hide keyboard or to force a reply from the user.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of /// cancellation.</param> /// <returns> /// On success, returns the sent <see cref="Types.Message" />. /// </returns> /// <remarks> /// Telegram clients support mp4 videos (other formats may be sent as <see cref="Types.Document" />). Bots /// can currently send video files of up to 50 MB in size, this limit may be changed in the future. /// </remarks> public Task <Message> SendVideoAsync(long chatId, [NotNull] string videoId, int duration = 0, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.SendVideoAsync(chatId.ToString(), videoId, duration, caption, disableNotification, replyToMessageId, replyMarkup, cancellationToken)); }
/// <summary> /// Sends <c>.webp</c> sticker. /// </summary> /// <param name="chatId">Unique identifier for the message recipient.</param> /// <param name="stickerStream">A <see cref="Stream" /> to the sticker file to send.</param> /// <param name="fileName">A name for the file to be sent using <paramref name="stickerStream" />.</param> /// <param name="disableNotification">If set to <c>true</c> 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. An <see cref="IReply" /> object for a custom reply keyboard, /// instructions to hide keyboard or to force a reply from the user.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of /// cancellation.</param> /// <returns> /// On success, returns the sent <see cref="Message" />. /// </returns> public Task <Message> SendStickerAsync(long chatId, [NotNull] Stream stickerStream, string fileName, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.SendStickerAsync(chatId.ToString(), stickerStream, fileName, disableNotification, replyToMessageId, replyMarkup, cancellationToken)); }
/// <summary>Send information about a venue.</summary> /// <param name="chatId">Unique identifier for the target chat.</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="forsquareId">Foursquare identifier of the venue.</param> /// <param name="disableNotification"> /// If set to <c>true</c> 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. An <see cref="IReply" /> object for a custom reply keyboard, /// instructions to hide keyboard or to force a reply from the user. /// </param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. The task results contains sent /// <see cref="Message" /> on success. /// </returns> public Task <Message> SendVenueAsync(long chatId, float latitude, float longitude, [NotNull] string title, [NotNull] string address, string forsquareId = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.SendVenueAsync(chatId.ToString(), latitude, longitude, title, address, forsquareId, disableNotification, replyToMessageId, replyMarkup, cancellationToken)); }
/// <summary> /// Sends an audio file. If you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format. /// </summary> /// <param name="chatId">Unique identifier for the message recipient.</param> /// <param name="audioStream">A <see cref="Stream" /> to the audio file to send.</param> /// <param name="fileName">A name for the file to be sent using <paramref name="audioStream" />.</param> /// <param name="duration">Duration of the audio in seconds.</param> /// <param name="performer">The performer of the audio.</param> /// <param name="title">The track name.</param> /// <param name="disableNotification">If set to <c>true</c> 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. An <see cref="IReply" /> object for a custom reply keyboard, /// instructions to hide keyboard or to force a reply from the user.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of /// cancellation.</param> /// <returns> /// On success, returns the sent <see cref="Message" />. /// </returns> public Task <Message> SendAudioAsync(long chatId, [NotNull] Stream audioStream, string fileName, int duration, string performer = null, string title = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.SendAudioAsync(chatId.ToString(), audioStream, fileName, duration, performer, title, disableNotification, replyToMessageId, replyMarkup, cancellationToken)); }
/// <summary> /// Edit only the reply markup of messages sent by the bot or via the bot (for inline bots). /// </summary> /// <param name="chatId"> /// Unique identifier for the target chat or username of the target channel (in the format /// @channelusername). /// </param> /// <param name="messageId">Unique identifier of the sent message.</param> /// <param name="replyMarkup"> /// An <see cref="InlineKeyboardMarkup" /> object for a custom reply keyboard. /// </param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. On success the task results contains the edited /// Message is returned. /// </returns> public Task <Message> EditMessageReplyMarkupAsync(long chatId, long messageId, InlineKeyboardMarkup replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.EditMessageReplyMarkupAsync(chatId.ToString(), messageId, replyMarkup, cancellationToken)); }
/// <summary>Send phone contacts.</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"> /// If set to <c>true</c> 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. An <see cref="IReply" /> object for a custom reply keyboard, /// instructions to hide keyboard or to force a reply from the user. /// </param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. The task results contains sent /// <see cref="Message" /> on success. /// </returns> /// <exception cref="System.ArgumentNullException"> /// chatId cannot be null -or- phoneNumber cannot be null -or- firstName cannot be null. /// </exception> public Task <Message> SendContactAsync(long chatId, [NotNull] string phoneNumber, [NotNull] string firstName, string lastName = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.SendContactAsync(chatId.ToString(), phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup, cancellationToken)); }
/// <summary>Forwards message of any kind.</summary> /// <param name="chatId">Unique identifier for the message recipient.</param> /// <param name="fromChatId"> /// Unique identifier for the chat where the original message was sent. /// </param> /// <param name="messageId">Unique message identifier</param> /// <param name="disableNotification">If set to <c>true</c> sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of /// cancellation. /// </param> /// <returns> /// On success, returns the sent <see cref="Message" />. /// </returns> public Task <Message> ForwardMessageAsync(long chatId, long fromChatId, long messageId, bool disableNotification = false, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.ForwardMessageAsync(chatId.ToString(), fromChatId.ToString(), messageId, disableNotification, cancellationToken)); }
/// <summary> /// Sends a text message. /// </summary> /// <param name="chatId">Unique identifier for the message recipient.</param> /// <param name="text">Text of the message to be sent.</param> /// <param name="parseMode">Indicates the way that the Telegram should parse the sent message.</param> /// <param name="disableWebPagePreview">if set to <c>true</c> disables link previews for links in this message.</param> /// <param name="disableNotification">If set to <c>true</c> 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. An <see cref="IReply" /> object for a custom reply keyboard, /// instructions to hide keyboard or to force a reply from the user.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of /// cancellation.</param> /// <returns> /// On success, returns the sent <see cref="Message" />. /// </returns> public Task <Message> SendMessageAsync(long chatId, [NotNull] string text, ParseMode parseMode = ParseMode.Normal, bool disableWebPagePreview = false, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.SendMessageAsync(chatId.ToString(), text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup, cancellationToken)); }
/// <summary> /// Sends a chat action. Use this method when you need to tell the user that something is happening on /// the bot's side. /// </summary> /// <param name="chatId">Unique identifier for the message recipient.</param> /// <param name="action">Type of action to broadcast.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of /// cancellation. /// </param> /// <returns> /// On success, returns the sent <see cref="Message" />. /// </returns> /// <remarks> /// Use this method when you need to tell the user that something is happening on the bot's side. The /// status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear /// its typing status). /// <example> /// The <c>ImageBot</c> needs some time to process a request and upload the image. Instead of sending a /// text message along the lines of "Retrieving image, please wait…", the bot may use /// <see cref="SendChatActionAsync(long,ChatAction,CancellationToken)" /> /// with action = upload_photo. The user will see a "sending photo" status for the bot. /// </example> /// </remarks> public Task <bool> SendChatActionAsync(long chatId, ChatAction action, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.SendChatActionAsync(chatId.ToString(), action, cancellationToken)); }
/// <summary> /// Unbans a previously kicked user in a supergroup. The user will not return to the group /// automatically, but will be able to join via link, etc. The bot must be an administrator in the /// group for this to work. /// </summary> /// <param name="chatId">Unique identifier for the target group.</param> /// <param name="userId">Unique identifier of the target user.</param> /// <param name="cancellationToken"> /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to /// complete. /// </param> /// <returns> /// A task that represents the asynchronous operation. The task results contains <c>true</c> on /// success. /// </returns> /// <remarks> /// Note: This will method only work if the ‘All Members Are Admins’ setting is off in the target /// group. Otherwise members may only be removed by the group's creator or by the member that added /// them. /// </remarks> /// <exception cref="System.ArgumentNullException">chatId cannot be null.</exception> /// <exception cref="System.ArgumentException">userId must be a number greater than zero.</exception> public Task <bool> UnbanChatMemberAsync(long chatId, long userId, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsurePositiveNumber(chatId, nameof(chatId)); return(this.KickChatMemberAsync(chatId.ToString(), userId, cancellationToken)); }