public async Task <IUpdates> SendUploadedDocument( IInputPeer peer, IInputFile file, string caption, string mimeType, TVector <IDocumentAttribute> attributes) { 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 }).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <IUpdates> SendUploadedDocumentAsync(IInputPeer peer, IInputFile document, string mimeType, IReadOnlyList <IDocumentAttribute> attributes, string message, [AllowNull] IInputFile thumb = null, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); var request = new RequestSendMedia { RandomId = Random.NextLong(), Background = false, ClearDraft = false, Message = message, Media = new TInputMediaUploadedDocument { File = document, MimeType = mimeType, Thumb = thumb, Attributes = new TVector <IDocumentAttribute>(attributes.ToArray()) }, Peer = peer }; return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <bool> SendTypingAsync(IInputPeer peer, CancellationToken cancellationToken = default(CancellationToken)) { var req = new RequestSetTyping { Action = new TSendMessageTypingAction(), Peer = peer }; return(await RequestSender.SendRequestAsync(req, cancellationToken).ConfigureAwait(false)); }
public async Task <bool> SendTypingAsync(IInputPeer peer) { var req = new RequestSetTyping { Action = new TSendMessageTypingAction(), Peer = peer }; return(await SenderService.SendRequestAsync(req).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <IAffectedMessages> ReadHistoryAsync(IInputPeer peer, int maxId, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); var readHistory = new RequestReadHistory { Peer = peer, MaxId = maxId }; return(await RequestSender.SendRequestAsync(readHistory, cancellationToken).ConfigureAwait(false)); }
/// <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) { EnsureUserAuthorized(); var readHistory = new RequestReadHistory { Peer = peer, MaxId = maxId }; return(await SenderService.SendRequestAsync(readHistory).ConfigureAwait(false)); }
/// <summary> /// Send text message to peer /// </summary> /// <returns> /// Object contains list of updates. /// </returns> public async Task <IUpdates> SendMessageAsync(IInputPeer peer, string message) { EnsureUserAuthorized(); return(await SenderService.SendRequestAsync( new RequestSendMessage { Peer = peer, Message = message, RandomId = TlHelpers.GenerateRandomLong() }).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <IAffectedHistory> DeleteHistoryAsync(IInputPeer peer, int maxId, bool justClear, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); var deleteHistory = new RequestDeleteHistory { Peer = peer, JustClear = justClear, MaxId = maxId }; return(await RequestSender.SendRequestAsync(deleteHistory, cancellationToken).ConfigureAwait(false)); }
/// <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)); }
/// <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) { EnsureUserAuthorized(); var forwardMessage = new RequestForwardMessage { Peer = peer, Id = messageId, RandomId = TlHelpers.GenerateRandomLong() }; return(await SenderService.SendRequestAsync(forwardMessage).ConfigureAwait(false)); }
/// <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)); }
/// <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) { EnsureUserAuthorized(); var deleteHistory = new RequestDeleteHistory { Peer = peer, JustClear = justClear, MaxId = maxId }; return(await SenderService.SendRequestAsync(deleteHistory).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <IUpdates> SendMessageAsync(IInputPeer peer, string message, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); return(await RequestSender.SendRequestAsync( new RequestSendMessage { Peer = peer, Message = message, RandomId = Random.NextLong() }, cancellationToken).ConfigureAwait(false)); }
public async Task <IMessages> GetHistoryAsync(IInputPeer peer, int offset, int maxId, int limit) { EnsureUserAuthorized(); var req = new RequestGetHistory { Peer = peer, AddOffset = offset, MaxId = maxId, Limit = limit }; return(await SenderService.SendRequestAsync(req).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <IMessages> GetHistoryAsync(IInputPeer peer, int offset, int maxId, int limit, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); var req = new RequestGetHistory { Peer = peer, AddOffset = offset, MaxId = maxId, Limit = limit }; return(await RequestSender.SendRequestAsync(req, cancellationToken).ConfigureAwait(false)); }
/// <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) { EnsureUserAuthorized(); var sendMedia = new RequestSendMedia { RandomId = TlHelpers.GenerateRandomLong(), Peer = peer, Media = media, Background = false, ClearDraft = false }; return(await SenderService.SendRequestAsync(sendMedia).ConfigureAwait(false)); }
public async Task <IUpdates> SendUploadedPhoto(IInputPeer peer, IInputFile file, string caption) { EnsureUserAuthorized(); return(await SenderService.SendRequestAsync(new RequestSendMedia { RandomId = TlHelpers.GenerateRandomLong(), Background = false, ClearDraft = false, Media = new TInputMediaUploadedPhoto { File = file, Caption = caption }, Peer = peer }).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <IUpdates> SendMediaAsync(IInputPeer peer, IInputMedia media, string message, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); var sendMedia = new RequestSendMedia { RandomId = Random.NextLong(), Peer = peer, Media = media, Message = message, Background = false, ClearDraft = false }; return(await RequestSender.SendRequestAsync(sendMedia, cancellationToken).ConfigureAwait(false)); }
/// <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) { 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)); }
/// <inheritdoc /> public async Task <IUpdates> SendUploadedPhotoAsync(IInputPeer peer, IInputFile photo, string message, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); var request = new RequestSendMedia { RandomId = Random.NextLong(), Background = false, ClearDraft = false, Message = message, Media = new TInputMediaUploadedPhoto { File = photo, }, Peer = peer }; return(await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false)); }
public async Task ForPeer(int id, PeerType peerType, string userId, int offset, int maxId) { IInputPeer peer = GetPeer(id, peerType); IClientApi client = await _telegramService.BuildAsync(userId); IMessages history = await TelegramRequest.HandleAsync(() => { return(client.MessagesService.GetHistoryAsync(peer, offset, maxId, 100)); }); List <Message> messages = MessagesParser.Parse(history, id, peerType); await _eventHub.SendAsync(messages); if (messages.Count > 0) { BackgroundJob.Schedule <GetMessages>( job => job.ForPeer(id, peerType, userId, offset + 100, 0), TimeSpan.FromSeconds(_randomService.Random.Next(5, 20))); } }
/// <inheritdoc /> public async Task <IUpdates> ForwardMessagesAsync(IInputPeer fromPeer, IInputPeer toPeer, IReadOnlyList <int> ids, bool silent, bool withMyScore, CancellationToken cancellationToken = default(CancellationToken)) { ClientSettings.EnsureUserAuthorized(); var forwardMessages = new RequestForwardMessages { FromPeer = fromPeer, ToPeer = toPeer, Id = new TVector <int>(ids.ToArray()), Background = false, Silent = silent, WithMyScore = withMyScore, RandomId = new TVector <long>(Random.NextLong()) }; return(await RequestSender.SendRequestAsync(forwardMessages, cancellationToken)); }