Skip to content

Commit

Permalink
Merge f56704c into 37c4a98
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-it committed Sep 23, 2016
2 parents 37c4a98 + f56704c commit afea930
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/api/contacts.js
Expand Up @@ -8,6 +8,7 @@
var api = require('../api');
var utility = require('../utility');

var tl = require('telegram-tl-node');

// ***

Expand Down Expand Up @@ -41,5 +42,29 @@ Contacts.prototype.getContacts = function (hash, callback) {
return utility.callService(api.service.contacts.getContacts, this.client, this.client._channel, callback, arguments);
};

// ***
// contacts.**importContacts(contacts, replace, [callback])**

// Return a Promise to get imported contacts info.

// [Click here for more details](https://core.telegram.org/method/contacts.importContacts)

// The code:
Contacts.prototype.importContacts = function (contacts, replace, callback) {
contacts = new tl.TypeVector({type: 'InputContact', list: contacts.map(function (contact) {
return new api.type.InputPhoneContact({props: {
client_id: contact.client_id,
phone: contact.phone,
first_name: contact.first_name,
last_name: contact.last_name
}});
})})

replace = replace === false ? new api.type.BoolFalse() :
( replace === true ? new api.type.BoolTrue() : replace);

return utility.callService(api.service.contacts.importContacts, this.client, this.client._channel, callback, arguments);
};

// Export the class
module.exports = exports = Contacts;
48 changes: 48 additions & 0 deletions lib/api/users.js
@@ -0,0 +1,48 @@
// 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 users.

// See [Api Methods](https://core.telegram.org/methods#working-with-users)

// Access only via Client object (like client.users) and `users` instance property

function Users(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.


// ***
// users.**getFullUser(user_id, [callback])**

// Return a Promise to get extended user info by ID (only users from the contact list supported).

// [Click here for more details](https://core.telegram.org/method/users.getFullUser)

// The code:
Users.prototype.getFullUser = function (id, callback) {
id = new api.type.InputUserContact({props: {
user_id: id
}});

return utility.callService(api.service.users.getFullUser, this.client, this.client._channel, callback, arguments);
};

// Export the class
module.exports = exports = Users;
2 changes: 2 additions & 0 deletions lib/telegram.link.js
Expand Up @@ -158,6 +158,8 @@ function Client(app, dataCenter) {
this.auth = new (require('./api/auth'))(this);
// User contacts
this.contacts = new (require('./api/contacts'))(this);
// Users
this.users = new (require('./api/users'))(this);
// Session updates
this.updates = new (require('./api/updates'))(this);
// Chat messages
Expand Down

0 comments on commit afea930

Please sign in to comment.