-
Notifications
You must be signed in to change notification settings - Fork 119
Add cloudflare environment. #229
base: master
Are you sure you want to change the base?
Conversation
The environment means the environment in which the code will be executed. How can cloudflare be an environment? Can you please provide the full context? |
@alik0211 So Cloudflare provides a serverless service called Cloudflare Workers. It behaves similar to JavaScript in the browser or in Node.js and under the hood, the Workers runtime uses the V8 engine, but there are some differences (e. g. WebSockets). You can read more how Workers works here if you interested in. I spent a few days trying to understand and get it to work with Cloudflare Workers, thought it would be helpful for anyone looking to use mtproto with Workers. |
@Legend1991 is your fork working with cloudflare worker? |
@numairawan yes it is. I'm using it for my project currently. That was the main purpose. |
I am trying to use in worker from last 5 days but failing. Can you please give example or your main file of mtprot-core or the worker if possible. I tried to browserify the mtproto but still its not working. |
Sure. I have telegram.js file that describes telegram api that I'm using:
Here I use Cloudflare KV storage (TELEGRAM_KV) and it looks like this: So you need to sign in first to get those data.
|
Let me know if you are available. The only reason why i asked you to install it for me is, I am not understanding how you are using mtproto-core api in cloudflare worker. You cant add files and you can also not use require in cf workers. I tried to browserify the mtproto-core but its not working because mtproto-core browser using the some browser function like windows, localstorage etc that don't work in cf worker. |
@numairawan to be able to use require in cf workers you need to use Cloudflare's CLI called Wrangler. |
@numairawan that's because "../builder" and "../parser" are generated by npm's prepublishOnly script. mtproto-cloudflare/index.js content:
and mtproto-cloudflare/transport.js content:
Then change the first require in telegram.js file to Now this should work. |
@Legend1991 thanks its working now. |
@Legend1991 sorry for the mention. But does this allow me use mtproto proxy on telegram on a cloudflare worker? If yes can you explain it a bit? |
I ran into this PR and observed that the Cloudflare Workers runtime environment supports the implementation of MTProto within the browser environment now. Maybe this changed sometime recently? Not sure if the PR is needed anymore. |
Cloudflare has its own way to work with WebSockets. Turns out to make it work you have to handle the handshaking process yourself using HTTP Upgrade mechanism. Actually it is the only difference from browser implementation.