Giter Club home page Giter Club logo

telegram.link's Introduction

Deprecation Notice

Don’t use this for new projects.
telegram-mtproto is much more advanced and has a better API.

Also check treact. My attempt to write Telegram client in React.js

@goodmind/telegram.link

npm version Build Status Coverage Status Climate Status Dependency Status Sauce Test Status

ALPHA SOFTWARE

Contact me in Telegram @goodmind

###telegram.link is a Telegram API library for

  • Hybrid Mobile Apps (phone and tablet)

  • Desktop Web Apps (standard HTML5 browsers)

  • Server-side Apps (i.e. a Command-Line Interface)

  • Desktop Apps (i.e. as third party module using the NW.js runtime)

telegram.link is an unofficial porting in javascript of the Telegram Application Programming Interface.

telegram.link library enables to write once a client-application (whole or only the communication part) that runs both on mobile and desktop browsers and also on a Node.js server and connect to the Telegram data-centers via standard protocol and API.

Telegram.link in action!

To start with the telegram.link library, you can install and study the Termgram application. Termgram is a terminal client to connect with Telegram and uses all the features currently available in telegram.link. The source code is quite straightforward and you'll be able to take inspiration to build your own application! As soon as a new feature will be available in telegram.link it will be exploited by Termgram.

Project Status

See the project status page on the wiki for the last notes.

Documentation

The api documentation is generated under the doc/ folder.

See the documentation page on the wiki.

Project Architecture

The whole library is split in three projects:

  • @goodmind/telegram.link (this library): is the main project and provides the highest-level interface to communicate with the Telegram data-center. When you write your 'telegram-like-app' you should deal only with this module.

  • @goodmind/telegram-mt-node (dependency): implements the Telegram Mobile Protocol (MTProto), the protocol level to establish a secure communication with the Telegram cloud.

  • @goodmind/telegram-tl-node (dependency): implements the core TypeLanguage types and a TypeBuilder class that writes Type classes and functions in pure javascript parsing TypeLanguage schemas. TypeLanguage types represent the building blocks of the Telegram protocol.

Other direct dependencies

  • get-flow: just yet another Node.js flow control utility, powerful and easy to use

  • get-log: a Node.js logging utility, easy to use and ready for production environment.

  • requirish: a tool for avoiding the ../../../ relative paths problem, includes a browserify-transform to rewrites the require() for browser.

Installation

To get the complete package:

$ git clone --branch=master git://github.com/goodmind/telegram.link.git
$ cd telegram.link
$ npm install

To install the library as dependency for your app (no tests, no docs, no dev files.. only pure code!):

$ cd YourApp
$ npm install --save @goodmind/telegram.link

Unit Testing

You can run unit-test executing the following command in the project-root folder:

$ npm test

About Telegram..

Telegram is a cross-platform messenger whose clients are open source. Telegram users can exchange encrypted and self-destructing messages, photos, videos and documents (all file-types supported). Telegram is officially available for Android and iOS (including tablets and devices without Wi-Fi). Unofficial clients for Windows Phone, as well as a web version, OS X version, Linux version and a Windows desktop client are available from independent developers using the Telegram API (from Wikipedia).

About Node.JS..

Node.js is a cross-platform runtime environment for server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows and Linux with no changes (from Wikipedia).

About the telegram.link logo ..

Logo crafted by Diego Pasquali

License

The project is released under the MIT license

telegram.link's People

Contributors

enricostara avatar goodmind avatar mien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

leonerd wfjsw mzilot

telegram.link's Issues

Phone migrate error

When i try to call sendCode, it return 303 error with message that i should migrate phone to data center 4 : DC_4
Next step, i receive Error: Nonce mismatch when i try to create new client with DC_4

[ERROR] Wed, 11 Jan 2017 22:26:24 GMT  net.HttpConnection Error ENETUNREACH
[ERROR] Wed, 11 Jan 2017 22:26:24 GMT  net.RpcChannel Unable to read: Error: connect ENETUNREACH 2001:0b28:f23f:f005:0000:0000:0000:000a:443 
[ERROR] Wed, 11 Jan 2017 22:26:24 GMT  get-flow.runSeries Exception occurs: Error: Nonce mismatch.
    at createError (/home/mlk/projects/telegramity/node_modules/@goodmind/telegram.link/node_modules/@goodmind/telegram-mt-node/lib/auth/request-pq.js:88:17)
at callback (/home/mlk/projects/telegramity/node_modules/@goodmind/telegram.link/node_modules/@goodmind/telegram-mt-node/lib/auth/request-pq.js:42:26)
....

It seems it can't connect to DC_4.
Do you have a test application like termgram to test your forked telegram.link?
@goodmind

A few API calls don't return `Promise`s

The methods that just wrap over-the-wire API calls (e.g. those in messages or contacts) return Promise instances, making it generally easier to use the object. A few of them don't, though. It would be nice if they did too, for consistency.

So far the ones I've found that don't and I have to wrap, are

createClient
createAuthKey
getDataCenters

INPUT_FETCH_ERROR

Fix roadmap

  • reset to original schema
  • hard reset goodmind/telegram-tl-node
  • try to send phone code

This is because I don't know how to serialize/deserialize flags (already looked at TLSharp and Telethon and have no idea)

Updates contained in Gzipped messages aren't emitted

If I receive update-style messages from Telegram in the body of a Gzip_packed message, those don't hit the event emitted.

I believe this is because in EncryptedRpcChannel, this._parser.parse() is not invoked a second time on such a body.

I don't know the correct solution to this; I can see two possible ideas:

  1. Extend the parse method in message-parser.js to unzip and walk into the contents of such a message.
  2. Make a second call to this._parser.parse in encrypted-rpc-channel.js after unzipping.

No result

Hi,
I'm giving below logs and pause working when call every api method after auth such as sendCode and getDatacenters.

[INFO] Tue, 10 Jan 2017 21:43:53 GMT  net.EncryptedRpcChannel Call of 'mtproto.service.invokeWithLayer' took 206ms
[INFO] Tue, 10 Jan 2017 21:43:53 GMT  net.EncryptedRpcChannel New session has been created by Telegram: { T:mtproto.type.New_session_created, first_msg_id: "0x58755599045a1c74", unique_id: "0xc502126bcf63a3aa", server_salt: "0xc63ac5a8349d52c7" }
[INFO] Tue, 10 Jan 2017 21:43:53 GMT  net.EncryptedRpcChannel Send the ack to the server: { T:mtproto.type.Msgs_ack, msg_ids: { T:Vector, type: "Long", list: ["0x5875559932ad5001"] } }
[INFO] Tue, 10 Jan 2017 21:43:53 GMT  net.EncryptedRpcChannel The server sent a acknowledge for the followings [0x58755599045a1c74]

Roadmap

I think that this is great project, but it seems to be in stalled state. I don't dived deep in code so I think it would be hard to understand some things.

If anyone wants to help me PRs are welcome!

Goals

  • Remove requirish (implicit)
  • Migrate to ESLint
  • JSDoc types
  • Drop 0.10 support
  • Fix methods
  • Update TL Schema and API Layer
  • Review pull requests (add labels etc)
    • Merge all pull requests from original project
  • Monorepo (?)

Repos

Wrap some of the `channels` API calls

I shall be needing quite a few of the functions in the channels namespace. I see they're not yet wrapped.

I'll probably have a go at implementing this locally, and if I get to a point where I have something that seems useful I'll send a PR

Constant accumulation of "updates"

I'm as yet unsure whether this is me doing something wrong, or a real bug in the library, but reporting it here anyway:

I've started attempting to handle incoming "updates", by using the client.registerOnUpdates() method, and calling client.updates.getState(). After I do that, I find that I receive an update in due course from Telegram. But then I receive two - the original and another one. And then three - those first two, plus one more. Each time I receive an update I also receive all the prior ones too.

For example:

[INFO] Tue, 17 Jan 2017 19:54:44 GMT  net.EncryptedRpcChannel Call of 'mtproto.type.Msgs_ack' took 5820ms
UPDATE: user status user_id=1234 _t=api.type.UserStatusOffline
[INFO] Tue, 17 Jan 2017 19:54:44 GMT  net.EncryptedRpcChannel Call of 'mtproto.service.invokeAfterMsg' took 6595ms
UPDATE: user status user_id=1234 _t=api.type.UserStatusOffline
UPDATE: user status user_id=5678 _t=api.type.UserStatusOnline
[INFO] Tue, 17 Jan 2017 19:54:45 GMT  net.EncryptedRpcChannel Call of 'mtproto.service.http_wait' took 7569ms
UPDATE: user status user_id=1234 _t=api.type.UserStatusOffline
UPDATE: user status user_id=5678 _t=api.type.UserStatusOnline
UPDATE: user status user_id=1234 _t=api.type.UserStatusOnline
[INFO] Tue, 17 Jan 2017 19:54:46 GMT  net.EncryptedRpcChannel Call of 'mtproto.service.http_wait' took 367ms
UPDATE: user status user_id=1234 _t=api.type.UserStatusOffline
UPDATE: user status user_id=5678 _t=api.type.UserStatusOnline
UPDATE: user status user_id=1234 _t=api.type.UserStatusOnline
UPDATE: user status user_id=5678 _t=api.type.UserStatusOffline

I can think of two possibilities here:

  1. The Telegram server requires some sort of explicit acknowledgement of each update to stop it sending them again, or
  2. The telegram.link library is buffering them locally and finding them all over and over again.

If I simply quit and restart my program, then the updates start again from scratch - I never seem to see those updates previously received. Plus by looking at some code of other telegram clients, I don't see any sort of "server acknowledge" mechanism to tell the server we've received those messages, so I begin to suspect the second possibility; that somehow these messages are all remaining inside the local client and being found again and again each time one new one is received.

Does that sound plausible? If so any idea where I might begin looking for it?

Autogenerate all of the API wrappings

It would be nice if, rather than having to manually write every method wrapping an API function, that they were all automatically generated. We only have a tiny fraction of the full API wrapped, so adding more of them is tedious manual work.

I suspect it wouldn't be too hard to do this given as the types are all nicely wrapped.

(migrated from goodmind/telegram-mt-node#14)

error after auth.signIn

anonymous {
  _writeBuffers: null,
  _readOffset: 32,
  _buffer: <Buffer 19 ca 44 21 90 ...>,
  _noId: undefined,
  _typeId: '19ca4421',
  _typeName: 'mtproto.type.Rpc_error',
  serialize: [Function: serialize],
  deserialize: [Function: deserialize],
  __writeError_code: [Function: __writeError_code],
  __writeError_message: [Function: __writeError_message],
  __readError_code: [Function: __readError_code],
  __readError_message: [Function: __readError_message],
  error_code: 400,
  error_message: 'MTPROTO_CLUSTER_INVALID' }

Should accept `undefined` as well as `null` as missing optional argument

For ages I was struggling with the following code

return client.messages.sendMessage(peer, message, Math.random() * (1<<30));

returning INPUT_FETCH_ERROR from Telegram. Much code-diving later reveals that I have to call

return client.messages.sendMessage(peer, message, Math.random() * (1<<30), null, null, null);

i.e. that only null works as missing arguments, not undefined.

adding createChat

I'm trying to add a createChat method. I installed termgram in termgram folder;
I added in termgram/lib/use-case/chat.js

var api = require('telegram.link')();
                    var user1 = new api.type.InputPeerContact({
                            props: {
                                user_id: 1234567
                            }
                        }),
                        user2 = new api.type.InputPeerContact({
                            props: {
                                user_id: 7654321
                            }
                        });

var cb = function() {
                        console.log("doing the callback");
                    };

 var vector = [user1, user2];

clientProxy.getClient().messages.createChat(vector, 'test', null, cb);


then i put in termgram/node_modules/telegram.link/lib/abi/messages.js

Messages.prototype.createChat = function(users, title, callback) {
    console.log("create the cat in the hat");
    return utility.callService(api.service.messages.createChat, this.client, this.client._channel, callback, arguments);
};

what happens is that it prints 'create the cat in the hat' then it gives the error

client error TypeError: this.users.serialize is not a function
    at serialize (eval at createConstructor (/home/diego/Workshop/Essay/termgram/node_modules/telegram-tl-node/lib/builder/constructor-builder.js:115:27), <anonymous>:12:31)
    at EncryptedRpcChannel.callMethod (/home/diego/Workshop/Essay/termgram/node_modules/telegram-mt-node/lib/net/encrypted-rpc-channel.js:165:31)
    at eval (eval at buildTypeFunction (/home/diego/Workshop/Essay/termgram/node_modules/telegram-tl-node/lib/builder/type-builder.js:104:24), <anonymous>:15:10)
    at Object.callService (/home/diego/Workshop/Essay/termgram/node_modules/telegram.link/lib/utility.js:24:13)
    at Messages.createChat (/home/diego/Workshop/Essay/termgram/node_modules/telegram.link/lib/api/messages.js:126:20)
    at /home/diego/Workshop/Essay/termgram/lib/use-case/chat.js:82:54

what do I need to do?

HTTP transport sometimes stalls but is resumable

Sometimes (maybe about 50% of the time?) a call to an API method over the HTTP API just stalls. It doesn't fail, but doesn't succeed either. If I send another command (of the same or different type) that's usually sufficient to wake it up and then I receive both responses.

By watching another telegram client on my phone, it appears that the command itself does get executed (e.g. if it's a messages.sendMessage() call then the message does appear on Telegram); it seems purely related to reading back of responses from the server. It feels like something temporarily stops trying to receive responses from the server.

HTML-level errors from `auth.sendCode`

I get no response at all attempting to use auth.sendCode over TCP (see #13), so I'm trying HTTP instead.

I successfully make an initial request to auth.sendCode and receive a PHONE_MIGRATE_4 error. I migrate to DC4 and try again, and this time get stuck in a loop:

[DEBUG] Thu, 12 Jan 2017 19:27:54 GMT  net.HttpConnection add buffer(340) to the write buffer queue, total length 340 +0ms
[DEBUG] Thu, 12 Jan 2017 19:27:54 GMT  net.HttpConnection content-length = 340
  net.HttpConnection content-type = undefined
  net.HttpConnection accept = undefined
  net.HttpConnection host = 149.154.165.120:443
  net.HttpConnection connection = keep-alive
  net.HttpConnection  +2ms
[DEBUG] Thu, 12 Jan 2017 19:27:54 GMT  net.HttpConnection writing request(340) to {"withCredentials":false,"path":"/apiw1","port":443,"host":"149.154.165.120","protocol":"http:"} +0ms
[DEBUG] Thu, 12 Jan 2017 19:27:54 GMT  net.HttpConnection reading from {"withCredentials":false,"path":"/apiw1","port":443,"host":"149.154.165.120","protocol":"http:"}
  net.HttpConnection status: 404
  net.HttpConnection headers: {"server":"nginx/0.3.33","date":"Thu, 12 Jan 2017 19:27:54 GMT","content-type":"text/html","connection":"close","access-control-allow-origin":"*","access-control-allow-methods":"POST, OPTIONS","access-control-allow-headers":"origin, content-type","access-control-max-age":"1728000","content-length":"169"} +38ms
[ERROR] Thu, 12 Jan 2017 19:27:54 GMT  net.RpcChannel Unable to read: <html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/0.3.33</center>
</body>
</html>
 
[ERROR] Thu, 12 Jan 2017 19:27:54 GMT  auth.RequestDHParams <html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/0.3.33</center>
</body>
</html>

[ERROR] Thu, 12 Jan 2017 19:27:54 GMT  get-flow.runSeries Exception occurs: undefined
[ERROR] Thu, 12 Jan 2017 19:27:54 GMT  get-flow.runSeries Exception occurs: undefined

Eventually this will fail, the value result of the failure itself being the actual HTTP string here, containing this nginx 404 error HTML code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.