示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Attachment"/> class.
        /// </summary>
        /// <param name="attachment">The attachment.</param>
        /// <param name="message">The message the attachment belongs to.</param>
        public Attachment(ChatMessageAttachment attachment, Message message)
        {
            GroupId          = attachment.GroupId;
            MimeType         = attachment.MimeType;
            OriginalFileName = attachment.OriginalFileName;
            Text             = attachment.Text;
            TransferProgress = attachment.TransferProgress;
            Id = $"{message.Id}-{attachment.GroupId}-{attachment.MimeType}-{attachment.OriginalFileName}";

            _Attachment = attachment;
        }
示例#2
0
        public async void Send(string phoneNumber, string messageBody, StorageFile attachmentFile, string mimeType)
        {
            var chat = new ChatMessage {
                Body = messageBody
            };

            if (attachmentFile != null)
            {
                var stream = RandomAccessStreamReference.CreateFromFile(attachmentFile);

                var attachment = new ChatMessageAttachment(mimeType, stream);

                chat.Attachments.Add(attachment);
            }

            chat.Recipients.Add(phoneNumber);

            await ChatMessageManager.ShowComposeSmsMessageAsync(chat);
        }
示例#3
0
        public async void Send(string phoneNumber,
            string messageBody,
            StorageFile attachmentFile,
            string mimeType)
        {
            var chat = new ChatMessage {Body = messageBody};

            if (attachmentFile != null)
            {
                var stream = RandomAccessStreamReference.CreateFromFile(attachmentFile);

                var attachment = new ChatMessageAttachment(
                    mimeType,
                    stream);

                chat.Attachments.Add(attachment);
            }

            chat.Recipients.Add(phoneNumber);

            await ChatMessageManager.ShowComposeSmsMessageAsync(chat);
        }
示例#4
0
        public async Task <ServiceResponse <object> > SendGroupMessage(GroupMessageForAddDto model)
        {
            var ToAdd = new GroupMessage
            {
                Comment           = model.Comment,
                MessageToUserIds  = string.Join(',', model.MessageToUserIds),
                IsRead            = false,
                CreatedDateTime   = DateTime.UtcNow,
                MessageFromUserId = _LoggedIn_UserID,
                MessageReplyId    = model.MessageReplyId,
                GroupId           = model.GroupId,
            };
            await _context.GroupMessages.AddAsync(ToAdd);

            await _context.SaveChangesAsync();

            if (model.files != null && model.files.Count() > 0)
            {
                for (int i = 0; i < model.files.Count(); i++)
                {
                    var dbPath     = _fileRepo.SaveFile(model.files[i]);
                    var attachment = new ChatMessageAttachment
                    {
                        MessageId      = ToAdd.Id,
                        AttachmentPath = dbPath,
                        FileName       = model.files[i].FileName != "blob" ? model.files[i].FileName : "",
                        FileType       = model.files[i].FileName != "blob" ? "FileAttachment" : ""
                    };
                    await _context.ChatMessageAttachments.AddAsync(attachment);

                    await _context.SaveChangesAsync();
                }
            }

            _serviceResponse.Success = true;
            _serviceResponse.Message = CustomMessage.Added;
            return(_serviceResponse);
        }
示例#5
0
        public async void Run()
        {
            var authProvider = await Login();

            var client = new GraphServiceClient(authProvider);

            //var drives = await client.Drives.Request().GetAsync();
            //foreach (var drive in drives)
            //{
            //	Console.WriteLine(drive.Name);
            //}

            //var mydrive = await client.Me.Drive.Request().GetAsync();

            //var root = await client.Me.Drive.Root.Request().GetAsync();
            //var children = await client.Me.Drive.Root.Children.Request().GetAsync();
            //foreach (var child in children)
            //{
            //	Console.WriteLine(child.Name);
            //}

            var folderItem = new DriveItem
            {
                Name   = "uploads",
                Folder = new Folder
                {
                },
                AdditionalData = new Dictionary <string, object>()
                {
                    { "@microsoft.graph.conflictBehavior", "replace" }
                }
            };
            var folder = await client.Me.Drive.Root.Children.Request().AddAsync(folderItem);

            var filename = System.IO.Path.GetRandomFileName();

            DriveItem uploadedItem = null;

            using (var stream = new System.IO.MemoryStream(new byte[1024 * 10]))
            {
                var uploadSession = await client.Me.Drive.Items[folder.Id].ItemWithPath(filename).CreateUploadSession().Request().PostAsync();

                var maxChunkSize = 320 * 1024;                 // 320 KB - Change this to your chunk size. 5MB is the default.
                var provider     = new ChunkedUploadProvider(uploadSession, client, stream, maxChunkSize);

                uploadedItem = await provider.UploadAsync();
            }

            //var me = await client.Me.Request().GetAsync();

            //var url = client.Me.JoinedTeams.RequestUrl;

            //var teams = await client.Me.JoinedTeams.Request().GetAsync();
            //foreach (var team in teams)
            //{
            //	Console.WriteLine(team.Id);
            //}

            //var channels = await client.Teams["9aa92ac0-e14e-4f5c-9748-da145c061844"].Channels.Request().GetAsync();
            //foreach (var channel in channels)
            //{
            //	Console.WriteLine(channel.Id);
            //}

            var fileGuid = Guid.NewGuid();

            var chatMessage = new ChatMessage
            {
                Body = new ItemBody
                {
                    Content = "Hello world <attachment id=\"" + fileGuid.ToString() + "\"></attachment>"
                }
            };

            var attachments = new ChatMessageAttachment[]
            {
                new ChatMessageAttachment
                {
                    Id          = fileGuid.ToString(),
                    ContentType = "reference",
                    ContentUrl  = uploadedItem.WebUrl,
                    Name        = uploadedItem.Name,
                }
            };

            chatMessage.Attachments = attachments;

            var teamId    = "9aa92ac0-e14e-4f5c-9748-da145c061844";
            var channelId = "19:[email protected]";

            await client.Teams[teamId].Channels[channelId].Messages
            .Request()
            .AddAsync(chatMessage);

            Console.WriteLine(uploadedItem.WebUrl);
        }
示例#6
0
 /// <summary>
 /// Parse a <see cref="ChatMessageAttachment" /> into <see cref="Attachment" />.
 /// </summary>
 /// <param name="attachment">The attachment.</param>
 /// <param name="message">The message the attachment belongs to.</param>
 /// <returns></returns>
 public static Attachment Parse(ChatMessageAttachment attachment, Message message)
 {
     return(new Attachment(attachment, message));
 }