<p>If you are new to Telegram bots, we recommend checking out our <ahref="/bots"><strong>Introduction to Bots</strong></a> first.<br>You may also find the <strong><ahref="/bots/api">Bot API Manual</a></strong> useful.</p>
<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 <ahref="https://telegram.me/botfather">@BotFather</a>, then connect it to your backend server via our <ahref="/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're sure you'll soon find plenty of bots created by other people to play with.</p>
<h4><aclass="anchor"name="i-39m-a-developer-where-can-i-find-some-examples"href="#i-39m-a-developer-where-can-i-find-some-examples"><iclass="anchor-icon"></i></a>I'm a developer. Where can I find some examples?</h4>
<p>Here are two sample bots, both written in PHP:</p>
<ul>
<li><ahref="/bots/samples/hellobot">Hello Bot</a> demonstrates the basics of the Telegram bot API.</li>
<li><ahref="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>
<p>Many members of our community are building bots and publishing sources.<br>We're collecting them on <ahref="/bots/samples"><strong>this page »</strong></a></p>
<p>Ping us on <ahref="https://telegram.me/botsupport">@BotSupport</a> if you've built a bot and would like to share it with others.</p>
<h4><aclass="anchor"name="will-you-add-x-to-the-bot-api"href="#will-you-add-x-to-the-bot-api"><iclass="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'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 <ahref="https://telegram.me/botsupport"><strong>@BotSupport</strong></a> account.</p>
<h4><aclass="anchor"name="what-messages-will-my-bot-get"href="#what-messages-will-my-bot-get"><iclass="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 <ahref="/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 <ahref="/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 <ahref="/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><aclass="anchor"name="why-doesn-39t-my-bot-see-messages-from-other-bots"href="#why-doesn-39t-my-bot-see-messages-from-other-bots"><iclass="anchor-icon"></i></a>Why doesn'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>
<h4><aclass="anchor"name="how-do-i-get-updates"href="#how-do-i-get-updates"><iclass="anchor-icon"></i></a>How do I get updates?</h4>
<p>There are currently two ways of getting updates. You can either use <ahref="https://core.telegram.org/bots/api#getupdates">long polling</a> or <ahref="https://core.telegram.org/bots/api#setwebhook">Webhooks</a>. Please note that it's <strong>not</strong> possible to get updates via long polling while an outgoing Webhook is set.</p>
<h4><aclass="anchor"name="long-polling-gives-me-the-same-updates-again-and-again"href="#long-polling-gives-me-the-same-updates-again-and-again"><iclass="anchor-icon"></i></a>Long polling gives me the same updates again and again!</h4>
<p>The <ahref="/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><aclass="anchor"name="i-39m-having-problems-with-webhooks"href="#i-39m-having-problems-with-webhooks"><iclass="anchor-icon"></i></a>I'm having problems with Webhooks.</h4>
<p>If you've set up your webhook successfully, but are not getting any updates, please remember:</p>
<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 <ahref="/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 <ahref="/bots/webhooks"><strong>WEBHOOK GUIDE</strong></a> to learn all there is to know about webhooks!</p>
<h4><aclass="anchor"name="i-39m-having-trouble-with-my-self-signed-certificate"href="#i-39m-having-trouble-with-my-self-signed-certificate"><iclass="anchor-icon"></i></a>I'm having trouble with my self-signed certificate!</h4>
<p>Please take a look at this <ahref="/bots/self-signed">self-signed certificate guide</a> we made just for you. If you've read it and still have a question, ping us on botsupport.</p>
<h4><aclass="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"><iclass="anchor-icon"></i></a>How can I make sure that Webhook requests are coming from Telegram?</h4>
<p>If you'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's token, you can be pretty sure it's us.</p>
<h4><aclass="anchor"name="how-can-i-make-requests-in-response-to-updates"href="#how-can-i-make-requests-in-response-to-updates"><iclass="anchor-icon"></i></a>How can I make requests in response to updates?</h4>
<p>This is possible if you're using webhooks. The upside is that you need less requests, the downside — that in this case it's not possible to know that such a request was successful or get its result. </p>
<ahref="/file/811140979/3/5p52TWl9X2o/5c6d684ee0d6a4399d"target="_blank"><imgsrc="/file/811140979/3/5p52TWl9X2o/5c6d684ee0d6a4399d"title="Confirm and request"class="dev_page_image"style="width:500px;"/></a>
<ahref="/file/811140266/2/vGxiVmENAos/6cffad00cbe72be7f2"target="_blank"><imgsrc="/file/811140266/2/vGxiVmENAos/6cffad00cbe72be7f2"title="Reply with payload"class="dev_page_image"style="width:500px;"/></a></div>
<h4><aclass="anchor"name="how-do-i-upload-a-large-file"href="#how-do-i-upload-a-large-file"><iclass="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't work for now. Sorry. This limit may be changed in the future.</p>
<h4><aclass="anchor"name="can-i-count-on-file-ids-to-be-persistent"href="#can-i-count-on-file-ids-to-be-persistent"><iclass="anchor-icon"></i></a>Can I count on file_ids to be persistent?</h4>
<h3><aclass="anchor"name="broadcasting-to-users"href="#broadcasting-to-users"><iclass="anchor-icon"></i></a>Broadcasting to Users</h3>
<h4><aclass="anchor"name="my-bot-is-hitting-limits-how-do-i-avoid-this"href="#my-bot-is-hitting-limits-how-do-i-avoid-this"><iclass="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'll begin receiving 429 errors.</p>
<p>If you'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>
<h4><aclass="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"><iclass="anchor-icon"></i></a>How can I message all of my bot's subscribers at once?</h4>
<p>Unfortunately, at this moment we don'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'll start getting 429 errors.</p>
<p>If you've got questions that are not answered on this page, ping us at <ahref="https://telegram.me/botsupport">@BotSupport</a> in Telegram.<br>We welcome any suggestions for the Bot Platform and API.</p>