Пример #1
0
        public SendMediaRequest(InputPeer inputPeer, InputMedia inputMedia)
        {
            this.inputPeer  = inputPeer;
            this.inputMedia = inputMedia;

            randomId = Helpers.GenerateRandomLong();
        }
Пример #2
0
        private async Task StartUploadPhoto(string name, Stream stream)
        {
            try {
//                Deployment.Current.Dispatcher.BeginInvoke(() => {
//                    UploadProgressBar.Visibility = Visibility.Collapsed;
//                });
                logger.info("START upload photo");
                if (!(model is DialogModelPlain))
                {
                    return;
                }

                DialogModelPlain plainModel = (DialogModelPlain)model;

                InputFile file =
                    await TelegramSession.Instance.Files.UploadFile(name, stream, delegate { });

                InputMedia media = TL.inputMediaUploadedPhoto(file);
                logger.info("END upload photo");

                Deployment.Current.Dispatcher.BeginInvoke(() => {
                    logger.info("Send media in UI thread");

                    plainModel.SendMedia(media);
                });
//                Deployment.Current.Dispatcher.BeginInvoke(() => {
//                    UploadProgressBar.Visibility = Visibility.Collapsed;
//                });
            } catch (Exception ex) {
                logger.error("exception {0}", ex);
            }
        }
Пример #3
0
        private void OnCheckinClick(object sender, EventArgs e)
        {
            InputGeoPoint point    = TL.inputGeoPoint(selectedPushpin.GeoCoordinate.Latitude, selectedPushpin.GeoCoordinate.Longitude);
            InputMedia    geoMedia = TL.inputMediaGeoPoint(point);

            PhoneApplicationService.Current.State["MapMedia"] = geoMedia;
            NavigationService.Navigate(new Uri("/UI/Pages/DialogPage.xaml?modelId=" + returnToModelId + "&action=sendMedia&content=MapMedia", UriKind.Relative));
        }
        public static IAlbumInputMedia ToTelegramMedia(Media media)
        {
            var rawMedia = new InputMedia(media.Url);

            return(media.Type switch
            {
                MediaType.Photo => new InputMediaPhoto(rawMedia),
                _ => new InputMediaVideo(rawMedia)
            });
Пример #5
0
 public Task <Message> SendDocumentAsync(
     ChatId chatId,
     InputOnlineFile document,
     string caption                      = null,
     ParseMode parseMode                 = ParseMode.Default,
     bool disableNotification            = false,
     int replyToMessageId                = 0,
     IReplyMarkup replyMarkup            = null,
     CancellationToken cancellationToken = new CancellationToken(),
     InputMedia thumb                    = null) => throw new NotImplementedException();
Пример #6
0
 public Task <Message> SendVideoNoteAsync(
     ChatId chatId,
     InputTelegramFile videoNote,
     int duration                        = 0,
     int length                          = 0,
     bool disableNotification            = false,
     int replyToMessageId                = 0,
     IReplyMarkup replyMarkup            = null,
     CancellationToken cancellationToken = new CancellationToken(),
     InputMedia thumb                    = null) => throw new NotImplementedException();
Пример #7
0
 public Task <Message> SendAnimationAsync(
     ChatId chatId,
     InputOnlineFile animation,
     int duration                        = 0,
     int width                           = 0,
     int height                          = 0,
     InputMedia thumb                    = null,
     string caption                      = null,
     ParseMode parseMode                 = ParseMode.Default,
     bool disableNotification            = false,
     int replyToMessageId                = 0,
     IReplyMarkup replyMarkup            = null,
     CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException();
Пример #8
0
        private void DoAction(string action, string content)
        {
            if (!(model is DialogModelPlain))
            {
                return;
            }

            if (action == "sendMedia")
            {
                InputMedia media = (InputMedia)PhoneApplicationService.Current.State[content];
                ((DialogModelPlain)model).SendMedia(media);
            }
        }
Пример #9
0
        private async Task DoSendContact(UserModel user)
        {
            if (!(dialogToReturn is DialogModelPlain))
            {
                return;
            }

            InputPeer  ip    = dialogToReturn.InputPeer;
            InputMedia media = TL.inputMediaContact(user.PhoneNumber, user.FirstName, user.LastName);

            DialogModelPlain dialog = (DialogModelPlain)dialogToReturn;
            await dialog.SendMedia(media);
        }
Пример #10
0
        public void Should_Serialize_Input_Media_Url()
        {
            const string url        = "http://github.org/TelgramBots";
            InputMedia   inputMedia = url;

            string     json = JsonConvert.SerializeObject(inputMedia);
            InputMedia obj  = JsonConvert.DeserializeObject <InputMedia>(json);

            Assert.Equal($@"""{url}""", json);
            Assert.Equal(url, obj.Url);
            Assert.Equal(FileType.Url, obj.FileType);
            Assert.Null(obj.Content);
            Assert.Null(obj.FileName);
            Assert.Null(obj.FileId);
        }
Пример #11
0
        public void Should_Serialize_Input_Media_File_Id()
        {
            const string fileId     = "This-is-a-file_id";
            InputMedia   inputMedia = fileId;

            string     json = JsonConvert.SerializeObject(inputMedia);
            InputMedia obj  = JsonConvert.DeserializeObject <InputMedia>(json);

            Assert.Equal($@"""{fileId}""", json);
            Assert.Equal(fileId, obj.FileId);
            Assert.Equal(FileType.Id, obj.FileType);
            Assert.Null(obj.Content);
            Assert.Null(obj.FileName);
            Assert.Null(obj.Url);
        }
Пример #12
0
        public void Should_Serialize_Input_Media_Stream()
        {
            const string fileName   = "myFile";
            InputMedia   inputMedia = new InputMedia(new MemoryStream(), fileName);

            string     json = JsonConvert.SerializeObject(inputMedia);
            InputMedia obj  = JsonConvert.DeserializeObject <InputMedia>(json);

            Assert.Equal($@"""attach://{fileName}""", json);
            Assert.Equal(Stream.Null, obj.Content);
            Assert.Equal(fileName, obj.FileName);
            Assert.Equal(FileType.Stream, obj.FileType);
            Assert.Null(obj.FileId);
            Assert.Null(obj.Url);
        }
Пример #13
0
        public void Should_Serialize_Input_Media_Stream()
        {
            const string fileName   = "myFile";
            InputMedia   inputMedia = new InputMedia(new MemoryStream(), fileName);

            string     json = JsonSerializer.Serialize(inputMedia, new JsonSerializerOptions(JsonSerializerDefaults.Web));
            InputMedia obj  = JsonSerializer.Deserialize <InputMedia>(json, new JsonSerializerOptions(JsonSerializerDefaults.Web));

            Assert.Equal($@"""attach://{fileName}""", json);
            Assert.Equal(Stream.Null, obj.Content);
            Assert.Equal(fileName, obj.FileName);
            Assert.Equal(FileType.Stream, obj.FileType);
            Assert.Null(obj.FileId);
            Assert.Null(obj.Url);
        }
Пример #14
0
        public void Should_Serialize_Input_Media_Url()
        {
            const string url        = "http://github.org/TelgramBots";
            InputMedia   inputMedia = url;

            string     json = JsonSerializer.Serialize(inputMedia, new JsonSerializerOptions(JsonSerializerDefaults.Web));
            InputMedia obj  = JsonSerializer.Deserialize <InputMedia>(json, new JsonSerializerOptions(JsonSerializerDefaults.Web));

            Assert.Equal($@"""{url}""", json);
            Assert.Equal(url, obj.Url);
            Assert.Equal(FileType.Url, obj.FileType);
            Assert.Null(obj.Content);
            Assert.Null(obj.FileName);
            Assert.Null(obj.FileId);
        }
Пример #15
0
        public void Should_Serialize_Input_Media_File_Id()
        {
            const string fileId     = "This-is-a-file_id";
            InputMedia   inputMedia = fileId;

            string     json = JsonSerializer.Serialize(inputMedia, new JsonSerializerOptions(JsonSerializerDefaults.Web));
            InputMedia obj  = JsonSerializer.Deserialize <InputMedia>(json, new JsonSerializerOptions(JsonSerializerDefaults.Web));

            Assert.Equal($@"""{fileId}""", json);
            Assert.Equal(fileId, obj.FileId);
            Assert.Equal(FileType.Id, obj.FileType);
            Assert.Null(obj.Content);
            Assert.Null(obj.FileName);
            Assert.Null(obj.Url);
        }
Пример #16
0
        public Task <Message> SendAudioAsync(
            ChatId chatId,
            InputOnlineFile audio,
            string caption                      = null,
            ParseMode parseMode                 = ParseMode.Default,
            int duration                        = 0,
            string performer                    = null,
            string title                        = null,
            bool disableNotification            = false,
            int replyToMessageId                = 0,
            IReplyMarkup replyMarkup            = null,
            CancellationToken cancellationToken = new CancellationToken(),
            InputMedia thumb                    = null)
        {
            _logger.LogInformation("Sending audio with url: {} and caption: {}", audio.Url, caption);

            return(Task.FromResult(new Message()));
        }
Пример #17
0
        public async Task SendAsync(MessageInfo message, Audio audio)
        {
            _logger.LogInformation("Sending audio message");

            var inputOnlineFile = new InputMedia(
                await _httpClient.GetStreamAsync(audio.Url, message.CancellationToken),
                "Audio");

            await _client.SendAudioAsync(
                chatId : message.ChatId,
                audio : inputOnlineFile,
                duration : audio.Duration?.Seconds ?? default,
                performer : audio.Artist,
                title : audio.Title,
                parseMode : TelegramConstants.MessageParseMode,
                replyToMessageId : message.ReplyMessageId,
                cancellationToken : message.CancellationToken
                );
        }
Пример #18
0
        public Task <Message> SendVideoAsync(
            ChatId chatId,
            InputOnlineFile video,
            int duration                        = 0,
            int width                           = 0,
            int height                          = 0,
            string caption                      = null,
            ParseMode parseMode                 = ParseMode.Default,
            bool supportsStreaming              = false,
            bool disableNotification            = false,
            int replyToMessageId                = 0,
            IReplyMarkup replyMarkup            = null,
            CancellationToken cancellationToken = new CancellationToken(),
            InputMedia thumb                    = null)
        {
            _logger.LogInformation("Sending video with url: {} and caption: {}", video.Url, caption);

            return(Task.FromResult(new Message()));
        }
Пример #19
0
        private async ValueTask <IAlbumInputMedia> ToAlbumInputMediaAsync(MessageInfo message, IMedia media)
        {
            InputMedia inputMedia = await GetInputMediaAsync(message, media);

            switch (media)
            {
            case Video v:
                var video = new InputMediaVideo(inputMedia)
                {
                    SupportsStreaming = true
                };

                if (v.ThumbnailUrl != null)
                {
                    video.Thumb = new InputMedia(
                        await _httpClient.GetStreamAsync(v.ThumbnailUrl, message.CancellationToken),
                        "Thumbnail");
                }

                if (v.Duration?.Seconds != null)
                {
                    video.Duration = (int)v.Duration?.Seconds;
                }
                if (v.Width != null)
                {
                    video.Width = (int)v.Width;
                }
                if (v.Height != null)
                {
                    video.Height = (int)v.Height;
                }

                return(video);

            default:
                return(new InputMediaPhoto(inputMedia));
            }
        }
Пример #20
0
 IMenuAudioThumbnail IMenuAudioOptionalBuilder.Thumbnail(InputMedia thumbnail)
 {
     Thumbnail = thumbnail; return(this);
 }
Пример #21
0
 IMenuAudioThumbnail IMenuAudioReplyMarkup.Thumbnail(InputMedia thumbnail)
 {
     Thumbnail = thumbnail; return(this);
 }
Пример #22
0
 IMenuAudioThumbnail IMenuAudioOptionalBuilder.Thumbnail(Stream content, string fileName)
 {
     Thumbnail = new InputMedia(content, fileName); return(this);
 }
Пример #23
0
 IMenuAudioThumbnail IMenuAudioPerformer.Thumbnail(InputMedia thumbnail)
 {
     Thumbnail = thumbnail; return(this);
 }
Пример #24
0
 IMenuAudioThumbnail IMenuAudioReplyMarkup.Thumbnail(Stream content, string fileName)
 {
     Thumbnail = new InputMedia(content, fileName); return(this);
 }
Пример #25
0
 IMenuAudioThumbnail IMenuAudioParseMode.Thumbnail(InputMedia thumbnail)
 {
     Thumbnail = thumbnail; return(this);
 }
Пример #26
0
 IMenuAudioThumbnail IMenuAudioPerformer.Thumbnail(Stream content, string fileName)
 {
     Thumbnail = new InputMedia(content, fileName); return(this);
 }
Пример #27
0
 IMenuAudioThumbnail IMenuAudioDisableNotification.Thumbnail(InputMedia thumbnail)
 {
     Thumbnail = thumbnail; return(this);
 }
Пример #28
0
 IMenuAudioThumbnail IMenuAudioDuration.Thumbnail(InputMedia thumbnail)
 {
     Thumbnail = thumbnail; return(this);
 }
Пример #29
0
 IMenuAudioThumbnail IMenuAudioDisableNotification.Thumbnail(Stream content, string fileName)
 {
     Thumbnail = new InputMedia(content, fileName); return(this);
 }
Пример #30
0
 IMenuAudioThumbnail IMenuAudioCancellationToken.Thumbnail(InputMedia thumbnail)
 {
     Thumbnail = thumbnail; return(this);
 }
Пример #31
0
        public async Task SendMedia(InputMedia media) {
            try {
                long randomId = Helpers.GenerateRandomLong();

                // PHOTO IS HERE
                MessageModelUndelivered undeliveredMessage = new MessageModelUndelivered() {
                    MessageType = MessageModelUndelivered.Type.Text,
                    Text = "",
                    Timestamp = DateTime.Now,
                    RandomId = randomId
                };

                ProcessNewMessage(undeliveredMessage);

                messages_StatedMessage sentMessage =
                    await session.Api.messages_sendMedia(InputPeer, media, randomId);

                Message message;
                int pts, seq;
                if (sentMessage.Constructor == Constructor.messages_statedMessage) {
                    Messages_statedMessageConstructor sentMessageConstructor =
        (Messages_statedMessageConstructor)sentMessage;

                    session.Updates.ProcessChats(sentMessageConstructor.chats);
                    session.Updates.ProcessUsers(sentMessageConstructor.users);

                    pts = sentMessageConstructor.pts;
                    seq = sentMessageConstructor.seq;
                    message = sentMessageConstructor.message;
                    
                } else if (sentMessage.Constructor == Constructor.messages_statedMessageLink) {
                    Messages_statedMessageLinkConstructor statedMessageLink =
                        (Messages_statedMessageLinkConstructor) sentMessage;

                    session.Updates.ProcessChats(statedMessageLink.chats);
                    session.Updates.ProcessUsers(statedMessageLink.users);
                    // TODO: process links

                    pts = statedMessageLink.pts;
                    seq = statedMessageLink.seq;
                    message = statedMessageLink.message;
                }
                else {
                    logger.error("unknown messages_StatedMessage constructor");
                    return;
                }

                if (!session.Updates.processUpdatePtsSeq(pts, seq)) {
                    logger.error("send media process updates failed");
                    messages.Remove(undeliveredMessage);
                    return;
                }

                TelegramSession.Instance.Dialogs.Model.UpDialog(this);

                int messageIndex = messages.IndexOf(undeliveredMessage);
                if (messageIndex != -1) {
                    MessageModel messageModel = new MessageModelDelivered(message);
                    MessageModelDelivered newMessage = (MessageModelDelivered)messageModel;
                    var selectedMessages = from msg in messages
                                            where msg is MessageModelDelivered && ((MessageModelDelivered)msg).Id == messageModel.Id
                                            select msg;
                    if (selectedMessages.Any()) {
                        messages.RemoveAt(messageIndex);
                    } else { 
                        messages[messageIndex] =
                            new MessageModelDelivered(message);
                    }
                } else {
                    logger.error("not found undelivered message to confirmation");
                }

            }
            catch (Exception ex) {
                logger.error("Error sending media {0}", ex);
            }
        }
Пример #32
0
 public Message_SendMediaRequest(InputPeer inputPeer, InputMedia inputMedia)
 {
     this.inputPeer = inputPeer;
     this.inputMedia = inputMedia;
 }
Пример #33
0
        public async Task<messages_StatedMessage> SendMediaMessage(InputPeer inputPeer, InputMedia inputMedia)
        {
            var request = new Message_SendMediaRequest(inputPeer, inputMedia);
            await _sender.Send(request);
            await _sender.Recieve(request);

            return request.StatedMessage;
        }