Exemple #1
0
        public static IReply <IEnumerable <T> > WithValues <T>(this IReply <IEnumerable <T> > reply, params T[] values)
        {
            using (var actual = reply.ParsedValue.GetEnumerator())
            {
                var expected = values.GetEnumerator();

                for (var i = 0; ; ++i)
                {
                    var aMoved = actual.MoveNext();
                    var eMoved = expected.MoveNext();

                    if (aMoved != eMoved)
                    {
                        throw new AssertionException("parsed and expected value collections have different sizes");
                    }

                    if (!aMoved)
                    {
                        break;
                    }

                    if (!Equals(expected.Current, actual.Current))
                    {
                        throw new AssertionException($"parsed value [{i}]: {expected}", $"parsed value [{i}]: {reply.ParsedValue}");
                    }
                }
            }


            return(reply);
        }
Exemple #2
0
        /// <summary>
        /// Get request
        /// </summary>
        /// <typeparam name="TReply"></typeparam>
        /// <returns></returns>
        protected async virtual Task <bool> Execute <TReply>()
            where TReply : IReply
        {
            string json = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                request.AutomaticDecompression = DecompressionMethods.GZip;
                request.Headers.Add(Utils.AuthorisationKey, Utils.ApiKey);

                using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
                    //using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            json       = reader.ReadToEnd();
                            Reply      = JsonConvert.DeserializeObject <TReply>(json);
                            Reply.Json = json;
                            return(Reply.Validate());
                        }
            }
            catch (Exception ex)
            {
                Reply = new BaseReply(false, ex.Message)
                {
                    Json = json
                };
            }
            return(Reply.Success);
        }
Exemple #3
0
        /// <summary>
        /// Получает и закрывается
        /// </summary>
        /// <param name="reply"></param>
        /// <returns></returns>
        public virtual bool Handle(IReply reply)
        {
            this.TotalHandledReplyCount++;
            this.CurrentReply = reply;

            return(true);
        }
Exemple #4
0
        public void SendReply(IReply reply)
        {
            StringBuilder sb = new StringBuilder();

            // Server
            sb.Append(IRCServer.PREFIX);
            sb.Append(Server.ServerHost);
            sb.Append(' ');

            // Reply code
            sb.AppendFormat(@"{0:000}", reply.ReplyCode);
            sb.Append(' ');

            // Receiver
            if (Session == null)
            {
                sb.Append('-');
            }
            else
            {
                sb.Append(Session.User.GetIRCName());
            }
            sb.Append(' ');

            // Contents
            sb.Append(reply.GetLine());
            sb.Append(IReply.CRLF);

            Send(sb);
        }
        /// <summary>
        /// Sends <c>.webp</c> sticker.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="stickerId">A file id as string to resend a sticker that is already on the Telegram servers.</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([NotNull] string chatId, [NotNull] string stickerId, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(stickerId, nameof(stickerId));

            var parameters = new NameValueCollection { { "sticker", stickerId } };
            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendSticker", parameters, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
Exemple #6
0
        public static void DeleteReply(int id)
        {
            ReplyInfo reply = GetReply(id);
            IReply    dal   = Factory <IReply> .Create("Reply");

            dal.Delete(reply);
            Admin.UpdateForumCounts();
        }
Exemple #7
0
        public static int AddReply(ReplyInfo reply)
        {
            IReply dal = Factory <IReply> .Create("Reply");

            int replyid = dal.Add(reply);

            return(replyid);
        }
Exemple #8
0
        public async Task <bool> HandleAsync(IReply <TOriginal, TSubject> e)
        {
            if (e.Original.Equals(Original))
            {
                return(await Handler(e.Subject));
            }

            return(false);
        }
Exemple #9
0
        public static IReply <T> WithValue <T>(this IReply <T> reply, T expected)
        {
            if (!Equals(expected, reply.ParsedValue))
            {
                throw new AssertionException($"parsed value: {expected}", $"parsed value: {reply.ParsedValue}");
            }

            return(reply);
        }
Exemple #10
0
 public ReplyController(IReply replyContext, IMailService mailService, ILogger <ReplyController> logger,
                        IUser user, IMapper mapper, IHubContext <CommentHub> hub, IComment commemtContext)
 {
     _commemtContext = commemtContext;
     _hub            = hub;
     _replyContext   = replyContext;
     _mailService    = mailService;
     _logger         = logger;
     _mapper         = mapper;
 }
        /// <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);
        }
Exemple #12
0
        public static void MoveReplies(int newtopicid, List <int> replyIDs)
        {
            ITopic topicdal = Factory <ITopic> .Create("Topic");

            TopicInfo topic = topicdal.GetById(newtopicid);

            IReply dal = Factory <IReply> .Create("Reply");

            dal.MoveReplies(topic, replyIDs);
            Admin.UpdateForumCounts();
        }
Exemple #13
0
 public static void Case <TToken, T>(
     this IReply <TToken, T> reply,
     Action <ITokenStream <TToken>, String> failure,
     Action <ITokenStream <TToken>, T> success)
 {
     reply.Case(
         failure: (stream, errorMessage) =>
         { failure(stream, errorMessage); return(Unit.Instance); },
         success: (stream, value) =>
         { success(stream, value); return(Unit.Instance); });
 }
        /// <summary>
        /// Sends a point on the map.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient 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">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> SendLocationAsync([NotNull] string chatId, double latitude, double longitude, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));

            var parameters = new NameValueCollection
                                 {
                                     { "latitude", latitude.ToString(CultureInfo.InvariantCulture) },
                                     { "longitude", longitude.ToString(CultureInfo.InvariantCulture) }
                                 };

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendLocation", parameters, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
Exemple #15
0
        /// <summary>
        /// Sends an audio file to be displayed as a playable voice message on Telegram clients.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="voice">Id of an audio file that is already on the Telegram servers to resend it.</param>
        /// <param name="duration">Duration of sent audio in seconds.</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>
        /// <remarks>
        /// For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent
        /// as <see cref="Audio" /> or <see cref="Document" />). Bots can currently send audio files of up to
        /// 50 MB in size, this limit may be changed in the future.
        /// </remarks>
        public Task<Message> SendVoiceAsync([NotNull] string chatId, [NotNull] string voice, int duration = 0, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(voice, nameof(voice));

            var parameters = new NameValueCollection { { "voice", voice } };

            if( duration > 0 )
                parameters.Add("duration", duration);

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendVoice", parameters, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
Exemple #16
0
        /// <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);
        }
Exemple #17
0
 public override bool Handle(IReply reply)
 {
     this.TotalHandledReplyCount++;
     if (Owner.Instance.EvalBoolean(Expression))
     {
         return(reply.Move(this, primTrue));
     }
     else
     {
         return(reply.Move(this, primFalse));
     }
 }
Exemple #18
0
 public override bool Handle(IReply reply)
 {
     CurrentReplyCount++;
     if (reply.PrevoisPrimitive is Blocker)
     {
         TotalNotHandledReplyCount++;
     }
     else
     {
         TotalHandledReplyCount++;
     }
     return(true);
 }
Exemple #19
0
 private IStatusCodeResult Map <T>(IReply <T> reply, HttpStatusCode defaultSuccess = HttpStatusCode.OK)
 {
     _logger.LogInformation(reply.ToStringLog());
     if (reply.IsSuccess)
     {
         return(new StatusCodeResult <T>(defaultSuccess, reply.Value));
     }
     return(reply.ErrorCode switch
     {
         NOT_FOUND => NotFound(reply.Value),
         INVALID_ID => BadRequest(reply.Value),
         _ => UnprocessableEntity(reply.Value)
     });
Exemple #20
0
 private IReplyMarkup GetKeyboard(IReply reply)
 {
     if (reply.GetType() == typeof(ReplyOnGetPlants))
     {
         return(keyboardController.GetUserPlantsKeyboard(((ReplyOnGetPlants)reply).PlantsName.ToArray()));
     }
     if (reply.GetType() == typeof(ReplyOnGetPlantsToDelete))
     {
         return(keyboardController.GetUserPlantsKeyboard(((ReplyOnGetPlantsToDelete)reply).PlantsName.ToArray()));
     }
     if (reply.GetType() == typeof(ReplyOnWantedAddPlant) || reply.GetType() == typeof(ReplyOnSetPlantName))
     {
         return(keyboardController.GetCancelKeyboard());
     }
     return(keyboardController.GetMainMenuKeyboard());
 }
Exemple #21
0
        public static void UpdateReply(int replyid, string message, MemberInfo author, bool isAdministrator, bool showsig)
        {
            ReplyInfo reply = GetReply(replyid);

            reply.Message = message;
            if (!isAdministrator)
            {
                reply.LastEditDate   = DateTime.UtcNow;
                reply.LastEditedById = author.Id;
            }
            reply.UseSignatures = showsig;

            IReply dal = Factory <IReply> .Create("Reply");

            dal.Update(reply);
        }
Exemple #22
0
 /// <summary>
 ///  Subscribes for an initial snapshot and then incremental update.
 /// </summary>
 /// <param name="fiber">the target executor to receive the message</param>
 /// <param name="receive"></param>
 public void PrimedSubscribe(IFiber fiber, Action <T> receive)
 {
     using (IReply <T> reply = this._requestChannel.SendRequest(new object()))
     {
         if (reply == null)
         {
             throw new ArgumentException(typeof(T).Name + " synchronous request has no reply subscriber.");
         }
         T result;
         if (!reply.Receive(this._timeoutInMs, out result))
         {
             throw new ArgumentException(typeof(T).Name + " synchronous request timed out in " + this._timeoutInMs);
         }
         receive(result);
         this._updatesChannel.Subscribe(fiber, receive);
     }
 }
Exemple #23
0
        /// <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);
        }
Exemple #24
0
        /// <summary>
        /// Update the parent meme to reflect the new state of the supplied meme
        /// Recalculate and update the reply trend score of the supplied meme inside the reply list of the parent meme (identified by ResponseToId)
        /// </summary>
        /// <param name="replyMeme"></param>
        /// <returns></returns>
        public void UpdateReplyToMeme(IMeme replyMeme)
        {
            if (replyMeme != null && replyMeme.ResponseToId != null)
            {
                IMeme parentMeme = repository.GetMeme(replyMeme.ResponseToId);
                if (parentMeme.ReplyIds == null)
                {
                    // This meme is not a reply within the parent meme
                    return;
                }

                IReply reply = parentMeme.ReplyIds.FirstOrDefault(x => x.Id == replyMeme.Id);
                if (reply != null)
                {
                    // Save the parent meme to which the reply meme is a response to (with the updated reply trend scrore)
                    Save(parentMeme);
                }
            }
        }
Exemple #25
0
        public void BuildMessageToUser(IReply reply)
        {
            if (reply is ReplyOnGetPlantPhoto replyOnGetPlantPhoto)
            {
                if (replyOnGetPlantPhoto.IsExist)
                {
                    SendAnswerWithPhoto(replyOnGetPlantPhoto);
                    return;
                }

                var answerText = "У этого растения пока нет фотографий.\n\n" +
                                 "Чтобы добавить фотографию своего растения, просто отправь её мне. " +
                                 "Не забудь добавить в описании имя растения, иначе я тебя не пойму :(";
                var keyboard = keyboardController.GetMainMenuKeyboard();
                SendAnswer(reply.UserId, answerText, keyboard);
                return;
            }

            SendAnswer(reply.UserId, GetTextAnswer(reply), GetKeyboard(reply));
        }
Exemple #26
0
        /// <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);
        }
Exemple #27
0
        /// <summary>
        /// Post request
        /// </summary>
        /// <typeparam name="TReply"></typeparam>
        /// <typeparam name="TRequest"></typeparam>
        /// <param name="args"></param>
        /// <returns></returns>
        protected virtual bool Execute <TReply, TRequest>(TRequest args)
            where TReply : IReply
            where TRequest : IRequest
        {
            string json = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                request.ContentType = "application/json";
                request.Method      = "POST";
                request.Headers.Add(Utils.AuthorisationKey, Utils.ApiKey);

                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                {
                    json = JsonConvert.SerializeObject(args);
                    writer.Write(json);
                    writer.Flush();
                    writer.Close();
                }

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            json       = reader.ReadToEnd();
                            Reply      = JsonConvert.DeserializeObject <TReply>(json);
                            Reply.Json = json;
                            return(Reply.Validate());
                        }
            }
            catch (Exception ex)
            {
                Reply = new BaseReply(false, ex.Message)
                {
                    Json = json
                };
            }
            return(Reply.Success);
        }
Exemple #28
0
        /// <summary>
        /// Sends a photo.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="photoStream">A <see cref="Stream" /> to the photo to upload.</param>
        /// <param name="fileName">A name for the file to be sent using <paramref name="photoStream" />.</param>
        /// <param name="caption">Photo caption (may also be used when resending photos by file id).</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> SendPhotoAsync([NotNull] string chatId, [NotNull] Stream photoStream, string fileName, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(photoStream, nameof(photoStream));

            // ReSharper disable once UseObjectOrCollectionInitializer
            var content = new MultipartFormDataContent();
            content.Add(new StreamContent(photoStream), "photo", fileName);

            if( !string.IsNullOrWhiteSpace(caption) )
                content.Add("caption", caption);

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendPhoto", content, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
 /// <summary>
 /// Sends a general file.
 /// </summary>
 /// <param name="chatId">Unique identifier for the message recipient.</param>
 /// <param name="documentStream">A <see cref="Stream" /> to the document file to send.</param>
 /// <param name="fileName">A name for the file to be sent using <paramref name="documentStream" />.</param>
 /// <param name="caption">Document caption, 0-200 characters.</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>
 /// <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(long chatId, [NotNull] Stream documentStream, string fileName, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return this.SendDocumentAsync(chatId.ToString(), documentStream, fileName, caption, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
Exemple #30
0
        /// <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.EnsureNotZero(chatId, nameof(chatId));

            return this.SendContactAsync(chatId.ToString(), phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
        }
Exemple #31
0
        /// <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);
        }
Exemple #32
0
 /// <summary>
 /// Sends a text message and requests to hide the current custom keyboard by default. Optionally if the
 /// message is a reply, ID of the original message will be sent.
 /// </summary>
 /// <param name="message">The original received message.</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="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. Defaults to hide the current
 /// custom keyboard.</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] Message message, [NotNull] string text, ParseMode parseMode = ParseMode.Normal, bool disableWebPagePreview = false, bool disableNotification = false, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     Contracts.EnsureNotNull(message, nameof(message));
     return(this.SendMessageAsync(message.Chat.Id.ToString(), text, parseMode, disableWebPagePreview, disableNotification, message.ReplyToMessage?.Id ?? 0, replyMarkup, cancellationToken));
 }
Exemple #33
0
 /// <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.EnsureNotZero(chatId, nameof(chatId));
     return(this.SendMessageAsync(chatId.ToString(), text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup, cancellationToken));
 }
Exemple #34
0
        /// <summary>
        /// Sends <c>.webp</c> sticker.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</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([NotNull] string chatId, [NotNull] Stream stickerStream, string fileName, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(stickerStream, nameof(stickerStream));

            // ReSharper disable once UseObjectOrCollectionInitializer
            var content = new MultipartFormDataContent();
            content.Add("sticker", stickerStream, fileName);

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendSticker", content, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
Exemple #35
0
 /// <summary>
 /// Sends <c>.webp</c> sticker.
 /// </summary>
 /// <param name="chatId">Unique identifier for the message recipient.</param>
 /// <param name="stickerId">A file id as string to resend a sticker that is already on the Telegram servers.</param>
 /// <param name="replyToMessageId">If the message is a reply, ID of the original 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="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] string stickerId, long replyToMessageId = 0, bool disableNotification = false, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     Contracts.EnsureNotZero(chatId, nameof(chatId));
     return this.SendStickerAsync(chatId.ToString(), stickerId, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
 /// <summary>
 /// Sends a point on the map.
 /// </summary>
 /// <param name="chatId">Unique identifier for the message recipient.</param>
 /// <param name="latitude">Latitude of location</param>
 /// <param name="longitude">Longitude of location</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> SendLocationAsync(long chatId, double latitude, double longitude, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     Contracts.EnsureNotZero(chatId, nameof(chatId));
     return this.SendLocationAsync(chatId.ToString(), latitude, longitude, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
Exemple #37
0
 /// <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.EnsureNotZero(chatId, nameof(chatId));
     return this.SendMessageAsync(chatId.ToString(), text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
Exemple #38
0
        /// <summary>
        /// Sends a video file.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="filePath">Fully qualified path to the video file to send.</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="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> SendVideoFromFileAsync([NotNull] string chatId, [NotNull] string filePath, int duration = 0, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(filePath, nameof(filePath));
            Contracts.EnsureFileExists(filePath);

            var fileName = Path.GetFileName(filePath);
            var fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            return this.SendVideoAsync(chatId, fileStream, fileName, duration, caption, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
        }
Exemple #39
0
 /// <summary>
 /// Sends a photo.
 /// </summary>
 /// <param name="chatId">Unique identifier for the message recipient.</param>
 /// <param name="photoStream">A <see cref="Stream" /> to the photo to upload.</param>
 /// <param name="fileName">A name for the file to be sent using <paramref name="photoStream" />.</param>
 /// <param name="caption">Photo caption (may also be used when resending photos by file id).</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> SendPhotoAsync(long chatId, [NotNull] Stream photoStream, string fileName, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     Contracts.EnsureNotZero(chatId, nameof(chatId));
     return this.SendPhotoAsync(chatId.ToString(), photoStream, fileName, caption, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
Exemple #40
0
 /// <summary>
 /// Sends an audio file to be displayed as a playable voice message on Telegram clients.
 /// </summary>
 /// <param name="chatId">Unique identifier for the message recipient.</param>
 /// <param name="filePath">Fully qualified path to the audio file.</param>
 /// <param name="caption"></param>
 /// <param name="duration">Duration of sent 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> SendAudioFromFileAsync(long chatId, [NotNull] string filePath, string caption, int duration = 0, string performer = null, string title = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(this.SendAudioFromFileAsync(chatId.ToString(), filePath, caption, duration, performer, title, disableNotification, replyToMessageId, replyMarkup, cancellationToken));
 }
Exemple #41
0
 /// <summary>
 /// Instantiate this classed (and its variables) based on the values of another IReply 
 /// </summary>
 /// <param name="reply"></param>
 public TableReply(IReply reply)
     : base(reply)
 {
 }
Exemple #42
0
        /// <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="caption">Audio caption, 0-200 characters</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, string caption = null, 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);
            parameters.AddIf(!string.IsNullOrWhiteSpace(caption), "caption", caption.Length > 200
                                                                                 ? caption.Substring(0, 200)
                                                                                 : caption);

            return(this.CallTelegramMethodAsync <Message>(cancellationToken, "sendAudio", parameters, chatId, replyToMessageId, replyMarkup, disableNotification));
        }
Exemple #43
0
        /// <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));
        }
Exemple #44
0
 /// <summary>
 /// Sends a point on the map.
 /// </summary>
 /// <param name="chatId">Unique identifier for the message recipient.</param>
 /// <param name="latitude">Latitude of location</param>
 /// <param name="longitude">Longitude of location</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> SendLocationAsync(long chatId, double latitude, double longitude, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     Contracts.EnsureNotZero(chatId, nameof(chatId));
     return(this.SendLocationAsync(chatId.ToString(), latitude, longitude, disableNotification, replyToMessageId, replyMarkup, cancellationToken));
 }
Exemple #45
0
        /// <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="audioStream">A <see cref="Stream" /> to the audio file to send.</param>
        /// <param name="caption">Audio caption, 0-200 characters</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([NotNull] string chatId, [NotNull] Stream audioStream, string caption, string fileName, int duration, 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(audioStream, nameof(audioStream));

            // ReSharper disable once UseObjectOrCollectionInitializer
            var content = new MultipartFormDataContent();

            content.Add("audio", audioStream, fileName);
            content.AddIf(duration > 0, "duration", duration);
            content.AddIf(!string.IsNullOrWhiteSpace(performer), "performer", performer);
            content.AddIf(!string.IsNullOrWhiteSpace(title), "title", title);
            content.AddIf(!string.IsNullOrWhiteSpace(caption), "caption", caption.Length > 200
                                                                               ? caption.Substring(0, 200)
                                                                               : caption);

            return(this.CallTelegramMethodAsync <Message>(cancellationToken, "sendAudio", content, chatId, replyToMessageId, replyMarkup, disableNotification));
        }
Exemple #46
0
 /// <summary>
 /// Sends a text message and requests to hide the current custom keyboard by default. Optionally if the
 /// message is a reply, ID of the original message will be sent.
 /// </summary>
 /// <param name="message">The original received message.</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="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. Defaults to hide the current
 /// custom keyboard.</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] Message message, [NotNull] string text, ParseMode parseMode = ParseMode.Normal, bool disableWebPagePreview = false, bool disableNotification = false, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     Contracts.EnsureNotNull(message, nameof(message));
     return this.SendMessageAsync(message.Chat.Id.ToString(), text, parseMode, disableWebPagePreview, disableNotification, message.ReplyToMessage?.Id ?? 0, replyMarkup, cancellationToken);
 }
Exemple #47
0
        /// <summary>
        /// Sends an audio file to be displayed as a playable voice message on Telegram clients.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="filePath">Fully qualified path to the audio file.</param>
        /// <param name="caption"></param>
        /// <param name="duration">Duration of sent 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> SendAudioFromFileAsync([NotNull] string chatId, [NotNull] string filePath, string caption = null, 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(filePath, nameof(filePath));
            Contracts.EnsureFileExists(filePath);

            var fileName   = Path.GetFileName(filePath);
            var fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            return(this.SendAudioAsync(chatId, fileStream, fileName, caption, duration, performer, title, disableNotification, replyToMessageId, replyMarkup, cancellationToken));
        }
Exemple #48
0
        /// <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.EnsureNotZero(chatId, nameof(chatId));

            return this.SendVenueAsync(chatId.ToString(), latitude, longitude, title, address, forsquareId, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
        }
Exemple #49
0
 /// <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="caption">Audio caption, 0-200 characters</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 caption, string fileName, int duration, string performer = null, string title = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     Contracts.EnsureNotZero(chatId, nameof(chatId));
     return(this.SendAudioAsync(chatId.ToString(), audioStream, caption, fileName, duration, performer, title, disableNotification, replyToMessageId, replyMarkup, cancellationToken));
 }
Exemple #50
0
 /// <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.EnsureNotZero(chatId, nameof(chatId));
     return this.SendAudioAsync(chatId.ToString(), audioStream, fileName, duration, performer, title, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
Exemple #51
0
        /// <summary>
        /// Sends a point on the map.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient 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">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> SendLocationAsync([NotNull] string chatId, double latitude, double longitude, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));

            var parameters = new NameValueCollection
            {
                { "latitude", latitude.ToString(CultureInfo.InvariantCulture) },
                { "longitude", longitude.ToString(CultureInfo.InvariantCulture) }
            };

            return(this.CallTelegramMethodAsync <Message>(cancellationToken, "sendLocation", parameters, chatId, replyToMessageId, replyMarkup, disableNotification));
        }
Exemple #52
0
 /// <summary>
 /// Sends an audio file to be displayed as a playable voice message on Telegram clients.
 /// </summary>
 /// <param name="chatId">Unique identifier for the message recipient.</param>
 /// <param name="filePath">Fully qualified path to the audio file.</param>
 /// <param name="duration">Duration of sent 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> SendAudioFromFileAsync(long chatId, [NotNull] string filePath, int duration = 0, string performer = null, string title = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return this.SendAudioFromFileAsync(chatId.ToString(), filePath, duration, performer, title, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
Exemple #53
0
        /// <summary>
        /// Sends a video file.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="videoStream">A <see cref="Stream" /> to the video file to send.</param>
        /// <param name="fileName">A name for the file to be sent using <paramref name="videoStream" />.</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="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>
        /// Telegram clients support mp4 videos (other formats may be sent as <see cref="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([NotNull] string chatId, [NotNull] Stream videoStream, string fileName, int duration = 0, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(videoStream, nameof(videoStream));

            var content = new MultipartFormDataContent { { new StreamContent(videoStream), "video", fileName } };
            if( duration > 0 )
                content.Add("duration", duration);

            if( caption != null )
                content.Add("caption", caption);

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendVideo", content, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
Exemple #54
0
        /// <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="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([NotNull] string 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.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(audioStream, nameof(audioStream));

            // ReSharper disable once UseObjectOrCollectionInitializer
            var content = new MultipartFormDataContent();
            content.Add("audio", audioStream, fileName);
            content.AddIf(duration > 0, "duration", duration);
            content.AddIf(!string.IsNullOrWhiteSpace(performer), "performer", performer);
            content.AddIf(!string.IsNullOrWhiteSpace(title), "title", title);

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendAudio", content, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
Exemple #55
0
 /// <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.EnsureNotZero(chatId, nameof(chatId));
     return this.SendVideoAsync(chatId.ToString(), videoId, duration, caption, disableNotification, replyToMessageId, replyMarkup, cancellationToken);
 }
Exemple #56
0
 /// <summary>
 /// Instantiate this classed (and its variables) based on the values of another IReply 
 /// </summary>
 /// <param name="reply"></param>
 public MessageReply(IReply reply)
 {
     StructuredResponse = reply.StructuredResponse;
     _Name = reply.Name;
     _Value = reply.Value;
     _Type = reply.ElementType;
     _ErrCode = reply.ErrCode;
     _ErrMsg = reply.ErrMsg;
     //_Contacts = reply.Contacts;
 }