mirror of
https://github.com/InsanusMokrassar/docs.git
synced 2025-11-28 18:35:36 +00:00
deploy: f7a2359066
This commit is contained in:
@@ -1305,28 +1305,28 @@
|
||||
</ul>
|
||||
<h3 id="longpolling">longPolling<a class="headerlink" href="#longpolling" title="Permanent link">¶</a></h3>
|
||||
<p><code>longPolling</code> is a simple way to start getting updates and work with bot:</p>
|
||||
<pre><code class="language-kotlin">val bot = telegramBot(token)
|
||||
bot.longPolling(
|
||||
textMessages().subscribe(scope) { // here "scope" is a CoroutineScope
|
||||
println(it) // will be printed each update from chats with messages
|
||||
}
|
||||
)
|
||||
</code></pre>
|
||||
<div class="language-kotlin highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kd">val</span><span class="w"> </span><span class="nv">bot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">telegramBot</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
|
||||
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="n">bot</span><span class="p">.</span><span class="na">longPolling</span><span class="p">(</span>
|
||||
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="w"> </span><span class="n">textMessages</span><span class="p">().</span><span class="na">subscribe</span><span class="p">(</span><span class="n">scope</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// here "scope" is a CoroutineScope</span>
|
||||
</span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a><span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="nb">it</span><span class="p">)</span><span class="w"> </span><span class="c1">// will be printed each update from chats with messages</span>
|
||||
</span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="w"> </span><span class="p">}</span>
|
||||
</span><span id="__span-0-6"><a id="__codelineno-0-6" name="__codelineno-0-6" href="#__codelineno-0-6"></a><span class="p">)</span>
|
||||
</span></code></pre></div>
|
||||
<h3 id="startgettingofupdatesbylongpolling">startGettingOfUpdatesByLongPolling<a class="headerlink" href="#startgettingofupdatesbylongpolling" title="Permanent link">¶</a></h3>
|
||||
<p>The main aim of <code>startGettingOfUpdatesByLongPolling</code> extension was to provide more simple way to get updates in automatic mode:</p>
|
||||
<pre><code class="language-kotlin">val bot = telegramBot(token)
|
||||
bot.startGettingOfUpdatesByLongPolling(
|
||||
{
|
||||
println(it) // will be printed each update from chats with messages
|
||||
}
|
||||
)
|
||||
</code></pre>
|
||||
<div class="language-kotlin highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="kd">val</span><span class="w"> </span><span class="nv">bot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">telegramBot</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
|
||||
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="n">bot</span><span class="p">.</span><span class="na">startGettingOfUpdatesByLongPolling</span><span class="p">(</span>
|
||||
</span><span id="__span-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a><span class="w"> </span><span class="p">{</span>
|
||||
</span><span id="__span-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="nb">it</span><span class="p">)</span><span class="w"> </span><span class="c1">// will be printed each update from chats with messages</span>
|
||||
</span><span id="__span-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a><span class="w"> </span><span class="p">}</span>
|
||||
</span><span id="__span-1-6"><a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a><span class="p">)</span>
|
||||
</span></code></pre></div>
|
||||
<p>The other way is to use the most basic <code>startGettingOfUpdatesByLongPolling</code> extension:</p>
|
||||
<pre><code class="language-kotlin">val bot = telegramBot(token)
|
||||
bot.startGettingOfUpdatesByLongPolling {
|
||||
println(it) // will be printed each update
|
||||
}
|
||||
</code></pre>
|
||||
<div class="language-kotlin highlight"><pre><span></span><code><span id="__span-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="kd">val</span><span class="w"> </span><span class="nv">bot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">telegramBot</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
|
||||
</span><span id="__span-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a><span class="n">bot</span><span class="p">.</span><span class="na">startGettingOfUpdatesByLongPolling</span><span class="w"> </span><span class="p">{</span>
|
||||
</span><span id="__span-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3" href="#__codelineno-2-3"></a><span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="nb">it</span><span class="p">)</span><span class="w"> </span><span class="c1">// will be printed each update</span>
|
||||
</span><span id="__span-2-4"><a id="__codelineno-2-4" name="__codelineno-2-4" href="#__codelineno-2-4"></a><span class="p">}</span>
|
||||
</span></code></pre></div>
|
||||
<h2 id="see-also">See also<a class="headerlink" href="#see-also" title="Permanent link">¶</a></h2>
|
||||
<ul>
|
||||
<li><a href="webhooks.html">Webhooks</a></li>
|
||||
|
||||
Reference in New Issue
Block a user