tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

Share phone number with bot #2833

Closed starkdm closed 7 months ago

starkdm commented 7 months ago

How can I send my contact to the bot in chat? The documentation for sharePhoneNumber says that the user must be a mutual contact. But the bot cannot be added to contacts.

I use TDLib 1.8.21

Code example:

Client = new TdClient();
await Client.SetTdlibParametersAsync(databaseDirectory: DatabaseDir, 
    apiId: apiId, 
    apiHash: apiHash, 
    systemLanguageCode: systemLanguageCode, 
    deviceModel: deviceModel, 
    systemVersion: systemVersion, 
    applicationVersion: version);
await Client.SharePhoneNumberAsync(chatId);

Everything works without exceptions, but the contact is not sent. The text message is sent, the contact is not.

levlam commented 7 months ago

To send a contact you need to use sendMessage with inputMessageContact.

starkdm commented 7 months ago

@levlam Thanks! This works.

await Client.SendMessageAsync(chatId, inputMessageContent: new InputMessageContent.InputMessageContact() {
    Contact = new Contact() { PhoneNumber = PhoneNumber }
});