TDLib send message by phone number
How to send message in Telegram API by phone number.
TDLib calls:
- importContacts
- createPrivateChat
- sendMerssage
importContacts
Make a request like this:
{ "api_key": "YOUR_API_KEY", "@type": "importContacts", "contacts": [{ "first_name": "Jane", "last_name": "Doe", "phone_number": "+1555012345", "user_id": 0 }] }
You will receive response similar to this:
{ "@type": "importedContacts", "user_ids": [ 1234567 ], "importer_count": [ 8 ], "@extra": "f402e93d-0cc3-4765-ad54-2f5f5c593a9b" }
createPrivateChat
Take the user_id from previous response and use it in next request: { "api_key": "YOUR_API_KEY", "@type": "createPrivateChat", "user_id": 1234567 }
sendMessage
Send message using user_id as chat_id like this:
{ "api_key": "YOUR_API_KEY", "@type": "sendMessage", "chat_id": "1234567", "disable_notification": true, "input_message_content": { "@type": "inputMessageText", "disable_web_page_preview": false, "text": { "@type": "formattedText", "text": "Hello world" } } }
Только авторизованные участники могут оставлять комментарии.