hlf20010508 / telegram-onedrive

A Telegram Bot to transfer files to OneDrive. No file size limitation. Restricted content supported. Doesn't occupy local space.
MIT License
49 stars 28 forks source link

Error sending files #4

Closed Zriel88 closed 1 year ago

Zriel88 commented 1 year ago

Managed to get it running and authenticated both in TG and Onedrive, however, upon sending a file into a group with the bot there.

Error: Traceback (most recent call last): File "/telegram-onedrive/modules/handlers/transfer.py", line 27, in transfer_handler if message.media: AttributeError: 'NoneType' object has no attribute 'media'

Also, had to change the azure web app manifest: "signInAudience": "AzureADandPersonalMicrosoftAccount",

because I was getting 172.18.0.4 - - [16/Oct/2023 15:16:30] "GET /auth?error=invalid_request&error_description=The%20request%20is%20not%20valid%20for%20the%20application's%20'userAudience'%20configuration.%20In%20order%20to%20use%20/common/%20endpoint,%20the%20application%20must%20not%20be%20configured%20with%20'Consumer'%20as%20the%20user%20audience.%20The%20userAudience%20should%20be%20configured%20with%20'All'%20to%20use%20/common/%20endpoint. HTTP/1.1" 200

https://stackoverflow.com/questions/63924098/is4-request-not-valid-for-the-applications-useraudience-configuration

hlf20010508 commented 1 year ago

Hi.

What kind of file did you send? Can you forward a video or picture successfully?

And what account did you use to login to onedrive? Are you using personal account?

Zriel88 commented 1 year ago

a jpg and a mp4. same error for both. Neither sending a file to the group directly, neither forwarding a message. My personal account. Altough is really old and as said, it didn't let me with the standard "PersonalMicrosoftAccount".

Zriel88 commented 1 year ago

Also, for sending /url

Please offer a message link.

Use /help for available command.

On docker log

Unhandled exception on wrapper
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/telethon/client/updates.py", line 570, in _dispatch_update
    await callback(event)
  File "/telegram-onedrive/modules/utils.py", line 92, in wrapper
    return await func(event, *args, **kwargs)
  File "/telegram-onedrive/modules/utils.py", line 103, in wrapper
    return await func(event, *args, **kwargs)
  File "/telegram-onedrive/modules/handlers/url.py", line 36, in url_handler
    status_message = await Status_Message.create(event)
  File "/telegram-onedrive/modules/utils.py", line 25, in create
    self.msg_link = '[Status:](https://t.me/c/%d/%d)' % (self.event.message.peer_id.channel_id, self.event.message.id)
AttributeError: 'PeerChat' object has no attribute 'channel_id'
Zriel88 commented 1 year ago

Entering the Azure AAD is giving me an error AADSTS16000 i'm going to try to solve that (and authenticate with the "PersonalMicrosoftAccount" on the manifest)

hlf20010508 commented 1 year ago

That's so wierd.

I need more informations.

What's your platform and telegram version?

Zriel88 commented 1 year ago

I fixed the auth error updating azure to a trial subscription. However I still get the same error for authenticating if I use "PersonalMicrosoftAccount".

Regarding your question, I use telegram on Android and Windows PC, latest version.

172.18.0.4 - - [17/Oct/2023 10:30:27] "GET /auth?error=invalid_request&error_description=The%20request%20is%20not%20valid%20for%20the%20application's%20'userAudience'%20configuration.%20In%20order%20to%20use%20/common/%20endpoint,%20the%20application%20must%20not%20be%20configured%20with%20'Consumer'%20as%20the%20user%20audience.%20The%20userAudience%20should%20be%20configured%20with%20'All'%20to%20use%20/common/%20endpoint. HTTP/1.1" 200 -

hlf20010508 commented 1 year ago

I've tested on Windows 10, it works fine.

And the interesting thing is, in your error:

Unhandled exception on wrapper
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/telethon/client/updates.py", line 570, in _dispatch_update
    await callback(event)
  File "/telegram-onedrive/modules/utils.py", line 92, in wrapper
    return await func(event, *args, **kwargs)
  File "/telegram-onedrive/modules/utils.py", line 103, in wrapper
    return await func(event, *args, **kwargs)
  File "/telegram-onedrive/modules/handlers/url.py", line 36, in url_handler
    status_message = await Status_Message.create(event)
  File "/telegram-onedrive/modules/utils.py", line 25, in create
    self.msg_link = '[Status:](https://t.me/c/%d/%d)' % (self.event.message.peer_id.channel_id, self.event.message.id)
AttributeError: 'PeerChat' object has no attribute 'channel_id'

It said it's a PeerChat object. But in all my tests, no matter whether it was in group or channel, the object type was always PeerChannel. I don't know what's wrong, because if I can't find a group recognized as PeerChat, I can't replicate your error to fix it.

Zriel88 commented 1 year ago

OK. Don't know what I did but it is fixed now. I created a new group without adding the bot. Then I added the bot. Now it can upload files over url and fles over redirection from another chat, or adding them to the chat. I'm gonna test over a channel now

Zriel88 commented 1 year ago

It doesn't work over a channel It doesn't say a thing, doesn't answer to commands...

hlf20010508 commented 1 year ago

Yes, you're right. That's a historical problem, in the early version the logic is different, so now it doesn't support channel any more, but I forget it.

I'll adjust the instruction later.

wangkingsten commented 1 year ago

the same error 1.onedrive seems not allow to use '/common/' to auth,i have to use /tenant ID/ 2.Error: Traceback (most recent call last): File "/telegram-onedrive/modules/handlers/transfer.py", line 33, in transfer_handler await multi_parts_uploader(tg_client, message.media.document, name, progress_callback=callback) File "/telegram-onedrive/modules/transfer.py", line 36, in multi_parts_uploader upload_session = onedrive.multipart_upload_session_builder(name) File "/telegram-onedrive/modules/onedrive.py", line 97, in multipart_upload_session_builder session = self.client.item(path=self.remote_root_path).children[name].create_session(item).post() File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request/item_create_session.py", line 106, in post return self.request().post() File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request/item_create_session.py", line 60, in post entity = UploadSession(json.loads(self.send(self.body_options).content)) File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request_base.py", line 132, in send self._client.auth_provider.authenticate_request(self) File "/telegram-onedrive/modules/onedrive.py", line 26, in authenticate_request raise RuntimeError("""Session must be authenticated RuntimeError: Session must be authenticated before applying authentication to a request.

hlf20010508 commented 1 year ago

the same error 1.onedrive seems not allow to use '/common/' to auth,i have to use /tenant ID/ 2.Error: Traceback (most recent call last): File "/telegram-onedrive/modules/handlers/transfer.py", line 33, in transfer_handler await multi_parts_uploader(tg_client, message.media.document, name, progress_callback=callback) File "/telegram-onedrive/modules/transfer.py", line 36, in multi_parts_uploader upload_session = onedrive.multipart_upload_session_builder(name) File "/telegram-onedrive/modules/onedrive.py", line 97, in multipart_upload_session_builder session = self.client.item(path=self.remote_root_path).children[name].create_session(item).post() File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request/item_create_session.py", line 106, in post return self.request().post() File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request/item_create_session.py", line 60, in post entity = UploadSession(json.loads(self.send(self.body_options).content)) File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request_base.py", line 132, in send self._client.auth_provider.authenticate_request(self) File "/telegram-onedrive/modules/onedrive.py", line 26, in authenticate_request raise RuntimeError("""Session must be authenticated RuntimeError: Session must be authenticated before applying authentication to a request.

Are you using personal account or business account or developer account?

What do you mean of using /tenant ID/?

hlf20010508 commented 1 year ago

I don't familiar with Microsoft's account management, maybe there are more than one account type.

Try recreating your app in azure portal and set Supported account types to All Microsoft account users.

Or edit your app's Manifest, set item "signInAudience": "PersonalMicrosoftAccount" to "signInAudience": "AzureADandPersonalMicrosoftAccount".

If this works, I'll edit the instruction in README.md

wangkingsten commented 1 year ago

OneDrive for Business. when i auth the onedrive,it alert: AADSTS50194: Application 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx' is not configured as a multi-tenant application. Usage of the /common endpoint is not supported for such applications created after '10/15/2018'. Use a tenant-specific endpoint or configure the application to be multi-tenant.

the auth url is: https://login.microsoftonline.com**/common/**oauth2/v2.0/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx&response_type=code&redirect_uri=https://127.0.0.1:8080%2Fauth&scope=offline_access+Files.ReadWrite

i have to change the '/common' to '/tenant id'. tenant id can be find together with od_client_id. and it works. the onedrive can auth.

Traceback (most recent call last) error still bothering me.

hlf20010508 commented 1 year ago

@wangkingsten Ok, have you tried this?

I don't familiar with Microsoft's account management, maybe there are more than one account type.

Try recreating your app in azure portal and set Supported account types to All Microsoft account users.

Or edit your app's Manifest, set item "signInAudience": "PersonalMicrosoftAccount" to "signInAudience": "AzureADandPersonalMicrosoftAccount".

If this works, I'll edit the instruction in README.md

I don't have a business account, so I can't test it. If it works, I won't have to change my code.

wangkingsten commented 1 year ago

AzureADandPersonalMicrosoftAccount

it works for auth but still Error

Error: Traceback (most recent call last): File "/telegram-onedrive/modules/handlers/transfer.py", line 33, in transfer_handler await multi_parts_uploader(tg_client, message.media.document, name, progress_callback=callback) File "/telegram-onedrive/modules/transfer.py", line 36, in multi_parts_uploader upload_session = onedrive.multipart_upload_session_builder(name) File "/telegram-onedrive/modules/onedrive.py", line 97, in multipart_upload_session_builder session = self.client.item(path=self.remote_root_path).children[name].create_session(item).post() File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request/item_create_session.py", line 106, in post return self.request().post() File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request/item_create_session.py", line 60, in post entity = UploadSession(json.loads(self.send(self.body_options).content)) File "/usr/local/lib/python3.8/site-packages/onedrivesdk/request_base.py", line 132, in send self._client.auth_provider.authenticate_request(self) File "/telegram-onedrive/modules/onedrive.py", line 26, in authenticate_request raise RuntimeError("""Session must be authenticated RuntimeError: Session must be authenticated before applying authentication to a request.

wangkingsten commented 1 year ago

ubuntu 22.04 x86_64

hlf20010508 commented 1 year ago

@wangkingsten Oh, sorry, I forgot it.

My project doesn't support business account yet, see #5.

hlf20010508 commented 1 year ago

This bot is self use, that's why I never consider business account or even developer account. Therefore I can't test it with those account types. Pull requests are welcome.

wangkingsten commented 1 year ago

OK. Don't know what I did but it is fixed now. I created a new group without adding the bot. Then I added the bot. Now it can upload files over url and fles over redirection from another chat, or adding them to the chat. I'm gonna test over a channel now

HOW TO FIX

wangkingsten commented 1 year ago

This bot is self use, that's why I never consider business account or even developer account. Therefore I can't test it with those account types. Pull requests are welcome.

This bot is self use, that's why I never consider business account or even developer account. Therefore I can't test it with those account types. Pull requests are welcome.

原谅我直接用中文交流了哈,我的onedrive是在拼多多买的,我问了一下应该卖家是教育版A1pro。