本文整理汇总了C#中NameValueCollection.AddIf方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.AddIf方法的具体用法?C# NameValueCollection.AddIf怎么用?C# NameValueCollection.AddIf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.AddIf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendAudioAsync
/// <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 or username of the target channel (in the format
/// @channelusername).</param>
/// <param name="audioId">Id of an audio file that is already on the Telegram servers.</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([NotNull] string chatId, [NotNull] string audioId, int duration = 0, string performer = null, string title = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
{
Contracts.EnsureNotNull(chatId, nameof(chatId));
Contracts.EnsureNotNull(chatId, nameof(audioId));
var parameters = new NameValueCollection { { "audio", audioId } };
parameters.AddIf(duration > 0, "duration", duration);
parameters.AddIf(!string.IsNullOrWhiteSpace(performer), "performer", performer);
parameters.AddIf(!string.IsNullOrWhiteSpace(title), "title", title);
return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendAudio", parameters, chatId, replyToMessageId, replyMarkup, disableNotification);
}
示例2: SendDocumentAsync
/// <summary>
/// Sends a general file.
/// </summary>
/// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
/// @channelusername).</param>
/// <param name="documentId">A file id as string to resend a file that is already on the Telegram servers.</param>
/// <param name="caption">The document caption, 0-200 characters.</param>
/// <param name="disableNotification">if set to <c>true</c> [disable notification].</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>
/// <remarks>
/// Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the
/// future.
/// </remarks>
public Task<Message> SendDocumentAsync([NotNull] string chatId, [NotNull] string documentId, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
{
Contracts.EnsureNotNull(chatId, nameof(chatId));
Contracts.EnsureNotNull(documentId, nameof(documentId));
var parameters = new NameValueCollection { { "document", documentId } };
parameters.AddIf(!string.IsNullOrWhiteSpace(caption), "caption", caption);
return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendDocument", parameters, chatId, replyToMessageId, replyMarkup, disableNotification);
}
示例3: SendVenueAsync
/// <summary>
/// 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="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>
/// <exception cref="System.ArgumentNullException">chatId cannot be null -or- title cannot be null -or- address cannot be null.</exception>
public Task<Message> SendVenueAsync([NotNull] string 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.EnsureNotNull(chatId, nameof(chatId));
Contracts.EnsureNotNull(title, nameof(title));
Contracts.EnsureNotNull(address, nameof(address));
var parameters = new NameValueCollection
{
{ "chat_id", chatId },
{ "latitude", latitude.ToString(CultureInfo.InvariantCulture) },
{ "longitude", longitude.ToString(CultureInfo.InvariantCulture) },
{ "title", title },
{ "address", address }
};
parameters.AddIf(!string.IsNullOrWhiteSpace(forsquareId), "foursquare_id", forsquareId);
parameters.AddIf(!disableNotification, "disable_notification", true);
parameters.AddIf(replyToMessageId > 0, "reply_to_message_id", replyToMessageId);
return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendVenue", parameters, replyMarkup: replyMarkup);
}
示例4: AnswerCallbackQueryAsync
/// <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="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, CancellationToken cancellationToken = default(CancellationToken))
{
Contracts.EnsureNotNull(callbackQueryId, nameof(callbackQueryId));
var parameters = new NameValueCollection
{
{ "callback_query_id", callbackQueryId },
{ "show_alert", showAlert.ToString() }
};
parameters.AddIf(!string.IsNullOrWhiteSpace(text), "text", text);
return this.CallTelegramMethodAsync<bool>(cancellationToken, "answerCallbackQuery", parameters);
}
示例5: SendContactAsync
/// <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([NotNull] string chatId, [NotNull] string phoneNumber, [NotNull] string firstName, string lastName = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
{
Contracts.EnsureNotNull(chatId, nameof(chatId));
Contracts.EnsureNotNull(phoneNumber, nameof(phoneNumber));
Contracts.EnsureNotNull(firstName, nameof(firstName));
var parameters = new NameValueCollection
{
{ "chat_id", chatId },
{ "phone_number", phoneNumber },
{ "first_name", firstName }
};
parameters.AddIf(!string.IsNullOrWhiteSpace(lastName), "last_name", lastName);
parameters.AddIf(!disableNotification, "disable_notification", true);
parameters.AddIf(replyToMessageId > 0, "reply_to_message_id", replyToMessageId);
return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendContact", parameters, replyMarkup: replyMarkup);
}
示例6: SendMessageAsync
/// <summary>Sends a text message.</summary>
/// <param name="chatId">
/// Unique identifier for the message recipient 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">
/// 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([NotNull] string 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.EnsureNotNull(chatId, nameof(chatId));
Contracts.EnsureNotNull(text, nameof(text));
var parameters = new NameValueCollection { { "text", text } };
parameters.AddIf(disableWebPagePreview, "disable_web_page_preview", true);
parameters.AddIf(parseMode != ParseMode.Normal, "parse_mode", parseMode.ToString());
return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendMessage", parameters, chatId, replyToMessageId, replyMarkup, disableNotification);
}