Exemple #1
0
        /// <summary>
        /// Get messages.
        /// </summary>
        public async Task <IApiResponse <MessageList> > GetMessagesAsync(long?chatId = null, IEnumerable <long> messageIds = null, long?from = null, long?to = null, long limit = 50, CancellationToken cancellationToken = default)
        {
            var relativeRequireUrl = $"messages?access_token={_accessToken}";

            if (chatId.HasValue)
            {
                relativeRequireUrl += $"&chat_id={chatId.Value}";
            }
            if (messageIds != null)
            {
                relativeRequireUrl += "&message_ids=" + string.Join(",", messageIds);
            }
            if (from.HasValue)
            {
                relativeRequireUrl += $"&from={from.Value}";
            }
            if (to.HasValue)
            {
                relativeRequireUrl += $"&to={to.Value}";
            }
            ThrowIfOutOfInclusiveRange(limit, nameof(limit), 1, 100);
            relativeRequireUrl += $"&count={limit}";
            IApiResponse <MessageList> result = null;

            result = await SenderApi.GetAsync <MessageList>(_connectorClient, GetApiUri(relativeRequireUrl), cancellationToken);

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Add members.
        /// </summary>
        public async Task <IApiResponse <SimpleQueryResult> > AddMembersAsync(long chatId, UserIdsList userIds, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.PostAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"chats/{chatId}/members?access_token={_accessToken}"), userIds, cancellationToken);

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Remove member.
        /// </summary>
        public async Task <IApiResponse <SimpleQueryResult> > RemoveMemberAsync(long chatId, long userId, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.DeleteAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"chats/{chatId}/members?access_token={_accessToken}&user_id={userId}"), cancellationToken);

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Get chat membership.
        /// </summary>
        public async Task <IApiResponse <ChatMember> > GetChatMembershipAsync(long chatId, CancellationToken cancellationToken = default)
        {
            IApiResponse <ChatMember> result = null;

            result = await SenderApi.GetAsync <ChatMember>(_connectorClient, GetApiUri($"chats/{chatId}/members/me?access_token={_accessToken}"), cancellationToken);

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Get subscriptions.
        /// </summary>
        /// <returns></returns>
        public async Task <IApiResponse <GetSubscriptionsResult> > GetSubscriptionsAsync(CancellationToken cancellationToken = default)
        {
            IApiResponse <GetSubscriptionsResult> result = null;

            result = await SenderApi.GetAsync <GetSubscriptionsResult>(_connectorClient, GetApiUri($"subscriptions?access_token={_accessToken}"), cancellationToken);

            return(result);
        }
Exemple #6
0
        /// <summary>
        /// Edit chat info.
        /// </summary>
        public async Task <IApiResponse <Chat> > EditChatInfoAsync(long chatId, ChatPatch chatPatch, CancellationToken cancellationToken = default)
        {
            IApiResponse <Chat> result = null;

            result = await SenderApi.PatchAsync <Chat>(_connectorClient, GetApiUri($"chats/{chatId}?access_token={_accessToken}"), chatPatch, cancellationToken);

            return(result);
        }
Exemple #7
0
        public async Task <IApiResponse <UploadedFileInfo> > UploadFileAsync(Uri requestUri, string assetName, Stream stream, CancellationToken cancellationToken = default)
        {
            IApiResponse <UploadedFileInfo> result = null;

            result = await SenderApi.UploadFileAsync(_connectorClient, requestUri, assetName, stream, cancellationToken);

            return(result);
        }
Exemple #8
0
        /// <summary>
        /// Edit current bot info.
        /// </summary>
        public async Task <IApiResponse <BotInfo> > EditCurrentBotInfoAsync(BotPatch botPatch, CancellationToken cancellationToken = default)
        {
            IApiResponse <BotInfo> result = null;

            result = await SenderApi.PatchAsync <BotInfo>(_connectorClient, GetApiUri($"me?access_token={_accessToken}"), botPatch, cancellationToken);

            return(result);
        }
Exemple #9
0
        public async Task <IApiResponse <SimpleQueryResult> > SubscribeAsync(SubscriptionRequestBody subscriptionRequest, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.PostAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"subscriptions?access_token={_accessToken}"), subscriptionRequest, cancellationToken);

            return(result);
        }
Exemple #10
0
        /// <summary>
        /// Unsubscribe.
        /// </summary>
        public async Task <IApiResponse <SimpleQueryResult> > UnsubscribeAsync(string url, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.DeleteAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"subscriptions?access_token={_accessToken}&url={url}"), cancellationToken);

            return(result);
        }
Exemple #11
0
        /// <summary>
        /// Send action.
        /// </summary>
        public async Task <IApiResponse <SimpleQueryResult> > SendActionAsync(long chatId, ActionRequestBody action, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.PostAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"chats/{chatId}/actions?access_token={_accessToken}"), action, cancellationToken);

            return(result);
        }
Exemple #12
0
        /// <summary>
        /// Answer on callback.
        /// </summary>
        public async Task <IApiResponse <SimpleQueryResult> > AnswerOnCallbackAsync(string callbackId, CallbackAnswer answer, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.PostAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"answers?access_token={_accessToken}&callback_id={callbackId}"), answer, cancellationToken);

            return(result);
        }
Exemple #13
0
        /// <summary>
        /// Delete message.
        /// </summary>
        public async Task <IApiResponse <SimpleQueryResult> > DeleteMessageAsync(string messageId, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.DeleteAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"messages?access_token={_accessToken}&message_id={messageId}"), cancellationToken);

            return(result);
        }
Exemple #14
0
        /// <summary>
        /// Get all chats.
        /// </summary>
        public async Task <IApiResponse <ChatList> > GetAllChatsAsync(int limit = 50, long offset = 0, CancellationToken cancellationToken = default)
        {
            ThrowIfOutOfInclusiveRange(limit, nameof(limit), 1, 100);
            IApiResponse <ChatList> result = null;

            result = await SenderApi.GetAsync <ChatList>(_connectorClient, GetApiUri($"chats?access_token={_accessToken}&count={limit}&marker={offset}"), cancellationToken);

            return(result);
        }
        public SenderApiControllerTest()
        {
            var config = new MapperConfiguration(cfg => cfg.AddProfile(new Mapper.SKSLayerMapper()));

            _mapper     = new AutoMapper.Mapper(config);
            _mock       = new Mock <ISenderLogic>();
            _controller = new SenderApi(_mock.Object, _mapper, new LoggerFactory().CreateLogger <SenderApi>());

            parcel = new Parcel();
        }
Exemple #16
0
        /// <summary>
        /// Get upload URL.
        /// </summary>
        public async Task <IApiResponse <UploadEndpoint> > GetUploadUrlAsync(UploadType type, CancellationToken cancellationToken = default)
        {
            var relativeRequireUrl = $"uploads?access_token={_accessToken}";

            relativeRequireUrl += $"&type=" + ToEnumString(type);

            IApiResponse <UploadEndpoint> result = null;

            result = await SenderApi.PostAsync <UploadEndpoint>(_connectorClient, GetApiUri(relativeRequireUrl), null, cancellationToken);

            return(result);
        }
Exemple #17
0
        public void Put()
        {
            IQueryable <Status> statuses = databaseMailContext.Status.Where(s => s.Status1 == (int)MailStatus.Pending);

            foreach (var item in statuses)
            {
                Mail        mail = databaseMailContext.Mail.SingleOrDefault(m => m.IdMail == item.IdMail);
                ReceiveMail temp = fillReceiveMail(mail);

                SenderApi senderApi = new SenderApi("http://127.0.0.1:5001");
                senderApi.SenderPost(temp.Sender, new List <string>(temp.To), new List <string>(temp.Cc), new List <string>(temp.Bcc), temp.Titel, temp.Body, (int)temp.PriorityEmail);
            }
        }
Exemple #18
0
        /// <summary>
        /// Send message.
        /// </summary>
        public async Task <IApiResponse <SendMessageResult> > SendMessageAsync(NewMessageBody message, long?userId = null, long?chatId = null, CancellationToken cancellationToken = default)
        {
            var relativeRequireUrl = $"messages?access_token={_accessToken}";

            if (userId.HasValue)
            {
                relativeRequireUrl += $"&user_id={userId.Value}";
            }
            if (chatId.HasValue)
            {
                relativeRequireUrl += $"&chat_id={chatId.Value}";
            }
            IApiResponse <SendMessageResult> result = null;

            result = await SenderApi.PostAsync <SendMessageResult>(_connectorClient, GetApiUri(relativeRequireUrl), message, cancellationToken);

            return(result);
        }
Exemple #19
0
        /// <summary>
        /// Get members.
        /// </summary>
        public async Task <IApiResponse <ChatMembersList> > GetMembersAsync(long chatId, IEnumerable <long> userIds = null, int limit = 20, long offset = 0, CancellationToken cancellationToken = default)
        {
            var relativeRequireUrl = $"chats/{chatId}/members?access_token={_accessToken}";

            if (userIds != null)
            {
                relativeRequireUrl += "&user_ids=" + string.Join(",", userIds);
            }
            else
            {
                ThrowIfOutOfInclusiveRange(limit, nameof(limit), 1, 100);
                relativeRequireUrl += $"&count={limit}&marker={offset}";
            }
            IApiResponse <ChatMembersList> result = null;

            result = await SenderApi.DeleteAsync <ChatMembersList>(_connectorClient, GetApiUri(relativeRequireUrl), cancellationToken);

            return(result);
        }
Exemple #20
0
        /// <summary>
        /// Get updates.
        /// </summary>
        public async Task <IApiResponse <UpdateList> > GetUpdatesAsync(long limit = 100, long?offset = null, IEnumerable <UpdateType> types = null, long timeout = 30, CancellationToken cancellationToken = default)
        {
            ThrowIfOutOfInclusiveRange(limit, nameof(limit), 1, 1000);
            ThrowIfOutOfInclusiveRange(timeout, nameof(timeout), 0, 90);

            var relativeRequireUrl = $"updates?access_token={_accessToken}";

            relativeRequireUrl += $"&limit={limit}&timeout={timeout}";
            if (offset.HasValue)
            {
                relativeRequireUrl += $"&marker={offset}";
            }
            if (types != null)
            {
                relativeRequireUrl += $"&types=" + string.Join(",", types.Select(type => ToEnumString(type)));
            }
            IApiResponse <UpdateList> result = null;

            result = await SenderApi.GetAsync <UpdateList>(_connectorClient, GetApiUri(relativeRequireUrl), cancellationToken);

            return(result);
        }