telegram-crawler/data/web/blogfork.telegram.org/bots/faq.html

247 lines
18 KiB
HTML
Raw Normal View History

2022-05-14 00:37:40 +02:00
<!DOCTYPE html>
<html class="">
<head>
<meta charset="utf-8">
<title>Bots FAQ</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="description" content="If you are new to Telegram bots, we recommend checking out our Introduction to Bots first.
You may also find the Bot API…">
<meta property="og:title" content="Bots FAQ">
<meta property="og:image" content="https://blogfork.telegram.org/file/811140979/3/5p52TWl9X2o/5c6d684ee0d6a4399d">
<meta property="og:description" content="If you are new to Telegram bots, we recommend checking out our Introduction to Bots first.
You may also find the Bot API…">
<link rel="icon" type="image/svg+xml" href="/img/website_icon.svg?4">
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
<link rel="alternate icon" href="/img/favicon.ico" type="image/x-icon" />
<link href="/css/bootstrap.min.css?3" rel="stylesheet">
2023-03-20 12:08:32 +01:00
<link href="/css/telegram.css?236" rel="stylesheet" media="screen">
2022-05-14 00:37:40 +02:00
<style>
</style>
</head>
<body class="preload">
<div class="dev_page_wrap">
<div class="dev_page_head navbar navbar-static-top navbar-tg">
<div class="navbar-inner">
<div class="container clearfix">
<ul class="nav navbar-nav navbar-right hidden-xs"><li class="navbar-twitter"><a href="https://twitter.com/telegram" target="_blank" data-track="Follow/Twitter" onclick="trackDlClick(this, event)"><i class="icon icon-twitter"></i><span> Twitter</span></a></li></ul>
<ul class="nav navbar-nav">
<li><a href="//telegram.org/">Home</a></li>
<li class="hidden-xs"><a href="//telegram.org/faq">FAQ</a></li>
<li class="hidden-xs"><a href="//telegram.org/apps">Apps</a></li>
<li class=""><a href="/api">API</a></li>
<li class=""><a href="/mtproto">Protocol</a></li>
<li class=""><a href="/schema">Schema</a></li>
</ul>
</div>
</div>
</div>
<div class="container clearfix">
<div class="dev_page">
<div id="dev_page_content_wrap" class=" ">
<div class="dev_page_bread_crumbs"><ul class="breadcrumb clearfix"><li><a href="/bots" >Telegram Bots</a></li><i class="icon icon-breadcrumb-divider"></i><li><a href="/bots/faq" >Bots FAQ</a></li></ul></div>
<h1 id="dev_page_title">Bots FAQ</h1>
<div id="dev_page_content"><blockquote>
<p>If you are new to Telegram bots, we recommend checking out our <a href="/bots"><strong>Introduction to Bots</strong></a> first.<br>You may also find the <strong><a href="/bots/api">Bot API Manual</a></strong> useful.</p>
</blockquote>
<p><div class="dev_page_nav_wrap"></p>
<p><a href="#general-questions"><strong>General</strong></a></p>
<ul>
<li><a href="#how-do-i-create-a-bot">How do I create a bot?</a></li>
<li><a href="#i-39m-a-developer-where-can-i-find-some-examples">Where can I get some code examples?</a></li>
<li><a href="#will-you-add-x-to-the-bot-api">I have a feature request!</a></li>
<li><a href="#what-messages-will-my-bot-get">What messages will my bot get?</a></li>
<li><a href="#why-doesn-39t-my-bot-see-messages-from-other-bots">Why doesn&#39;t my bot see messages from other bots?</a></li>
</ul>
<p><a href="#getting-updates"><strong>Getting Updates</strong></a></p>
<ul>
<li><a href="#how-do-i-get-updates">How do I get updates?</a></li>
<li><a href="#long-polling-gives-me-the-same-updates-again-and-again">Long polling problems</a></li>
<li><a href="#i-39m-having-problems-with-webhooks">Webhook problems</a></li>
<li><a href="#i-39m-having-trouble-with-my-self-signed-certificate">Using self-signed certificates</a></li>
<li><a href="#how-can-i-make-sure-that-webhook-requests-are-coming-from-telegr">How can I make sure webhook requests come from Telegram?</a></li>
</ul>
<p><a href="#handling-media"><strong>Handling Media</strong></a></p>
<ul>
<li><a href="#how-do-i-download-files">Downloading files</a></li>
<li><a href="#how-do-i-upload-a-large-file">Uploading large files</a></li>
<li><a href="#can-i-count-on-file-ids-to-be-persistent">Can I count of file_ids to be persistent?</a></li>
</ul>
<p><a href="#broadcasting-to-users"><strong>Broadcasting to Users</strong></a></p>
<ul>
<li><a href="#my-bot-is-hitting-limits-how-do-i-avoid-this">How do I avoid hitting limits?</a></li>
<li><a href="#how-can-i-message-all-of-my-bot-39s-subscribers-at-once">How do I message all my subscribers?</a><br></div></li>
</ul>
<hr>
<h3><a class="anchor" name="general-questions" href="#general-questions"><i class="anchor-icon"></i></a>General Questions</h3>
<h4><a class="anchor" name="how-do-i-create-a-bot" href="#how-do-i-create-a-bot"><i class="anchor-icon"></i></a>How do I create a bot?</h4>
<p>Creating Telegram bots is super-easy, but you will need at least some skills at computer programming. In order for a bot to work, set up a bot account with <a href="https://telegram.me/botfather">@BotFather</a>, then connect it to your backend server via our <a href="/bots/api">API</a>.</p>
<p>Unfortunately, there are no out-of-the-box ways to create a working bot if you are not a developer. But we&#39;re sure you&#39;ll soon find plenty of bots created by other people to play with.</p>
<h4><a class="anchor" name="i-39m-a-developer-where-can-i-find-some-examples" href="#i-39m-a-developer-where-can-i-find-some-examples"><i class="anchor-icon"></i></a>I&#39;m a developer. Where can I find some examples?</h4>
<p>Here are two sample bots, both written in PHP:</p>
<ul>
<li><a href="/bots/samples/hellobot">Hello Bot</a> demonstrates the basics of the Telegram bot API.</li>
<li><a href="https://github.com/kolar/telegram-poll-bot">Simple Poll bot</a> is a more complete example, it supports both long-polling and Webhooks for updates.</li>
</ul>
<blockquote>
<p>Many members of our community are building bots and publishing sources.<br>We&#39;re collecting them on <a href="/bots/samples"><strong>this page »</strong></a></p>
</blockquote>
<p>Ping us on <a href="https://telegram.me/botsupport">@BotSupport</a> if you&#39;ve built a bot and would like to share it with others.</p>
<h4><a class="anchor" name="will-you-add-x-to-the-bot-api" href="#will-you-add-x-to-the-bot-api"><i class="anchor-icon"></i></a>Will you add X to the Bot API?</h4>
<p>The bot API is still pretty young. There are many potential features to consider and implement. We&#39;ll be studying what people do with their bots for a while to see which directions will be most important for the platform.</p>
<p>All bot developers are welcome to share ideas for our Bot API with our <a href="https://telegram.me/botsupport"><strong>@BotSupport</strong></a> account.</p>
<h4><a class="anchor" name="what-messages-will-my-bot-get" href="#what-messages-will-my-bot-get"><i class="anchor-icon"></i></a>What messages will my bot get?</h4>
<p><strong>1.</strong> <strong>All bots</strong>, regardless of settings, will receive:</p>
<ul>
<li>All service messages.</li>
<li>All messages from private chats with users.</li>
<li>All messages from channels where they are a member.</li>
</ul>
<p><strong>2.</strong> <strong>Bot admins</strong> and bots with <a href="/bots#privacy-mode">privacy mode</a> <strong>disabled</strong> will receive all messages except messages sent by other bots.</p>
<p><strong>3.</strong> Bots with <a href="/bots#privacy-mode">privacy mode</a> <strong>enabled</strong> will receive:</p>
<ul>
<li>Commands explicitly meant for them (e.g., /command@this_bot).</li>
<li>General commands from users (e.g. /start) <strong>if</strong> the bot was the last bot to send a message to the group.</li>
<li>Messages sent <a href="/bots/api#inline-mode">via</a> this bot.</li>
<li>Replies to any messages implicitly or explicitly meant for this bot.</li>
</ul>
<p><strong>Note</strong> that each particular message can only be available to <strong>one</strong> privacy-enabled bot at a time, i.e., a reply to bot A containing an explicit command for bot B or sent via bot C will only be available to bot A. Replies have the highest priority.</p>
<h4><a class="anchor" name="why-doesn-39t-my-bot-see-messages-from-other-bots" href="#why-doesn-39t-my-bot-see-messages-from-other-bots"><i class="anchor-icon"></i></a>Why doesn&#39;t my bot see messages from other bots?</h4>
<p>Bots talking to each other could potentially get stuck in unwelcome loops. To avoid this, we decided that bots will not be able to see messages from other bots regardless of mode.</p>
<h3><a class="anchor" name="getting-updates" href="#getting-updates"><i class="anchor-icon"></i></a>Getting Updates</h3>
<h4><a class="anchor" name="how-do-i-get-updates" href="#how-do-i-get-updates"><i class="anchor-icon"></i></a>How do I get updates?</h4>
<p>There are currently two ways of getting updates. You can either use <a href="https://core.telegram.org/bots/api#getupdates">long polling</a> or <a href="https://core.telegram.org/bots/api#setwebhook">Webhooks</a>. Please note that it&#39;s <strong>not</strong> possible to get updates via long polling while an outgoing Webhook is set.</p>
<h4><a class="anchor" name="long-polling-gives-me-the-same-updates-again-and-again" href="#long-polling-gives-me-the-same-updates-again-and-again"><i class="anchor-icon"></i></a>Long polling gives me the same updates again and again!</h4>
<p>The <a href="/bots/api#getupdates">getUpdates</a> method returns the earliest 100 unconfirmed updates. To confirm an update, use the <em>offset</em> parameter when calling getUpdates like this:</p>
<pre><code>offset = update_id of last processed update + 1</code></pre>
<p>All updates with <em>update_id</em> less than or equal to <em>offset</em> will be marked as confirmed on the server and will no longer be returned.</p>
<h4><a class="anchor" name="i-39m-having-problems-with-webhooks" href="#i-39m-having-problems-with-webhooks"><i class="anchor-icon"></i></a>I&#39;m having problems with Webhooks.</h4>
<p>If you&#39;ve set up your webhook successfully, but are not getting any updates, please remember:</p>
<ul>
<li>You need a valid SSL certificate for webhooks to work.</li>
<li>To use a self-signed certificate, you need to upload your public key certificate using the <em>certificate</em> parameter in <a href="/bots/api#setwebhook">setWebhook</a>. Please upload as InputFile, sending a String will not work.</li>
<li>Ports currently supported for Webhooks: <strong>443</strong>, <strong>80</strong>, <strong>88</strong>, <strong>8443</strong>.</li>
<li>Wildcard certificates may not be supported.</li>
<li>Redirects are not supported.</li>
<li>CN must exactly match your domain.</li>
</ul>
<blockquote>
<p>Please check out this new <a href="/bots/webhooks"><strong>WEBHOOK GUIDE</strong></a> to learn all there is to know about webhooks!</p>
</blockquote>
<h4><a class="anchor" name="i-39m-having-trouble-with-my-self-signed-certificate" href="#i-39m-having-trouble-with-my-self-signed-certificate"><i class="anchor-icon"></i></a>I&#39;m having trouble with my self-signed certificate!</h4>
<p>Please take a look at this <a href="/bots/self-signed">self-signed certificate guide</a> we made just for you. If you&#39;ve read it and still have a question, ping us on botsupport.</p>
<h4><a class="anchor" name="how-can-i-make-sure-that-webhook-requests-are-coming-from-telegr" href="#how-can-i-make-sure-that-webhook-requests-are-coming-from-telegr"><i class="anchor-icon"></i></a>How can I make sure that Webhook requests are coming from Telegram?</h4>
<p>If you&#39;d like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL you give us, e.g. www.example.com/your_token. Since nobody else knows your bot&#39;s token, you can be pretty sure it&#39;s us.</p>
<h4><a class="anchor" name="how-can-i-make-requests-in-response-to-updates" href="#how-can-i-make-requests-in-response-to-updates"><i class="anchor-icon"></i></a>How can I make requests in response to updates?</h4>
<p>This is possible if you&#39;re using webhooks. The upside is that you need less requests, the downside — that in this case it&#39;s not possible to know that such a request was successful or get its result. </p>
<p>Whenever you receive a webhook update, you have two options:</p>
<p><strong>1. Issue POST to https://api.telegram.org/bot&lt;token&gt;/method</strong></p>
<div>
<a href="/file/811140979/3/5p52TWl9X2o/5c6d684ee0d6a4399d" target="_blank"><img src="/file/811140979/3/5p52TWl9X2o/5c6d684ee0d6a4399d" title="Confirm and request" class="dev_page_image" style="width:500px;" /></a>
</div>
<p><strong>2. Reply directly and give method as JSON payload in the reply</strong></p>
<div>
<a href="/file/811140266/2/vGxiVmENAos/6cffad00cbe72be7f2" target="_blank"><img src="/file/811140266/2/vGxiVmENAos/6cffad00cbe72be7f2" title="Reply with payload" class="dev_page_image" style="width:500px;" /></a></div>
<blockquote>
<p>You may also want to look at our sample <a href="/bots/samples/hellobot">HelloBot</a>, it offers a PHP implementation of this.</p>
</blockquote>
<h3><a class="anchor" name="handling-media" href="#handling-media"><i class="anchor-icon"></i></a>Handling Media</h3>
<h4><a class="anchor" name="how-do-i-download-files" href="#how-do-i-download-files"><i class="anchor-icon"></i></a>How do I download files?</h4>
<p>Use the <a href="/bots/api#getfile">getFile</a> method. Please note that this will only work with files of up to 20 MB in size.</p>
<h4><a class="anchor" name="how-do-i-upload-a-large-file" href="#how-do-i-upload-a-large-file"><i class="anchor-icon"></i></a>How do I upload a large file?</h4>
<p>Bots can currently send files of any type of up to 50 MB in size, so yes, very large files won&#39;t work for now. Sorry. This limit may be changed in the future.</p>
<h4><a class="anchor" name="can-i-count-on-file-ids-to-be-persistent" href="#can-i-count-on-file-ids-to-be-persistent"><i class="anchor-icon"></i></a>Can I count on file_ids to be persistent?</h4>
<p>Yes, file_ids can be treated as persistent.</p>
<h3><a class="anchor" name="broadcasting-to-users" href="#broadcasting-to-users"><i class="anchor-icon"></i></a>Broadcasting to Users</h3>
<h4><a class="anchor" name="my-bot-is-hitting-limits-how-do-i-avoid-this" href="#my-bot-is-hitting-limits-how-do-i-avoid-this"><i class="anchor-icon"></i></a>My bot is hitting limits, how do I avoid this?</h4>
<p>When sending messages inside a particular chat, avoid sending more than one message per second. We may allow short bursts that go over this limit, but eventually you&#39;ll begin receiving 429 errors.</p>
<p>If you&#39;re sending bulk notifications to multiple users, the API will not allow more than 30 messages per second or so. Consider spreading out notifications over large intervals of 8—12 hours for best results.</p>
<p>Also note that your bot will not be able to send more than 20 messages per minute to the same group.</p>
<h4><a class="anchor" name="how-can-i-message-all-of-my-bot-39s-subscribers-at-once" href="#how-can-i-message-all-of-my-bot-39s-subscribers-at-once"><i class="anchor-icon"></i></a>How can I message all of my bot&#39;s subscribers at once?</h4>
<p>Unfortunately, at this moment we don&#39;t have methods for sending bulk messages, e.g. notifications. We may add something along these lines in the future.</p>
<p>In order to avoid hitting our limits when sending out mass notifications, consider spreading them over longer intervals, e.g. 8-12 hours. The API will not allow bulk notifications to more than ~30 users per second, if you go over that, you&#39;ll start getting 429 errors.</p>
<p>See also: <a href="#my-bot-is-hitting-limits-how-do-i-avoid-this">How to avoid hitting limits?</a></p>
<hr>
<blockquote>
<p>If you&#39;ve got questions that are not answered on this page, ping us at <a href="https://telegram.me/botsupport">@BotSupport</a> in Telegram.<br>We welcome any suggestions for the Bot Platform and API.</p>
</blockquote>
</div>
</div>
</div>
</div>
<div class="footer_wrap">
<div class="footer_columns_wrap footer_desktop">
<div class="footer_column footer_column_telegram">
<h5>Telegram</h5>
<div class="footer_telegram_description"></div>
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.
</div>
<div class="footer_column">
<h5><a href="//telegram.org/faq">About</a></h5>
<ul>
<li><a href="//telegram.org/faq">FAQ</a></li>
2022-09-09 12:10:24 +02:00
<li><a href="//telegram.org/privacy">Privacy</a></li>
2022-09-09 23:58:59 +02:00
<li><a href="//telegram.org/press">Press</a></li>
2022-05-14 00:37:40 +02:00
</ul>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/apps#mobile-apps">Mobile Apps</a></h5>
<ul>
<li><a href="//telegram.org/dl/ios">iPhone/iPad</a></li>
2022-09-09 23:58:59 +02:00
<li><a href="//telegram.org/android">Android</a></li>
<li><a href="//telegram.org/dl/web">Mobile Web</a></li>
2022-05-14 00:37:40 +02:00
</ul>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/apps#desktop-apps">Desktop Apps</a></h5>
<ul>
<li><a href="//desktop.telegram.org/">PC/Mac/Linux</a></li>
<li><a href="//macos.telegram.org/">macOS</a></li>
<li><a href="//telegram.org/dl/web">Web-browser</a></li>
</ul>
</div>
<div class="footer_column footer_column_platform">
<h5><a href="/">Platform</a></h5>
<ul>
<li><a href="/api">API</a></li>
<li><a href="//translations.telegram.org/">Translations</a></li>
<li><a href="//instantview.telegram.org/">Instant View</a></li>
</ul>
</div>
</div>
<div class="footer_columns_wrap footer_mobile">
<div class="footer_column">
<h5><a href="//telegram.org/faq">About</a></h5>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/blog">Blog</a></h5>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/apps">Apps</a></h5>
</div>
<div class="footer_column">
<h5><a href="/">Platform</a></h5>
</div>
<div class="footer_column">
2024-02-15 05:47:18 +01:00
<h5><a href="//telegram.org/press">Press</a></h5>
2022-05-14 00:37:40 +02:00
</div>
</div>
</div>
</div>
2022-12-10 23:50:15 +01:00
<script src="/js/main.js?47"></script>
2022-05-14 00:37:40 +02:00
<script>backToTopInit("Go up");
removePreloadInit();
</script>
</body>
</html>