/// <summary>Sends answers to an inline query.</summary> /// <param name="inlineQueryId">Unique identifier for answered query.</param> /// <param name="results">Results of the inline query.</param> /// <param name="cacheTime"> /// The maximum amount of time in seconds the result of the inline query may be cached on the Telegram /// server. Default is 300. /// </param> /// <param name="isPersonal"> /// <c>true</c>, to cache the results on the Telegram server only for the user that sent the query. By /// default, results may be returned to any user who sends the same query. /// </param> /// <param name="nextOffset"> /// The offset that a client should send in the next query with the same text to receive more results. /// <c>null</c> or <see cref="string.Empty" /> if there are no more results or if you don't support /// pagination. Offset length can't exceed 64 bytes. /// </param> /// <param name="switchPrivateMessageText"> /// If passed, clients will display a button with specified text that switches the user to a private /// chat with the bot and sends the bot a start message with the parameter /// <paramref name="switchPrivateMessageParameter" />. /// </param> /// <param name="switchPrivateMessageParameter"> /// Parameter for the start message sent to the bot when user presses the switch button. /// <para> /// Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their /// YouTube account to adapt search results accordingly. To do this, it displays a ‘Connect your /// YouTube account’ button above the results, or even before showing any. The user presses the button, /// switches to a private chat with the bot and, in doing so, passes a start parameter that instructs /// the bot to return an oauth link. Once done, the bot can offer a switch_inline button so that the /// user can easily return to the chat where they wanted to use the bot's inline capabilities. /// </para> /// </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> if the /// answer successfully sent; otherwise <c>false</c>. /// </returns> /// <exception cref="System.ArgumentNullException"> /// <paramref name="inlineQueryId" /> is null -or- <paramref name="results" /> is null. /// </exception> /// <exception cref="System.ArgumentException"> /// The nextOffset argument must be less than 64 bytes. /// </exception> /// <exception cref="ArgumentException">No more than 50 results per query are allowed.</exception> public Task <bool> AnswerInlineQueryAsync([NotNull] string inlineQueryId, [NotNull] IEnumerable <InlineQueryResult> results, int cacheTime = 300, bool isPersonal = false, string nextOffset = null, string switchPrivateMessageText = null, string switchPrivateMessageParameter = null, CancellationToken cancellationToken = default(CancellationToken)) { Contracts.EnsureNotNull(inlineQueryId, nameof(inlineQueryId)); Contracts.EnsureNotNull(results, nameof(results)); var inlineQueryResults = results as IList <InlineQueryResult> ?? results.ToList(); if (inlineQueryResults.Count > 50) { throw new ArgumentException("No more than 50 results per query are allowed.", nameof(results)); } var parameters = new MultipartFormDataContent(); if (!string.IsNullOrWhiteSpace(nextOffset)) { Contracts.EnsureByteCount(nextOffset, nameof(nextOffset)); parameters.Add("next_offset", nextOffset); } parameters.Add("inline_query_id", inlineQueryId); parameters.Add("results", inlineQueryResults); parameters.AddIf(cacheTime != 300, "cache_time", cacheTime); parameters.AddIf(isPersonal, "is_peronal", isPersonal); parameters.AddIf(!string.IsNullOrWhiteSpace(switchPrivateMessageText), "switch_pm_text", switchPrivateMessageText); parameters.AddIf(!string.IsNullOrWhiteSpace(switchPrivateMessageParameter), "switch_pm_parameter", switchPrivateMessageParameter); return(this.CallTelegramMethodAsync <bool>(cancellationToken, "answerInlineQuery", parameters)); }