var api = require('./api');
-var utility = require('./utility');
diff --git a/doc/updates.html b/doc/api/account.html similarity index 78% rename from doc/updates.html rename to doc/api/account.html index 81fbdc1..b06a1da 100644 --- a/doc/updates.html +++ b/doc/api/account.html @@ -2,10 +2,10 @@
-var api = require('./api');
-var utility = require('./utility');
var api = require('../api');
+var utility = require('../utility');
This module wraps API methods required to manage the session updates
+This module wraps API methods required to manage notifications and settings
@@ -85,7 +85,7 @@See Api Methods
+See Api Methods
@@ -98,12 +98,12 @@Access only via Client object and updates
instance property
Access only via Client object and account
instance property
-function Updates(client) {
+function Account(client) {
this.client = client;
}
updates.getState([callback])
+account.updateStatus(offline, [callback])
@@ -169,7 +169,7 @@Returns a Promise for get the current state of updates.
+Return a Promise to update the online user status..
@@ -182,7 +182,7 @@Updates.prototype.getState = function (callback) {
- return utility.callService(api.service.updates.getState, this.client, this.client._channel, callback, arguments);
+ Account.prototype.updateStatus = function (offline, callback) {
+
+ offline = offline === false ? new api.type.BoolFalse() :
+ ( offline === true ? new api.type.BoolTrue() : offline);
+
+ return utility.callService(api.service.account.updateStatus, this.client, this.client._channel, callback, arguments);
};
@@ -216,7 +220,7 @@ updates.js
module.exports = exports = Updates;
module.exports = exports = Account;
var api = require('./api');
-var utility = require('./utility');
var api = require('../api');
+var utility = require('../utility');
Sends a text message with the confirmation code required for registration to the given phone number.
+Send a text message with the confirmation code required for registration to the given phone number.
Makes a voice call to the passed phone number. A robot will repeat the confirmation code from a previously sent SMS message. -Returns a Promise.
+Return a Promise to make a voice call to the passed phone number. +A robot will repeat the confirmation code from a previously sent SMS message.
@@ -305,8 +305,7 @@Signs in a user with a validated phone number. -Returns a Promise.
+Return a Promise to sign in a user with a validated phone number.
@@ -363,8 +362,7 @@Registers a validated phone number in the system. -Returns a Promise.
+Return a Promise to register a validated phone number in the system.
@@ -421,7 +419,7 @@Returns a Promise for get the information on whether the passed phone number was registered.
+Return a Promise to get the information on whether the passed phone number was registered.
@@ -464,7 +462,7 @@Exports the class.
+Export the class.
diff --git a/doc/contacts.html b/doc/api/contacts.html similarity index 95% rename from doc/contacts.html rename to doc/api/contacts.html index 2d6b09f..d7be614 100644 --- a/doc/contacts.html +++ b/doc/api/contacts.html @@ -5,7 +5,7 @@var api = require('./api');
-var utility = require('./utility');
var api = require('../api');
+var utility = require('../utility');
Returns a Promise for get the current user’s contact list.
+Return a Promise to get the current user’s contact list.
@@ -212,7 +212,7 @@Exports the class
+Export the class
diff --git a/doc/messages.html b/doc/api/messages.html similarity index 83% rename from doc/messages.html rename to doc/api/messages.html index 6e1bd52..2215dbb 100644 --- a/doc/messages.html +++ b/doc/api/messages.html @@ -5,7 +5,7 @@var api = require('./api');
-var utility = require('./utility');
var api = require('../api');
+var utility = require('../utility');
Returns a Promise for get the current user dialog list.
+Return a Promise to get the current user dialog list.
@@ -226,7 +226,7 @@Returns a Promise for get the message history for a chat.
+Return a Promise to get the message history for a chat.
@@ -312,7 +312,7 @@messages.sendMessage(peer, message, random_id, [callback])
+messages.readHistory(peer, max_id, offset, read_contents, [callback])
@@ -325,7 +325,7 @@Returns a Promise for get the message history for a chat.
+Return a Promise to mark the message history as read..
@@ -338,7 +338,7 @@Usage example (user_id
must be a real contact id, of course):
The code:
+Messages.prototype.readHistory = function (peer, max_id, offset, read_contents, callback) {
+
+ read_contents = read_contents === false ? new api.type.BoolFalse() :
+ ( read_contents === true ? new api.type.BoolTrue() : read_contents);
+
+ return utility.callService(api.service.messages.readHistory, this.client, this.client._channel, callback, arguments);
+};
messages.sendMessage(peer, message, random_id, [callback])
+ + + + + + +Return a Promise to send a message to the peer.
+ +Usage example (user_id
must be a real contact id, of course):
var api = require('telegram.link')();
var client = api.createClient( ...
@@ -387,11 +448,11 @@ messages.js
-
+
The code:
@@ -404,13 +465,13 @@ messages.js
-
+
diff --git a/doc/api/updates.html b/doc/api/updates.html
new file mode 100644
index 0000000..43d306e
--- /dev/null
+++ b/doc/api/updates.html
@@ -0,0 +1,283 @@
+
+
+
+
+ updates.js
+
+
+
+
+
+
+
+
+
+
+ -
+
+
updates.js
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
telegram.link
+Copyright 2014 Enrico Stara 'enrico.stara@gmail.com'
+Released under the MIT License
+http://telegram.link
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
Dependencies:
+
+
+
+ var api = require('../api');
+var utility = require('../utility');
+
+
+
+
+ -
+
+
+
+ ¶
+
+
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
This module wraps API methods required to manage the session updates
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
See Api Methods
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
Access only via Client object and updates
instance property
+
+
+
+
+function Updates(client) {
+ this.client = client;
+}
+
+
+
+
+ -
+
+
+
+ ¶
+
+
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
Event: 'method name'
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
Each of the following methods emits an event with the same name when done, an error
event otherwise.
+
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
Return a Promise to get the current state of updates.
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
The code:
+
+
+
+ Updates.prototype.getState = function (callback) {
+ return utility.callService(api.service.updates.getState, this.client, this.client._channel, callback, arguments);
+};
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
Return a Promise to get the difference between the current state of updates and transmitted.
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
+
+
+
+
+
+
+ -
+
+
+
+ ¶
+
+
The code:
+
+
+
+ Updates.prototype.getDifference = function (pts, date, qts, callback) {
+ return utility.callService(api.service.updates.getDifference, this.client, this.client._channel, callback, arguments);
+};
+
+
+
+
+ -
+
+
+
+ ¶
+
+
Export the class
+
+
+
+ module.exports = exports = Updates;
+
+
+
+
+
+
+
diff --git a/doc/telegram.link.html b/doc/telegram.link.html
index 774fce4..b9bf6ba 100644
--- a/doc/telegram.link.html
+++ b/doc/telegram.link.html
@@ -425,12 +425,11 @@ telegram.link.js
- creates the authorization modules bound with the client to call all the API methods
-user authorization
+ User authorization
- this.auth = new (require('./auth'))(this);
+ this.auth = new (require('./api/auth'))(this);
@@ -441,11 +440,11 @@ telegram.link.js
- user contacts
+ User contacts
this.contacts = new (require('./contacts'))(this);
this.contacts = new (require('./api/contacts'))(this);
session updates
+Session updates
- this.updates = new (require('./updates'))(this);
this.updates = new (require('./api/updates'))(this);
chat messages
+Chat messages
- this.messages = new (require('./messages'))(this);
-}
this.messages = new (require('./api/messages'))(this);
Extend the events.EventEmitter
class
Notifications and settings
-require('util').inherits(Client, require('events').EventEmitter);
this.account = new (require('./api/account'))(this);
+}
createEncryptedChannel()
+Extend the events.EventEmitter
class
require('util').inherits(Client, require('events').EventEmitter);
Creates the encrypted channel used to call all the Telegram API methods (private).
+createEncryptedChannel()
@@ -529,6 +530,19 @@Creates the encrypted channel used to call all the Telegram API methods (private).
+ + + + + + +The code:
client.createAuthKey([callback])
@@ -561,11 +575,11 @@Exchanges the authorization key with Telegram, see https://core.telegram.org/mtproto/auth_key
@@ -574,11 +588,11 @@This method is asynchronous and the client must be already connected before calling this function.
When the authKey is created, the authKeyCreate
event will be emitted.
The last parameter callback will be added as a listener for the authKeyCreate
event, the callback
could receive the following arguments:
The code:
@@ -637,11 +651,11 @@client.getDataCenterList([callback])
@@ -651,11 +665,11 @@Gets the data center list, the current data center and the nearest one.
@@ -664,11 +678,11 @@The code:
@@ -726,11 +740,273 @@HTTP long poll service.
+ +The code:
+ +Client.prototype.httpPoll = function (callback, maxWait, waitAfter, maxDelay) {
+ if (callback) {
+ this.once('httpPoll', callback);
+ }
+ if (this.isReady(true) && this._connection instanceof mt.net.HttpConnection) {
+ var self = this;
+ maxWait = maxWait || 30000;
+ console.log('call http long poll each %sms', maxWait);
+ try {
+ mt.service.http_wait({
+ props: {
+ max_delay: maxDelay || 0,
+ wait_after: waitAfter || 0,
+ max_wait: maxWait
+ },
+ channel: self._channel,
+ callback: function (ex, result) {
+ if (ex) {
+ self.emit('error', ex);
+ } else {
+ self.emit('httpPoll', result);
+ if(self._httpPollLoop) {
+ self.httpPoll(callback, maxWait, waitAfter, maxDelay);
+ }
+ }
+ }
+ });
+ } catch (err) {
+ this.emit('error', err);
+ }
+ }
+};
Start the HTTP long poll service loop.
+ +The code:
+ +Client.prototype.startHttpPollLoop = function (callback, maxWait, waitAfter, maxDelay) {
+ this._httpPollLoop = true;
+ this.httpPoll(callback, maxWait, waitAfter, maxDelay);
+};
Stop the HTTP long poll service loop.
+ +The code:
+ +Client.prototype.stopHttpPollLoop = function () {
+ this._httpPollLoop = false;
+};
Register the function and call back on any update events.
+ +The code:
+ +Client.prototype.registerOnUpdates = function (callback) {
+ var emitter = this._channel.getParser();
+ emitter.on('api.type.UpdatesTooLong', callback);
+ emitter.on('api.type.UpdateShortMessage', callback);
+ emitter.on('api.type.UpdateShortChatMessage', callback);
+ emitter.on('api.type.UpdateShort', callback);
+ emitter.on('api.type.UpdatesCombined', callback);
+ emitter.on('api.type.Updates', callback);
+};
Un-register from the update events.
+ +The code:
+ +Client.prototype.unregisterOnUpdates = function (callback) {
+ var emitter = this._channel.getParser();
+ emitter.removeListener('api.type.UpdatesTooLong', callback);
+ emitter.removeListener('api.type.UpdateShortMessage', callback);
+ emitter.removeListener('api.type.UpdateShortChatMessage', callback);
+ emitter.removeListener('api.type.UpdateShort', callback);
+ emitter.removeListener('api.type.UpdatesCombined', callback);
+ emitter.removeListener('api.type.Updates', callback);
+};
client.isReady()
@@ -740,11 +1016,11 @@Checks if the client is ready to communicate with Telegram and immediately emits the error-event if required.
@@ -753,11 +1029,11 @@The code:
@@ -776,11 +1052,11 @@client.end([callback])
@@ -790,11 +1066,11 @@Closes the communication with the DataCenter,
@@ -803,11 +1079,11 @@The last parameter callback will be added as a listener for the end
event.
The code:
@@ -836,11 +1112,11 @@connect()
@@ -850,11 +1126,11 @@Establishes the connection with the data center (private).
@@ -863,11 +1139,11 @@The code:
@@ -880,11 +1156,11 @@Event: ‘connect’ @@ -895,11 +1171,11 @@
Event: ‘authKeyCreate’ Emitted when the authKey is successfully created. See client.createAuthKey().
@@ -909,11 +1185,11 @@Event: ‘dataCenter’ Emitted when the data-center map is available. See client.getDataCenters().
@@ -923,11 +1199,11 @@Event: ‘end’ Emitted when the data center close the connection. See client.end().
@@ -937,11 +1213,11 @@Event: ‘error’ Emitted when an error occurs.
@@ -951,11 +1227,11 @@Export the internals.
@@ -983,11 +1259,11 @@Export all the API types. (no methods)
diff --git a/doc/utility.html b/doc/utility.html index 885444c..5e9ba6f 100644 --- a/doc/utility.html +++ b/doc/utility.html @@ -88,7 +88,8 @@