Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
313 stars 44 forks source link

can't send attachment in private chat #87

Closed feddelegrand7 closed 3 years ago

feddelegrand7 commented 3 years ago

Hi, it's me again sorry ^^

I'm trying to send an image within a private chat (not a channel) using the following code:

chat <- Microsoft365R::get_chat("some_chat_id")
chat$send_message(
  body = "hello world", 
  attachments = "image.png"
)

Nevertheless, I'm receiving the following Error:

Error in channel$upload_file(f, dest = basename(f)) : 
  attempt to apply non-function

Maybe the problem arises from the fact that we're trying to apply a method from "ms_channel" while we're dealing with an "ms_chat" object?

Best.

hongooi73 commented 3 years ago

Unfortunately the process for sending file attachments in a chat isn't very well-documented. I also don't have a tenant where I can test this easily.

When you send an attachment using the regular Teams client, do you know where it saves the file? Here, it ends up in my business OneDrive under a folder called "Microsoft Teams Chat Files".

hongooi73 commented 3 years ago

I have a fix in the 'chat-attachments' branch, can you try that?

feddelegrand7 commented 3 years ago

Hi @hongooi73 thank you for your prompt response.

When I send a png file for example with a client it is saved in the Files tab of the chat. Unfortunately, I'm working on a server that only allows me to install R packages from CRAN. Therefore, I can't test the new branch sorry :/

Best. Fodil.

hongooi73 commented 3 years ago

I've uploaded the tar.gz. You should be able to install it with devtools::install_local, assuming you're able to download it.

Microsoft365R_2.3.1.9000.tar.gz

feddelegrand7 commented 3 years ago

Thank you @hongooi73 I'll try do it. Btw you were right when I send a file in the teams client it's stored here: Documents/Microsoft Teams Chat Files. Thank again.

hongooi73 commented 3 years ago

Ok, let's just make sure exactly where that folder is located. Run get_business_onedrive() and look for the folder:

od <- get_business_onedrive()
od$list_files()
od$list_files("folder1")
... etc ...

Search through the directories until you find it, and tell me where it is. On my work machine, it's under the root directory.

feddelegrand7 commented 3 years ago

I'm note sure but it seems that it's located in the onedrive of the company:

C:\Users\mihaddaden\OneDrive - CompanyAlpha\Microsoft Teams Chat Files

hongooi73 commented 3 years ago

Ok, now can you run get_business_onedrive() and confirm that for me please.

od <- get_business_onedrive()
od$list_files()

It should show up in the root directory listing.

feddelegrand7 commented 3 years ago

running the above code, I got the following:

image

I don't have any indication about the directory location.

hongooi73 commented 3 years ago

Excellent, thank you. Line 5 above is the directory we're after. Line 6 looks suspicious though -- what does "Chatdateien" translate as?

feddelegrand7 commented 3 years ago

It's Chat Files in German.

hongooi73 commented 3 years ago

Right, so things are a bit more complicated than I thought. It looks like Teams can store the files in different locations depending on your language settings.

For now, I've set Microsoft365R to always save files under the English version--localisation is way above my pay grade....

feddelegrand7 commented 3 years ago

ahhh yes you're absolutely right I think I have changed the language of MSTEAMS in my settings (from German to English), that's why I have now two folders. Should I keep only one (the english version) and remove the other one?

hongooi73 commented 3 years ago

No, just leave them alone. You're not hurting anything by having 2 folders, and deleting one means you'll lose all the attachments inside.

Let me know if you run into problems with the fix.

feddelegrand7 commented 3 years ago

Sure, I'll try the fix asap. Thank you again for your help.

feddelegrand7 commented 3 years ago

Hi @hongooi73, sorry for the delay. I've tested Microsoft365R_2.3.1.9000.tar.gz and it works like a charm, thank you so much again!

hongooi73 commented 3 years ago

Cool! It would be great if you could give the fix a good workout. As said above, I don't have the ability to test this myself so I'm going to need outside help.

feddelegrand7 commented 3 years ago

Sure, I've tested it sofar to send attachment in private Chats and Channels. I've successfully sent csv files, xlsx, docx, png. Everything seems to work perfectly. Do you need a specific test?

hongooi73 commented 3 years ago

Nothing specific right now, just ping me if anything breaks. Thanks!

feddelegrand7 commented 3 years ago

Will do! thank you :)