示例#1
0
        private void SendFile(VisualBubble bubble, IInputFile inputFile)
        {
            var inputPeer = GetInputPeer(bubble.Address, bubble.Party, bubble.ExtendedParty);
            var imageBubble = bubble as ImageBubble;
            var fileBubble = bubble as FileBubble;
            var audioBubble = bubble as AudioBubble;

            using (var client = new FullClientDisposable(this))
            {
                if (imageBubble != null)
                {

                    var iUpdates = TelegramUtils.RunSynchronously(
                        client.Client.Methods.MessagesSendMediaAsync(new MessagesSendMediaArgs
                        {

                            Flags = 0,
                            Peer = inputPeer,
                            Media = new InputMediaUploadedPhoto
                            {
                                Caption = "",
                                File = inputFile,
                            },
                            RandomId = GenerateRandomId(),
                        }));
                    var messageId = GetMessageId(iUpdates);
                    imageBubble.IdService = messageId;
                    var updates = iUpdates as Updates;

                    SendToResponseDispatcher(iUpdates, client.Client);
                }
                else if (fileBubble != null)
                {
                    var documentAttributes = new List<IDocumentAttribute>
                    {
                        new DocumentAttributeFilename
                        {
                            FileName = fileBubble.FileName
                        }
                    };
                    var iUpdates = TelegramUtils.RunSynchronously(
                        client.Client.Methods.MessagesSendMediaAsync(new MessagesSendMediaArgs
                        {

                            Flags = 0,
                            Peer = inputPeer,
                            Media = new InputMediaUploadedDocument
                            {
                                Attributes = documentAttributes,
                                Caption = "",
                                File = inputFile,
                                MimeType = fileBubble.MimeType,
                            },
                            RandomId = GenerateRandomId(),
                        }));
                    var messageId = GetMessageId(iUpdates);
                    fileBubble.IdService = messageId;
                    SendToResponseDispatcher(iUpdates, client.Client);

                }
                else if (audioBubble != null)
                {
                    var documentAttributes = new List<IDocumentAttribute>();

                    if (audioBubble.Recording)
                    {
                        documentAttributes.Add(new DocumentAttributeAudio
                        {
                            Flags = 1024,
                            Duration = (uint)audioBubble.Seconds,
                            Voice = new True()
                        });
                    }
                    else if (audioBubble.FileName != null)
                    {
                        documentAttributes.Add(new DocumentAttributeAudio
                        {
                            Flags = 1,
                            Duration = (uint)audioBubble.Seconds,
                            Title = audioBubble.FileName
                        });
                    }
                    else 
                    {
                        documentAttributes.Add(new DocumentAttributeAudio
                        {
                            Flags = 0,
                            Duration = (uint)audioBubble.Seconds
                        });
                    }

                    var mimeType = Platform.GetMimeTypeFromPath(audioBubble.AudioPath);
                    var inputMedia = new InputMediaUploadedDocument
                    {
                        Attributes = documentAttributes,
                        Caption = "",
                        File = inputFile,
                        MimeType = mimeType,
                    };

                    var media = new MessagesSendMediaArgs
                    {
                        Flags = 0,
                        Media = inputMedia,
                        Peer = inputPeer,
                        RandomId = GenerateRandomId(),
                    };
                    var iUpdates = TelegramUtils.RunSynchronously(
                        client.Client.Methods.MessagesSendMediaAsync(media));
                    var messageId = GetMessageId(iUpdates);
                    audioBubble.IdService = messageId;
                    SendToResponseDispatcher(iUpdates, client.Client);
                }
            }
        }
 public Task<IMessagesStatedMessage> MessagesSendMediaAsync(MessagesSendMediaArgs args)
 {
     return _remoteProcedureCaller.RpcAsync<IMessagesStatedMessage>(args);
 }