Exemple #1
0
        public static async Task <List <Update> > GetUpdatesAsync(this Telegram telegram)
        {
            var result = new List <Update>();

            var url = telegram.GetFullPathUrl("getUpdates");

            var request = new ExternalRequest <ResponseAnswer <List <Update> >, GetUpdatesRequest>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json",
            };

            if (offset != 0)
            {
                request.PostContent = new GetUpdatesRequest()
                {
                    Offset = offset
                };
            }

            var response = await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);

            result = response?.Result?.Result ?? new List <Update>();

            if (result.Any())
            {
                offset = result.LastOrDefault().Id + 1;
            }

            return(result);
        }
Exemple #2
0
        public static async Task SendBotActionAsync(this Telegram telegram, SendBotActionRequest sendRequest)
        {
            var result = new Message();

            var url = telegram.GetFullPathUrl("sendChatAction");

            var request = new ExternalRequest <ResponseAnswer <Message>, SendBotActionRequest>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json",
                PostContent     = sendRequest
            };

            await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);
        }
Exemple #3
0
        public static async Task <WebhookInfoEntity> GetWebhookInfoAsync(this Telegram telegram)
        {
            var url = telegram.GetFullPathUrl("getWebhookInfo");


            var request = new ExternalRequest <ResponseAnswer <WebhookInfoEntity>, object>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json"
            };

            var result = await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);

            return(result.Result.Result);
        }
Exemple #4
0
        public static async Task <bool> SendCallbackAnswerAsync(this Telegram telegram, AnswerCallbackQueryRequest answer)
        {
            var url = telegram.GetFullPathUrl("answerCallbackQuery");

            var request = new ExternalRequest <ResponseAnswer <bool>, AnswerCallbackQueryRequest>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json",
                PostContent     = answer
            };

            var response = await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);

            var isSuccess = response.Result?.Result ?? false;

            return(isSuccess);
        }
Exemple #5
0
        public static async Task <bool> TryUnbanChatMemberAsync(this Telegram telegram, KickChatMemberRequest kickRequest)
        {
            var url = telegram.GetFullPathUrl("unbanChatMember");

            var request = new ExternalRequest <ResponseAnswer <bool>, KickChatMemberRequest>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json",
                PostContent     = kickRequest
            };

            var response = await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);

            var isSuccess = response.Result.Result;

            return(isSuccess);
        }
Exemple #6
0
        public static async Task SetWebhookAsync(this Telegram telegram, string webhookUrl)
        {
            var webhookRequest = new WebhookEntity()
            {
                Url = webhookUrl
            };

            var url = telegram.GetFullPathUrl("setWebhook");

            var request = new ExternalRequest <ResponseAnswer <object>, WebhookEntity>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json",
                PostContent     = webhookRequest
            };

            var response = await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);
        }
Exemple #7
0
        public static async Task <Message> EditMessageReplyMarkupAsync(this Telegram telegram, EditReplyMarkupRequest sendMessageRequest)
        {
            var result = new Message();

            var url = telegram.GetFullPathUrl("editMessageText");

            var request = new ExternalRequest <ResponseAnswer <Message>, EditReplyMarkupRequest>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json",
                PostContent     = sendMessageRequest
            };

            var response = await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);

            result = response.Result.Result;

            return(result);
        }
Exemple #8
0
        public static async Task <File> GetFileAsync(this Telegram telegram, GetFileRequest sendRequest)
        {
            var result = new File();

            var url = telegram.GetFullPathUrl("getFile");

            var request = new ExternalRequest <ResponseAnswer <File>, GetFileRequest>()
            {
                Method          = POST_METHOD,
                PostContentType = "application/json",
                PostContent     = sendRequest
            };

            var response = await RequestSender.Execute(DataAccessMode.Server, request, url).ConfigureAwait(false);

            result = response.Result.Result;

            return(result);
        }