Esempio n. 1
0
        public static Result <Message> sendAnimation(long chat_id, string url, string caption, string parse_mode = "markdown", bool disable_notification = false, int reply_to_message_id = 0, InlineKeyboardMarkup keyboard = null)
        {
            SendAnimationUrlRequest anur = new SendAnimationUrlRequest()
            {
                animation_url = url,
                chat_id       = chat_id,
                caption       = caption,
                parse_mode    = parse_mode,
            };

            if (disable_notification)
            {
                anur.disable_notification = true;
            }
            if (reply_to_message_id != 0)
            {
                anur.reply_to_message_id = reply_to_message_id;
            }
            if (keyboard != null)
            {
                anur.reply_markup = keyboard;
            }
            Result <Message> result;

            result = sendRequest <Message>(Method.sendAnimation, buildRequest <SendAnimationUrlRequest>(anur));
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a message to a Chat in response to another message, Channel, Group, or User. Returns the Result<Message> object on success.
        /// </summary>
        /// <param name="chat_id">The Id number od the chat to send a Photo. Can be a User, Channel, Or group. Cannot be a bot.</param>
        /// <param name="fileData">The StreamContent object for the raw image file to upload. Cannot be larger than 20MB.</param>
        /// <param name="filename">Telegram requires a file name for images. It can be anything, must end in jpg, png, or jpeg</param>
        /// <param name="caption">The text to send to the Chat, as part of the image. Character Limit of 4096.
        /// <param name="parse_mode">Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. Markdown by default.</param>
        /// <param name="disable_notification">If True, Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="reply_to_message_id" >The ID of the message you want this Photo message to be in response of. Setting this to 0 will not send it as a reply.</param>
        /// <param name="keyboard">InlineKeyboardMarkup Object. Pass a built Keyboard object in here to include it in your messages.</param>
        /// <returns></returns>
        public static Result <Message> sendPhoto(long chatId, StreamContent fileData, string filename, string caption, string parse_mode = "markdown", bool disable_notification = false, int reply_to_message_id = 0, InlineKeyboardMarkup keyboard = null)
        {
            SendPhotoDataRequest spr = new SendPhotoDataRequest()
            {
                chat_id = chatId
            };

            using (MultipartFormDataContent form = new MultipartFormDataContent())
            {
                form.Add(new StringContent(chatId.ToString(), Encoding.UTF8), "chat_id");
                form.Add(fileData, "photo", filename);
                if (caption != null)
                {
                    form.Add(new StringContent(caption.ToString(), Encoding.UTF8), "caption");
                }
                if (parse_mode != null)
                {
                    form.Add(new StringContent(parse_mode.ToString(), Encoding.UTF8), "parse_mode");
                }
                if (disable_notification)
                {
                    form.Add(new StringContent(disable_notification.ToString(), Encoding.UTF8), "disable_notification");
                }
                if (reply_to_message_id != 0)
                {
                    form.Add(new StringContent(reply_to_message_id.ToString(), Encoding.UTF8), "reply_to_message_id");
                }
                if (keyboard != null)
                {
                    //spr.reply_markup = keyboard;
                    form.Add(new StringContent(buildRequest <InlineKeyboardMarkup>(keyboard), Encoding.UTF8), "reply_markup");
                }
                Result <Message> result = sendRequest <Message>(Method.sendPhoto, "", "", form);
                return(result);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Sends a message to a Chat, Group, Channel, or User. Returns the Result<Message> object on success.
        /// </summary>
        /// <param name="chat_id">The Id number od the chat to send a message. Can be a User, Channel, Or group. Cannot be a bot.</param>
        /// <param name="text">The text to send to the Chat. Character Limit of 4096.</param>
        /// <param name="parse_mode">Markdown, HTML, or Empty. Tells telegram how to parse special markdown flags in the text. Markdown by default.</param>
        /// <param name="keyboard">InlineKeyboardMarkup Object. Pass a built Keyboard object in here to include it in your messages.</param>
        /// <returns></returns>
        public static Result <Message> sendMessage(long chatId, string text, string parse_mode = "markdown", InlineKeyboardMarkup keyboard = null)
        {
            SendMessageRequest smr = new SendMessageRequest()
            {
                chat_id    = chatId,
                text       = text,
                parse_mode = parse_mode
            };

            if (keyboard != null)
            {
                smr.reply_markup = keyboard;
            }
            Result <Message> result = null;

            result = sendRequest <Message>(Method.sendMessage, buildRequest <SendMessageRequest>(smr));
            return(result);
        }
Esempio n. 4
0
        public static Result <Message> sendVideo(long chat_id, Stream content, string fileName, string caption, string parse_mode = "markdown",
                                                 int duration = 0, int width = 0, int height = 0, string thumb = "", bool supports_streaming = false,
                                                 bool disable_notification = false, int reply_to_message_id = 0, InlineKeyboardMarkup keyboard = null)

        {
            using (MultipartFormDataContent form = new MultipartFormDataContent())
            {
                form.Add(new StringContent(chat_id.ToString(), Encoding.UTF8), "chat_id");
                fileName = fileName ?? "video";
                string      contentDisposision = $@"form-data; name=""video""; filename=""{fileName}""";
                HttpContent mediaPartContent   = new StreamContent(content)
                {
                    Headers =
                    {
                        { "Content-Type",        "application/octet-stream" },
                        { "Content-Disposition", contentDisposision         }
                    }
                };

                form.Add(mediaPartContent, "video");
                if (duration != 0)
                {
                    form.Add(new StringContent(duration.ToString(), Encoding.UTF8), "duration");
                }
                if (width != 0)
                {
                    form.Add(new StringContent(width.ToString(), Encoding.UTF8), "width");
                }
                if (height != 0)
                {
                    form.Add(new StringContent(height.ToString(), Encoding.UTF8), "height");
                }
                if (caption != null)
                {
                    form.Add(new StringContent(caption.ToString(), Encoding.UTF8), "caption");
                }
                if (!string.IsNullOrEmpty(thumb))
                {
                    form.Add(new StringContent(thumb.ToString(), Encoding.UTF8), "thumb");
                }
                if (parse_mode != null)
                {
                    form.Add(new StringContent(parse_mode.ToString(), Encoding.UTF8), "parse_mode");
                }
                if (supports_streaming)
                {
                    form.Add(new StringContent(supports_streaming.ToString(), Encoding.UTF8), "supports_streaming");
                }
                if (disable_notification)
                {
                    form.Add(new StringContent(disable_notification.ToString(), Encoding.UTF8), "disable_notification");
                }
                if (reply_to_message_id != 0)
                {
                    form.Add(new StringContent(reply_to_message_id.ToString(), Encoding.UTF8), "reply_to_message_id");
                }
                if (keyboard != null)
                {
                    form.Add(new StringContent(buildRequest <InlineKeyboardMarkup>(keyboard), Encoding.UTF8), "reply_markup");
                }
                Result <Message> result = sendRequest <Message>(Method.sendVideo, "", "", form);
                return(result);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Use this method to send general files. On success, the sent Result<Message> is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
        /// </summary>
        /// <param name="chat_id">The Id number od the chat to send a Photo. Can be a User, Channel, Or group. Cannot be a bot.</param>
        /// <param name="fileData">The StreamContent object for the raw image file to upload. Cannot be larger than 20MB.</param>
        /// <param name="thumb">Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320.</param>
        /// <param name="caption">Document caption (may also be used when resending documents by file_id), 0-1024 characters.
        /// <param name="parse_mode">Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. Markdown by default.</param>
        /// <param name="disable_notification">If True, Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="reply_to_message_id" >The ID of the message you want this Photo message to be in response of. Setting this to 0 will not send it as a reply.</param>
        /// <param name="keyboard">InlineKeyboardMarkup Object. Pass a built Keyboard object in here to include it in your messages.</param>
        /// <returns></returns>
        public static Result <Message> sendDocument(long chatId, StreamContent fileData, string caption, StreamContent thumb = null, string parse_mode = "markdown", bool disable_notification = false, int reply_to_message_id = 0, InlineKeyboardMarkup keyboard = null)
        {
            SendDocumentDataRequest sddr = new SendDocumentDataRequest()
            {
                chat_id    = chatId,
                caption    = caption,
                parse_mode = parse_mode,
            };
            MultipartFormDataContent form = new MultipartFormDataContent();

            form.Add(new StringContent(chatId.ToString(), Encoding.UTF8), "chat_id");

            form.Add(fileData, "document");

            if (thumb != null)
            {
                form.Add(thumb, "thumb");
            }
            if (caption != null)
            {
                form.Add(new StringContent(caption.ToString(), Encoding.UTF8), "caption");
            }
            if (parse_mode != null)
            {
                form.Add(new StringContent(parse_mode.ToString(), Encoding.UTF8), "parse_mode");
            }
            if (disable_notification)
            {
                form.Add(new StringContent(disable_notification.ToString(), Encoding.UTF8), "disable_notification");
            }
            if (reply_to_message_id != 0)
            {
                form.Add(new StringContent(reply_to_message_id.ToString(), Encoding.UTF8), "reply_to_message_id");
            }
            if (keyboard != null)
            {
                string payload1 = buildRequest <SendDocumentDataRequest>(sddr);
                form.Add(new StringContent(payload1, Encoding.UTF8), "reply_markup");
            }
            string a = Task.Run(() => form.ReadAsStringAsync()).Result;

            Console.WriteLine(a);
            Result <Message> result = sendRequest <Message>(Method.sendDocument, "", "", form);

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Sends a message to a Chat in response to another message, Channel, Group, or User. Returns the Result<Message> object on success.
        /// </summary>
        /// <param name="chat_id">The Id number od the chat to send a Audio file. Can be a User, Channel, Or group. Cannot be a bot.</param>
        /// <param name="fileData">The StreamContent object for the raw audio file to upload. Cannot be larger than 20MB.</param>
        /// <param name="filename">Telegram requires a file name for files. It can be anything, must end in the file ext that matches the type of audio file you're sending.</param>
        /// <param name="caption">The text to send to the Chat, as part of the audio file. Character Limit of 4096.
        /// <param name="parse_mode">Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. Markdown by default.</param>
        /// <param name="duration">The length of the audio file in seconds.</param>
        /// <param name="performer">The artist of of audio clip (If its music) Optional.</param>
        /// <param name="title">The title of of audio clip (If its music) Optional.</param>
        /// <param name="disable_notification">If True, Sends the message silently. Users will receive a notification with no sound.</param>
        /// <param name="reply_to_message_id" >The ID of the message you want this Photo message to be in response of. Setting this to 0 will not send it as a reply.</param>
        /// <param name="keyboard">InlineKeyboardMarkup Object. Pass a built Keyboard object in here to include it in your messages.</param>
        /// <returns></returns>
        public static Result <Message> sendAudio(long chatId, StreamContent fileData, string filename, string caption, string parse_mode = "markdown", int duration = 0, string performer = "", string title = "", bool disable_notification = false, int reply_to_message_id = 0, InlineKeyboardMarkup keyboard = null)
        {
            SendAudioRequest spr = new SendAudioRequest()
            {
                chat_id    = chatId,
                caption    = caption,
                parse_mode = parse_mode,
            };
            MultipartFormDataContent form = new MultipartFormDataContent();

            form.Add(new StringContent(chatId.ToString(), Encoding.UTF8), "chat_id");
            form.Add(fileData, "audio", filename);
            if (caption != null)
            {
                form.Add(new StringContent(caption.ToString(), Encoding.UTF8), "caption");
            }
            if (parse_mode != null)
            {
                form.Add(new StringContent(parse_mode.ToString(), Encoding.UTF8), "parse_mode");
            }
            if (duration != 0)
            {
                form.Add(new StringContent(duration.ToString(), Encoding.UTF8), "duration");
            }
            if (performer != "")
            {
                form.Add(new StringContent(performer.ToString(), Encoding.UTF8), "performer");
            }
            if (title != "")
            {
                form.Add(new StringContent(title.ToString(), Encoding.UTF8), "title");
            }
            if (disable_notification)
            {
                form.Add(new StringContent(disable_notification.ToString(), Encoding.UTF8), "disable_notification");
            }
            if (reply_to_message_id != 0)
            {
                form.Add(new StringContent(reply_to_message_id.ToString(), Encoding.UTF8), "reply_to_message_id");
            }
            if (keyboard != null)
            {
                string payload1 = buildRequest <SendPhotoDataRequest>(spr);
                form.Add(new StringContent(payload1, Encoding.UTF8), "reply_markup");
            }
            Result <Message> result = sendRequest <Message>(Method.sendAudio, "", "", form);

            return(result);
        }
Esempio n. 7
0
        internal static InlineKeyboardMarkup PluginMgr()
        {
            InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();

            return(keyboard);
        }