예제 #1
0
        public async Task <IUpdates> SendUploadedDocument(
            IInputPeer peer,
            IInputFile file,
            string caption,
            string mimeType,
            TVector <IDocumentAttribute> attributes,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            return(await SenderService.SendRequestAsync(
                       new RequestSendMedia
            {
                RandomId = TlHelpers.GenerateRandomLong(),
                Background = false,
                ClearDraft = false,
                Media = new TInputMediaUploadedDocument
                {
                    File = file,
                    Caption = caption,
                    MimeType = mimeType,
                    Attributes = attributes
                },
                Peer = peer
            },
                       cancellationToken).ConfigureAwait(false));
        }
예제 #2
0
        /// <summary>Returns full chat info according to its ID.</summary>
        /// <param name="chatId">Chat's identifier</param>
        /// <returns>Object contains extended info on chat with auxiliary data.</returns>
        public async Task <IChatFull> GetFullChatAsync(int chatId, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var request = new RequestGetFullChat {
                ChatId = chatId
            };

            return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
예제 #3
0
        public async Task <IContacts> GetContactsAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var req = new RequestGetContacts {
                Hash = 0
            };

            return(await SenderService.SendRequestAsync(req, cancellationToken).ConfigureAwait(false));
        }
예제 #4
0
        /// <summary>Returns chat basic info on their IDs.</summary>
        /// <param name="ids">Identifiers of chats</param>
        /// <returns>Object contains list of chats with auxiliary data.</returns>
        public async Task <IChats> GetChatsAsync(TVector <int> ids, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var request = new RequestGetChats {
                Id = ids
            };

            return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
예제 #5
0
        /// <summary>Confirms receipt of messages by a client, cancels PUSH-notification sending.</summary>
        /// <param name="maxId">Maximum message ID available in a client.</param>
        /// <returns>The method returns the list of message IDs, for which PUSH-notifications were cancelled.</returns>
        /// TODO: interface?
        public async Task <TVector <TReceivedNotifyMessage> > ReceivedMessagesAsync(int maxId, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var receivedMessages = new RequestReceivedMessages
            {
                MaxId = maxId
            };

            return(await SenderService.SendRequestAsync(receivedMessages, cancellationToken).ConfigureAwait(false));
        }
예제 #6
0
        /// <summary>Notifies the sender about the recipient having listened a voice message or watched a video.</summary>
        /// <param name="ids">Identifiers of messages</param>
        /// <returns>Returns a <see cref="IAffectedMessages" /> object containing a affected messages</returns>
        public async Task <IAffectedMessages> ReadMessageContentsAsync(TVector <int> ids, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var readMessageContents = new RequestReadMessageContents
            {
                Id = ids
            };

            return(await SenderService.SendRequestAsync(readMessageContents, cancellationToken).ConfigureAwait(false));
        }
예제 #7
0
        /// <summary>Marks message history as read.</summary>
        /// <param name="peer">User or group to receive the message</param>
        /// <param name="maxId">
        ///     If a positive value is passed, only messages with identifiers less or equal than the given one will
        ///     be read
        /// </param>
        /// <returns>Returns a <see cref="IAffectedMessages" /> object containing a affected messages</returns>
        public async Task <IAffectedMessages> ReadHistoryAsync(IInputPeer peer, int maxId, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var readHistory = new RequestReadHistory
            {
                Peer  = peer,
                MaxId = maxId
            };

            return(await SenderService.SendRequestAsync(readHistory, cancellationToken).ConfigureAwait(false));
        }
예제 #8
0
        /// <summary>Deletes a user from a chat and sends a service message on it.</summary>
        /// <param name="chatId">Chat's identifier</param>
        /// <param name="user">User ID to be deleted</param>
        /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during the action.</returns>
        public async Task <IUpdates> DeleteChatUser(int chatId, IInputUser user, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var request = new RequestDeleteChatUser
            {
                ChatId = chatId,
                UserId = user
            };

            return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
예제 #9
0
        /// <summary>Chanages chat name and sends a service message on it.</summary>
        /// <param name="chatId">Chat's identifier</param>
        /// <param name="title">New chat name, different from the old one</param>
        /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during an action.</returns>
        public async Task <IUpdates> EditChatTitle(int chatId, string title, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var request = new RequestEditChatTitle
            {
                ChatId = chatId,
                Title  = title
            };

            return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
예제 #10
0
        /// <summary>Changes chat photo and sends a service message on it.</summary>
        /// <param name="chatId">Chat's identifier</param>
        /// <param name="photo">Photo to be set</param>
        /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during an action.</returns>
        public async Task <IUpdates> EditChatPhoto(int chatId, IInputChatPhoto photo, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var request = new RequestEditChatPhoto
            {
                ChatId = chatId,
                Photo  = photo
            };

            return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
예제 #11
0
        /// <summary>Deletes messages by their IDs.</summary>
        /// <param name="ids">Identifiers of messages</param>
        /// <param name="revoke">Delete messages for everyone</param>
        /// <returns>Returns a <see cref="IAffectedMessages" /> object containing a affected messages</returns>
        public async Task <IAffectedMessages> DeleteMessagesAsync(TVector <int> ids, bool revoke, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var deleteMessages = new RequestDeleteMessages
            {
                Id     = ids,
                Revoke = revoke
            };

            return(await SenderService.SendRequestAsync(deleteMessages, cancellationToken).ConfigureAwait(false));
        }
예제 #12
0
        /// <summary>Serch user or chat.</summary>
        /// <param name="q">User or chat name</param>
        /// <param name="limit">Max result count</param>
        /// <param name="cancellationToken">A cancellation token</param>
        /// <returns></returns>
        public async Task <IFound> SearchUserAsync(string q, int limit = 10, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var r = new RequestSearch
            {
                Q     = q,
                Limit = limit
            };

            return(await SenderService.SendRequestAsync(r, cancellationToken).ConfigureAwait(false));
        }
예제 #13
0
        /// <summary>Creates a new chat.</summary>
        /// <param name="title">Chat name</param>
        /// <param name="users">List of user IDs to be invited</param>
        /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during an action.</returns>
        public async Task <IUpdates> CreateChatAsync(string title, TVector <IInputUser> users, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var request = new RequestCreateChat
            {
                Title = title,
                Users = users
            };

            return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
예제 #14
0
        public async Task <IDialogs> GetUserDialogsAsync(int limit = 100, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var getDialogs = new RequestGetDialogs
            {
                OffsetDate = 0,
                OffsetPeer = new TInputPeerSelf(),
                Limit      = limit
            };

            return(await SenderService.SendRequestAsync(getDialogs, cancellationToken).ConfigureAwait(false));
        }
예제 #15
0
        public async Task <IDifference> GetUpdates(IState currentState, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var getDiffRequest = new RequestGetDifference
            {
                Pts  = currentState.Pts,
                Qts  = currentState.Qts,
                Date = currentState.Date
            };

            return(await SenderService.SendRequestAsync(getDiffRequest, cancellationToken).ConfigureAwait(false));
        }
예제 #16
0
        /// <summary>Forwards single messages.</summary>
        /// <param name="peer">User or chat where a message will be forwarded</param>
        /// <param name="messageId">Forwarded message ID</param>
        /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during an action.</returns>
        public async Task <IUpdates> ForwardMessageAsync(IInputPeer peer, int messageId, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var forwardMessage = new RequestForwardMessage
            {
                Peer     = peer,
                Id       = messageId,
                RandomId = TlHelpers.GenerateRandomLong()
            };

            return(await SenderService.SendRequestAsync(forwardMessage, cancellationToken).ConfigureAwait(false));
        }
예제 #17
0
        /// <summary>Send text message to peer</summary>
        /// <returns>Object contains list of updates.</returns>
        public async Task <IUpdates> SendMessageAsync(IInputPeer peer, string message, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            return(await SenderService.SendRequestAsync(
                       new RequestSendMessage
            {
                Peer = peer,
                Message = message,
                RandomId = TlHelpers.GenerateRandomLong()
            },
                       cancellationToken).ConfigureAwait(false));
        }
예제 #18
0
        /// <summary>Deletes communication history.</summary>
        /// <param name="peer">User or chat, communication history of which will be deleted</param>
        /// <param name="maxId">
        ///     If a positive value was transferred, the method will return only messages with IDs less than the
        ///     set one
        /// </param>
        /// <param name="justClear">Delete as non-recoverable or just clear the history</param>
        /// <returns>Returns a <see cref="IAffectedHistory" /> object containing a affected history</returns>
        public async Task <IAffectedHistory> DeleteHistoryAsync(IInputPeer peer, int maxId, bool justClear, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var deleteHistory = new RequestDeleteHistory
            {
                Peer      = peer,
                JustClear = justClear,
                MaxId     = maxId
            };

            return(await SenderService.SendRequestAsync(deleteHistory, cancellationToken).ConfigureAwait(false));
        }
예제 #19
0
        public async Task <IMessages> GetHistoryAsync(IInputPeer peer, int offset, int maxId, int limit, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var req = new RequestGetHistory
            {
                Peer      = peer,
                AddOffset = offset,
                MaxId     = maxId,
                Limit     = limit
            };

            return(await SenderService.SendRequestAsync(req, cancellationToken).ConfigureAwait(false));
        }
예제 #20
0
        /// <summary>Sends a non-text message.</summary>
        /// <param name="peer">User or group to receive the message</param>
        /// <param name="media">Message contents</param>
        /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during the action.</returns>
        public async Task <IUpdates> SendMediaAsync(IInputPeer peer, IInputMedia media, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var sendMedia = new RequestSendMedia
            {
                RandomId   = TlHelpers.GenerateRandomLong(),
                Peer       = peer,
                Media      = media,
                Background = false,
                ClearDraft = false
            };

            return(await SenderService.SendRequestAsync(sendMedia, cancellationToken).ConfigureAwait(false));
        }
예제 #21
0
        /// <summary>Forwards messages by their IDs.</summary>
        /// <param name="fromPeer">User or chat from where a message will be forwarded</param>
        /// <param name="toPeer">User or chat where a message will be forwarded</param>
        /// <param name="ids">Forwarded message IDs</param>
        /// <param name="silent"></param>
        /// <param name="withMyScore"></param>
        /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during an action.</returns>
        public async Task <IUpdates> ForwardMessagesAsync(IInputPeer fromPeer, IInputPeer toPeer, TVector <int> ids, bool silent, bool withMyScore, CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            var forwardMessages = new RequestForwardMessages
            {
                FromPeer    = fromPeer,
                ToPeer      = toPeer,
                Id          = ids,
                Background  = false,
                Silent      = silent,
                WithMyScore = withMyScore,
                RandomId    = TlHelpers.GenerateRandomTVectorLong(ids.Items.Count)
            };

            return(await SenderService.SendRequestAsync(forwardMessages, cancellationToken));
        }
예제 #22
0
        public async Task <IState> GetCurrentState(CancellationToken cancellationToken = default(CancellationToken))
        {
            AuthApiService.EnsureUserAuthorized();

            return(await SenderService.SendRequestAsync(new RequestGetState(), cancellationToken).ConfigureAwait(false));
        }