Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

How to call api-methods with the vector in args? #6

Closed
FragsterAt opened this issue Feb 17, 2017 · 11 comments
Closed

How to call api-methods with the vector in args? #6

FragsterAt opened this issue Feb 17, 2017 · 11 comments

Comments

@FragsterAt
Copy link

such as https://core.telegram.org/method/contacts.importContacts

i try this code:

              let contact = {
                client_id: 1, //long
                phone: 'phone', //string
                first_name: 'name', //string
                last_name: 'name' //strings
              };
              let cont = new tl.TypeVector({type: 'InputContact', list: [contact]});
              return client.callApi('contacts.importContacts', cont, true);

but have an error:

TypeError: Cannot read property 'serialize' of undefined

@goodmind
Copy link
Collaborator

goodmind commented Feb 17, 2017

You should use client.schema.type.InputPhoneContact constructor for contact

@goodmind
Copy link
Collaborator

/cc @FragsterAt

@FragsterAt
Copy link
Author

@goodmind , folloving code generate an error
c1 = new client.schema.type.InputPhoneContact(contact);

undefined:4
this.constructor.util._extend(this, opts.props);
^

TypeError: Cannot read property '_extend' of undefined
at Object.eval [as InputPhoneContact] (eval at createConstructor (/home/antonio/work/shedsender/shedsender/node_modules/telegram-mtproto/lib/tl/builder/constructor-builder.js:100:27), :4:23)

@FragsterAt
Copy link
Author

at Object.eval [as InputPhoneContact] (eval at createConstructor (///node_modules/telegram-mtproto/lib/tl/builder/constructor-builder.js:100:27), <anonymous>:4:23)
at Object.<anonymous> (///importContacts.js:93:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)

@FragsterAt
Copy link
Author

this is also wrong :(

let contact = {
                client_id: 1, //long
                phone: '12345678901', //string
                first_name: 'name', //string
                last_name: 'name' //strings
              };
let cont = new tl.TypeVector({type: 'InputContact', list: ([contact]).map((elem) => {
		return new client.schema.type.InputPhoneContact(elem);
	})});
			return client.callApi('contacts.importContacts', {contacts: cont, replace: true});

@zerobias
Copy link
Owner

Hi. Currently, I'm doing a new API for such cases, because current one came from 2014 and it's really buggy and unsound.

@zerobias
Copy link
Owner

I will upload new module within two or three days, stay tuned

@FragsterAt
Copy link
Author

FragsterAt commented Feb 20, 2017

@zerobias Hello! I saw a lot of commits. They have a solution of my problem? NPM version also updated, or better to clone the repository in my project? (This involves some problems when I deploy an application on the production server)

@FragsterAt
Copy link
Author

@goodmind @zerobias Guys, documentation is very important thing!
the right way to create vectors for requests is pass object with 'props' property:
let cont = new tl.TypeVector({type: 'InputContact', list: ([contact]).map((elem) => {
return new client.schema.type.InputPhoneContact({props:elem});
})});
the right way to pass parameters to the call - object with properties equal to the parameter names from api.telegram.org
also bug with non latin characters is present enricostara/telegram.link#34 ...

Unfortunately, I'm new to git and I do not know how to do pull request for README.md and bugfix for non-Latin characters in strings, so please do it yourself!

@goodmind
Copy link
Collaborator

goodmind commented Feb 21, 2017

There is fix for this in goodmind/telegram-tl-node@66613a8. We need to just merge some fixes in @zerobias's version, but we are dropped working on @enricostara's version and forked zhukov/webogram to zerobias/telegram-mtproto#mtproto2. I agree with you about documentation but we want to make treact works firstly

@goodmind
Copy link
Collaborator

@FragsterAt non-latin characters fixed in e476c5c

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants