mirror of
https://github.com/MarshalX/telegram-crawler.git
synced 2025-01-06 02:45:30 +01:00
Update content of files
This commit is contained in:
parent
e8f6eed550
commit
45f23521f2
1 changed files with 27 additions and 15 deletions
|
@ -109,31 +109,41 @@ def post_request_status(endpoint, json_body):
|
|||
return None</code></pre>
|
||||
<h3><a class="anchor" name="sending-auth-codes" href="#sending-auth-codes"><i class="anchor-icon"></i></a>Sending Auth Codes</h3>
|
||||
<blockquote>
|
||||
<p><strong>TLDR</strong>: Pass a phone number (<a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format) to <a href="https://core.telegram.org/gateway/api#checksendability">this method</a> as a dry run – if you don’t get an error, pass the <code>request_id</code> you just obtained to <a href="https://core.telegram.org/gateway/api#sendverificatiomessage">this method</a> to send an auth code to the user.</p>
|
||||
<p><strong>TLDR</strong>: Pass a phone number (<a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format) to <a href="https://core.telegram.org/gateway/api#sendverificatiomessage">this method</a> to directly send an auth code to the user. If you need a dry run to verify your code can be delivered, use <a href="https://core.telegram.org/gateway/api#checksendability">this method</a>.</p>
|
||||
</blockquote>
|
||||
<p>To send an authorization code, we’ll first use the <a href="https://core.telegram.org/gateway/api#checksendability">checkSendAbility</a> method to verify that the user we want to target can receive messages on Telegram.</p>
|
||||
<pre><code>endpoint = 'checkSendAbility'
|
||||
json_body = {
|
||||
'phone_number': PHONE # E.164 format
|
||||
}
|
||||
result = post_request_status(endpoint, json_body)
|
||||
if result:
|
||||
request_id = result.get('request_id')
|
||||
print(f"Request ID: {request_id}")</code></pre>
|
||||
<blockquote>
|
||||
<p>If the method returns an error and the user cannot be contacted, you will not be charged. If the method instead indicates that the user can be contacted, you will be <strong>automatically charged</strong> in advance for the price of a message regardless of whether you eventually send one. If you do send a message, use the <code>request_id</code> returned by this method to avoid paying the message fee again.</p>
|
||||
</blockquote>
|
||||
<p>Assuming the outcome was positive and the user can be contacted, we can send them a code generated by Telegram with the <a href="https://core.telegram.org/gateway/api#sendverificatiomessage">sendVerificationMessage</a> method:</p>
|
||||
<p>To send the user a code generated by Telegram, you can use the <a href="https://core.telegram.org/gateway/api#sendverificatiomessage">sendVerificationMessage</a> method:</p>
|
||||
<pre><code>endpoint = 'sendVerificationMessage'
|
||||
|
||||
json_body = {
|
||||
'request_id': request_id, # Reuse to avoid paying the fee again
|
||||
'phone_number': PHONE, # Must be the one tied to request_id
|
||||
'code_length': 6, # Ignored if you specify your own 'code'
|
||||
'ttl': 60, # 1 minute
|
||||
'payload': 'my_payload_here', # Not shown to users
|
||||
'callback_url': 'https://my.webhook.here/auth'
|
||||
}
|
||||
|
||||
result = post_request_status(endpoint, json_body)</code></pre>
|
||||
<blockquote>
|
||||
<p>If the method returns an error (e.g., because the user cannot receive codes), you <strong>will not be charged</strong>. On success, it will return a <a href="https://core.telegram.org/gateway/api#requeststatus">RequestStatus</a> object.</p>
|
||||
</blockquote>
|
||||
<p>You can optionally specify the <code>sender_username</code> parameter, designating a <strong>verified channel</strong> you own as the one from which the code will be sent to the user. When sending codes to yourself for testing purposes, the channel does not need to be verified.</p>
|
||||
<h4><a class="anchor" name="checking-that-codes-can-be-delivered" href="#checking-that-codes-can-be-delivered"><i class="anchor-icon"></i></a>Checking that codes can be delivered</h4>
|
||||
<p>Before sending, you can also optionally use the <a href="https://core.telegram.org/gateway/api#checksendability">checkSendAbility</a> method to verify that the user you want to target can receive messages on Telegram. This is especially useful when you generated a code yourself but need to check that it can be delivered before sending it out to the user through the Gateway API.</p>
|
||||
<pre><code>endpoint = 'checkSendAbility'
|
||||
|
||||
json_body = {
|
||||
'phone_number': PHONE # E.164 format
|
||||
}
|
||||
|
||||
result = post_request_status(endpoint, json_body)
|
||||
|
||||
if result:
|
||||
request_id = result.get('request_id')
|
||||
print(f"Request ID: {request_id}")</code></pre>
|
||||
<blockquote>
|
||||
<p>If the method returns an error (e.g., because the user cannot receive codes), you <strong>will not be charged</strong>. If the method instead indicates that the user can be contacted, you will be <strong>automatically charged</strong> in advance for the price of a message regardless of whether you eventually send one. </p>
|
||||
</blockquote>
|
||||
<p>If the check succeeds and you ultimately decide to send a message, use the <code>request_id</code> returned by the <code>checkSendAbility</code> method to avoid paying the message fee again.</p>
|
||||
<h4><a class="anchor" name="revoking-codes" href="#revoking-codes"><i class="anchor-icon"></i></a>Revoking Codes</h4>
|
||||
<p>You can optionally revoke codes even before they expire by passing the relevant <code>request_id</code> to the <a href="https://core.telegram.org/gateway/api#revokeverificatiomessage">revokeVerificationMessage</a> method. Messages which were already read will not be deleted.</p>
|
||||
<blockquote>
|
||||
|
@ -142,10 +152,12 @@ result = post_request_status(endpoint, json_body)</code></pre>
|
|||
<h3><a class="anchor" name="checking-the-authorization-status" href="#checking-the-authorization-status"><i class="anchor-icon"></i></a>Checking the Authorization Status</h3>
|
||||
<p>If you let Telegram generate a code for you (i.e., you did not provide a <code>code</code> param in your request), you can use the <a href="https://core.telegram.org/gateway/api#checkverificationstatus">checkVerificationStatus</a> method to verify the OTP submitted by your user.</p>
|
||||
<pre><code>endpoint = 'checkVerificationStatus'
|
||||
|
||||
json_body = {
|
||||
'request_id': request_id, # Relevant request id
|
||||
'code': CODE, # The code the user entered in your app
|
||||
}
|
||||
|
||||
result = post_request_status(endpoint, json_body)
|
||||
|
||||
# Assuming the request was successful
|
||||
|
|
Loading…
Reference in a new issue