Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add a contact with phptdlib? #78

Closed
sheko016 opened this issue Mar 22, 2021 · 4 comments
Closed

how to add a contact with phptdlib? #78

sheko016 opened this issue Mar 22, 2021 · 4 comments

Comments

@sheko016
Copy link

good morning dear.

this is to request a help to add a contact with phptdlib

I am using the following:

$obj3 = (object)[
'phone_number' => '+584145782661',
'first_name' => 'fernando',
'last_name' => 'moutinho',
'vcard' => [],
'user_id' => 0];

 $testencode = json_encode($obj3);
 //var_dump($testencode);

$addContact = $client->query(json_encode(['@type' => 'addContact', ['contact' => $testencode]]), 10);

but it shows me the following error message

"{"@type":"error","code":5,"message":"Contact must be non-empty","@extra":1714636915}"

I also tried the contact class
$contact = $client->query(json_encode(['@type' => 'contact', [
'phone_number' => '+584145782661',
'first_name' => 'fernando',
'last_name' => 'moutinho',
'vcard' => [],
'user_id' => 0
]]), 10);

but it shows me the following error message
"{"@type":"error","code":400,"message":"Failed to parse JSON object as TDLib request: Unknown class "contact"","@extra":1714636915}"

Please could you help me.

or make an example of how to add a contact with phptdlib

thanks greetings.

@yaroslavche
Copy link
Owner

You don't need encode twice. query method expecs encoded json, where @type and method arguments is top level keys in same array. So try to just prepare array with payload, then encode and then pass as argument. Unfortunately, I can't check code below, but I think it should work.

$query = [
    '@type' => 'addContact',
    'contact' => [
        'phone_number' => '+584145782661',
        'first_name' => 'fernando',
        'last_name' => 'moutinho',
        'vcard' => '',
        'user_id' => 0,
    ],
    'share_phone_number' => true,
];
$addContact = $client->query(json_encode($query), 10);

@sheko016
Copy link
Author

hello @yaroslavche thank you very much for your prompt response.

Personally, it didn't work for me. like that.

add the contact by doing the following

$addContact = $client->query(json_encode(['@type' => 'importContacts', 'contacts' => [
    		[	
    			'phone_number' => '+584145782661',
    		],
    	]]), 10);

I have another question anyway.
How to send a message to a newly added contact?
but I'm going to open another thread for that question.
Thanks a lot
Greetings.

@yaroslavche
Copy link
Owner

This questions aren't related to phptdlib (and how to send message you can find in docs for this repo). Also addContact !== importContact (what you asked about). And I don't know what's wrong on your side without any output. Read the docs, please, what need to send and what you should wait in response https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1import_contacts.html

@sheko016
Copy link
Author

Hi @yaroslavche

ok yes Mr. and if I am reading the documentation to perform all the possible tests.

Thanks a lot

Regards.

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

No branches or pull requests

2 participants