예제 #1
0
        /// <summary>
        /// Send chat action
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="action"></param>
        public void SendChatAction(string chatId, ChatAction action)
        {
            var actionDictionary = new Dictionary <int, string>
            {
                { 1, "typing" },
                { 2, "upload_photo" },
                { 3, "record_video" },
                { 4, "upload_video" },
                { 5, "record_audio" },
                { 6, "upload_audio" },
                { 7, "upload_document" },
                { 8, "find_location" }
            };
            string currentAction;

            actionDictionary.TryGetValue((int)action, out currentAction);

            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "action", currentAction }
            };

            RequestCore.Get("sendChatAction", _token, coll).Wait();
        }
예제 #2
0
        /// <summary>
        /// Returns information about your bot
        /// </summary>
        /// <returns></returns>
        public User GetMe()
        {
            var user = JsonConvert
                       .DeserializeObject <RootObject <User> >(RequestCore.Get("getMe", _token, new NameValueCollection()).Result)
                       .Result;

            return(user);
        }
예제 #3
0
 /// <summary>
 /// Forward message
 /// </summary>
 /// <param name="chatId"></param>
 /// <param name="fromChatId"></param>
 /// <param name="messageId"></param>
 public void ForwardMessage(string chatId, string fromChatId, string messageId)
 {
     var coll = new NameValueCollection
     {
         { "chat_id", chatId },
         { "from_chat_id", fromChatId },
         { "message_id", messageId }
     };
     var kek = RequestCore.Get("forwardMessage", _token, coll).Result;
 }
예제 #4
0
        public static async Task Send(this AbbybotCommandArgs arg, RestUserMessage abbybot, SocketMessage user, RequestType type, DateTime time, ISocketMessageChannel imc = null)
        {
            var ro = new RequestObject()
            {
                AbbybotMessage = abbybot, UsersMessage = user, itc = imc, requestType = type, time = time
            };
            await Task.FromResult(ro);

            RequestCore.AddRequest(ro);
        }
예제 #5
0
        /// <summary>
        /// Get information about file
        /// </summary>
        /// <param name="fileId"></param>
        /// <returns></returns>
        public File GetFile(string fileId)
        {
            var coll = new NameValueCollection
            {
                { "file_id", fileId }
            };
            var file = JsonConvert
                       .DeserializeObject <RootObject <File> >(RequestCore.Get("getFile", _token, coll).Result)
                       .Result;

            return(file);
        }
예제 #6
0
        /// <summary>
        /// Send sticker by id
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="sticker"></param>
        /// <param name="replyToMessage"></param>
        /// <param name="replyMarkup"></param>
        public void SendSticker(string chatId, string sticker, string replyToMessage = "", string replyMarkup = "")
        {
            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "sticker", sticker },
                { "reply_to_message_id", replyToMessage },
                { "reply_markup", replyMarkup }
            };

            RequestCore.Get("sendSticker", _token, coll).Wait();
        }
예제 #7
0
        /// <summary>
        /// Send voice message by id
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="voiceId"></param>
        /// <param name="duration"></param>
        /// <param name="replyToMessageId"></param>
        /// <param name="replyMarkup"></param>
        public void SendVoiceById(string chatId, string voiceId, string duration, string replyToMessageId,
                                  string replyMarkup)
        {
            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "voice", voiceId },
                { "duration", duration },
                { "reply_to_message_id", replyToMessageId },
                { "reply_markup", replyMarkup }
            };

            RequestCore.Get("sendVoice", _token, coll).Wait();
        }
예제 #8
0
        /// <summary>
        /// Send existing photo
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="photoId"></param>
        /// <param name="caption"></param>
        /// <param name="replyToMessageId"></param>
        /// <param name="replyMarkup"></param>
        public void SendPhotoById(string chatId, string photoId, string caption = "",
                                  string replyToMessageId = "", string replyMarkup = "")
        {
            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "photo", photoId },
                { "caption", caption },
                { "reply_to_message_id", replyToMessageId },
                { "reply_markup", replyMarkup }
            };

            RequestCore.Get("sendPhoto", _token, coll).Wait();
        }
예제 #9
0
        /// <summary>
        /// Send location
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <param name="replyToMessageId"></param>
        /// <param name="replyMarkUp"></param>
        public void SendLocation(string chatId, string latitude, string longitude, string replyToMessageId = "",
                                 string replyMarkUp = "")
        {
            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "latitude", latitude },
                { "longitude", longitude },
                { "reply_to_message_id", replyToMessageId },
                { "reply_markup", replyMarkUp }
            };

            RequestCore.Get("sendLocation", _token, coll).Wait();
        }
예제 #10
0
        /// <summary>
        /// Gets updates for your bot
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public List <Update> GetUpdates(string offset = "", string limit = "", string timeout = "")
        {
            var coll = new NameValueCollection
            {
                { "offset", offset },
                { "limit", limit },
                { "timeout", timeout }
            };
            var update =
                JsonConvert.DeserializeObject <RootObject <List <Update> > >(
                    RequestCore.Get("getUpdates", _token, coll).Result).Result;

            return(update);
        }
예제 #11
0
        /// <summary>
        /// Send video by id
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="videoId"></param>
        /// <param name="duration"></param>
        /// <param name="caption"></param>
        /// <param name="replyToMessageId"></param>
        /// <param name="replyMarkUp"></param>
        public void SendVideoById(string chatId, string videoId, string duration = "", string caption = "",
                                  string replyToMessageId = "", string replyMarkUp = "")
        {
            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "video", videoId },
                { "duration", duration },
                { "caption", caption },
                { "reply_to_message_id", replyToMessageId },
                { "reply_markup", replyMarkUp }
            };

            RequestCore.Get("sendVideo", _token, coll).Wait();
        }
예제 #12
0
        /// <summary>
        /// Send message to chat
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="text"></param>
        /// <param name="parseMode"></param>
        /// <param name="disableWebPagePreview"></param>
        /// <param name="replyToMessageId"></param>
        /// <param name="replyMarkup"></param>
        public void SendMessage(string chatId, string text, string parseMode = "", string disableWebPagePreview = "",
                                string replyToMessageId = "", string replyMarkup = "")
        {
            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "text", text },
                { "parse_mode", parseMode },
                { "disable_web_page_preview", disableWebPagePreview },
                { "reply_to_message_id", replyToMessageId },
                { "reply_markup", replyMarkup }
            };

            RequestCore.Get("sendMessage", _token, coll).Wait();
        }
예제 #13
0
        /// <summary>
        /// Get user profile photos
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public UserProfilePhotos GetUserProfilePhotos(string userId, string offset = "", string limit = "")
        {
            var coll = new NameValueCollection
            {
                { "file_id", userId },
                { "file_id", offset },
                { "file_id", limit }
            };
            var photos = JsonConvert
                         .DeserializeObject <RootObject <UserProfilePhotos> >(
                RequestCore.Get("getUserProfilePhotos", _token, coll).Result)
                         .Result;

            return(photos);
        }
예제 #14
0
        /// <summary>
        /// Send existing audio
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="audioId"></param>
        /// <param name="duration"></param>
        /// <param name="performer"></param>
        /// <param name="title"></param>
        /// <param name="replyToMessageId"></param>
        /// <param name="replyMarkup"></param>
        public void SendAudioById(string chatId, string audioId, string duration = "", string performer = "",
                                  string title = "", string replyToMessageId = "", string replyMarkup = "")
        {
            var coll = new NameValueCollection
            {
                { "chat_id", chatId },
                { "audio", audioId },
                { "duration", duration },
                { "performer", performer },
                { "title", title },
                { "reply_to_message_id", replyToMessageId },
                { "reply_markup", replyMarkup }
            };

            RequestCore.Get("sendAudio", _token, coll).Wait();
        }
예제 #15
0
        /* Some examples for requests
         * 1. https://jsonplaceholder.typicode.com/
         * 2. https://docs.postman-echo.com/
         * */

        static void Main(string[] args)
        {
            var request = new RequestCore();

            Console.Write("enter url: ");
            var url = Console.ReadLine();

            Console.WriteLine("1. get\n2. post\n3. head\n4. options\n5. auth\n\n9. change url");

            while (true)
            {
                var option = Convert.ToInt32(Console.ReadLine());
                Console.Clear();

                switch (option)
                {
                case 1:
                    request.Get(url);
                    break;

                case 2:
                    request.Post(url);
                    break;

                case 3:
                    request.Head(url);
                    break;

                case 4:
                    request.Options(url);
                    break;

                case 5:
                    request.Auth(url);
                    break;

                case 9:
                    Console.Write("enter url: ");
                    url = Console.ReadLine();
                    break;

                default:
                    return;
                }
            }
        }
예제 #16
0
 public void Init() => _core = new RequestCore();
예제 #17
0
        public static async Task Send(this AbbybotCommandArgs arg, RequestObject ro)
        {
            await Task.FromResult(ro);

            RequestCore.AddRequest(ro);
        }
예제 #18
0
 public MainForm()
 {
     InitializeComponent();
     authUtil    = AuthUtil.getInstance();
     requestCore = RequestCore.GetInstance();
 }
예제 #19
0
 public void Init() => _core = new RequestCore();