Search code examples
c#.nettelegram

TDLib Share phone number with bot


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. Appropriate method: TdApi.Client.SharePhoneNumberAsync


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.


Solution

  • This works:

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