mirror of
https://github.com/MarshalX/telegram-crawler.git
synced 2024-12-18 12:49:16 +01:00
832 lines
57 KiB
HTML
832 lines
57 KiB
HTML
<!DOCTYPE html>
|
||
<html class="">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>Marvin's Marvellous Guide to All Things Webhook</title>
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta property="description" content="We currently support two ways of processing bot updates, getUpdates and setWebhook. getUpdates is a pull mechanism, setwebhook…">
|
||
<meta property="og:title" content="Marvin's Marvellous Guide to All Things Webhook">
|
||
<meta property="og:image" content="https://core.telegram.org/file/811140281/1/5le8eVE7mPk.261973/25ba8c07609aef2310">
|
||
<meta property="og:description" content="We currently support two ways of processing bot updates, getUpdates and setWebhook. getUpdates is a pull mechanism, setwebhook…">
|
||
<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">
|
||
|
||
<link href="/css/telegram.css?236" rel="stylesheet" media="screen">
|
||
<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/webhooks" >Marvin's Marvellous Guide to All Things…</a></li></ul></div>
|
||
<h1 id="dev_page_title">Marvin's Marvellous Guide to All Things Webhook</h1>
|
||
|
||
<div id="dev_page_content"><!-- scroll_nav -->
|
||
|
||
<p>We currently support two ways of processing bot updates, <a href="https://core.telegram.org/bots/api#getting-updates"><strong>getUpdates</strong></a> and <a href="/bots/api#setwebhook"><strong>setWebhook</strong></a>. <strong>getUpdates</strong> is a pull mechanism, <strong>setwebhook</strong> is push. Although the concept of a webhook is fairly simple, the setup of the individual components has proven to be tricky for many. This guide provides some extra information for those of you brave enough to venture into the art of the webhook.</p>
|
||
<p>There are some advantages of using a webhook over getUpdates. As soon as an update arrives, we’ll kindly deliver it to your bot for processing.</p>
|
||
<p><strong>This:</strong></p>
|
||
<pre><code>1. Avoids your bot having to ask for updates frequently.
|
||
2. Avoids the need for some kind of polling mechanism in your code.</code></pre>
|
||
<p>Other advantages may include saving some potential CPU cycles and an increase in response time, these things however depend heavily on the usage pattern of your bot.</p>
|
||
<p>Setting a webhook means you supplying Telegram with a location in the form of a URL, on which your bot listens for updates. We need to be able to connect and post updates to that URL. </p>
|
||
<p>To ensure that we can do that, there are some basic requirements:</p>
|
||
<h3><a class="anchor" name="the-short-version" href="#the-short-version"><i class="anchor-icon"></i></a>The short version</h3>
|
||
<p>You'll need a server that:</p>
|
||
<ul>
|
||
<li>Supports IPv4, IPv6 is currently not supported for webhooks.</li>
|
||
<li>Accepts incoming POSTs from subnets <code>149.154.160.0/20</code> and <code>91.108.4.0/22</code> on port 443, 80, 88, or 8443. </li>
|
||
<li>Is able to handle TLS1.2(+) HTTPS-traffic. </li>
|
||
<li>Provides a supported, verified or self-signed certificate.</li>
|
||
<li>Uses a CN or SAN that matches the domain you’ve supplied on setup.</li>
|
||
<li>Supplies all intermediate certificates to complete a verification chain.</li>
|
||
</ul>
|
||
<p>That’s almost all there’s to it.<br>If you decide to limit traffic to our specific range of addresses, keep an eye on this document whenever you seem to run into trouble. Our IP-range might change in the future. </p>
|
||
<h3><a class="anchor" name="the-longer-version" href="#the-longer-version"><i class="anchor-icon"></i></a>The longer version</h3>
|
||
<ul>
|
||
<li><h4><a class="anchor" name="a-domain-name" href="#a-domain-name"><i class="anchor-icon"></i></a>A domain name</h4>
|
||
<p>Setting a webhook needs a URL for us to post to. For that you'll need a server with a domain name. If you don't have one, you'll need to obtain one first. Telegram currently doesn't offer hosting or domain name services. There are quite a few VPS/Web hosting providers around the internet, feel free to pick one to your liking.<br>If you're using a self-signed certificate, you may use the IP as a CN, instead of the domain name.<br><a href="https://core.telegram.org/bots/webhooks#how-do-i-get-a-server-with-a-domain-name">How do I get a server with a domain name?</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="an-open-port" href="#an-open-port"><i class="anchor-icon"></i></a>An open port</h4>
|
||
<p>A webhook needs an open port on your server. We currently support the following ports: <strong>443, 80, 88</strong> and <strong>8443</strong>. Other ports are not supported and will not work. Make sure your bot is running on one of those supported ports, and that the bot is reachable via its public address.</p>
|
||
<pre><code>If you want to limit access to Telegram only, please allow traffic from 149.154.160.0/20 and 91.108.4.0/22.
|
||
Whenever something stops working in the future, please check this document again as
|
||
the range might expand or change.</code></pre>
|
||
<p><a href="https://core.telegram.org/bots/webhooks#how-do-i-check-for-open-ports-or-limit-access-to-my-bot">How do I check for open ports or limit access to my bot?</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="always-ssl-tls" href="#always-ssl-tls"><i class="anchor-icon"></i></a>Always SSL/TLS</h4>
|
||
<p>A webhook requires SSL/TLS encryption, no matter which port is used. It's not possible to use a plain-text HTTP webhook. You shouldn't want to either, for the sake of your bot and users.<br><a href="https://core.telegram.org/bots/webhooks#ssl-tls-what-is-it-and-why-do-i-have-to-handle-this-for-a-webhoo">SSL/TLS, why do I have to handle this for a webhook?</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="not-all-ssl-tls-is-equal" href="#not-all-ssl-tls-is-equal"><i class="anchor-icon"></i></a>Not all SSL/TLS is equal</h4>
|
||
<p>We support any SSL/TLS version TLS1.2 and up for your webhook. This means that <strong>SSLV2/3/TLS1.0/TSL1.1 are NOT supported</strong>, due to security issues associated with those older versions.<br><a href="https://core.telegram.org/bots/webhooks#how-do-i-check-that-im-handling-the-right-version">How do I check that I’m handling the right version?</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="ssl-needs-a-certificate" href="#ssl-needs-a-certificate"><i class="anchor-icon"></i></a>SSL needs a certificate</h4>
|
||
<p>The common name (CN) of your certificate (self-signed or verified) has to match the domain name where your bot is hosted. You may also use a subject alternative name (SAN), that matches the domain for your webhook. Server Name Indication (SNI)-routing is supported. If you're using a self-signed certificate, you may use the IP as a CN, instead of the domain name.<br><a href="https://core.telegram.org/bots/webhooks#a-certificate-where-do-i-get-one-and-how">A certificate, where do I get one, and how?</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="verified-or-self-signed" href="#verified-or-self-signed"><i class="anchor-icon"></i></a>Verified or self-signed</h4>
|
||
<p>A certificate can either be verified or self-signed. Setting a webhook with a self-signed certificate differs a little from setting a webhook with a verified certificate. Ensure you're using the correct setup for the type of certificate you've chosen for your webhook.<br><a href="https://core.telegram.org/bots/webhooks#how-do-i-set-a-webhook-for-either-type">How do I set a webhook for either type?</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="supported-certificates" href="#supported-certificates"><i class="anchor-icon"></i></a>Supported certificates</h4>
|
||
<p>Not all verified certificates are supported. Certificates are based on a network of trust and come in a chain. Trusting your verified certificate means we have to trust the provider of that certificate, the Certificate Authority (and hence its root certificate). Before you pick a certificate provider, Check <a href="https://packages.ubuntu.com/bionic/all/ca-certificates/filelist">this list</a> to make sure that we actually trust their root certificate.<br><a href="https://core.telegram.org/bots/webhooks#an-untrusted-root">What if my root certificate isn’t on that list?</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="an-untrusted-root" href="#an-untrusted-root"><i class="anchor-icon"></i></a>An Untrusted root</h4>
|
||
<p>Ok, so you already had a certificate installed and just discovered it’s not on our list.<br>Start by ignoring it, and just try to set it. We occasionally add extra root certificates to keep up with popular demand, so the list isn't always exhaustive. Unlucky after all? We'll allow you to supply an unsupported root certificate when setting the webhook. This method is nearly identical to setting a self-signed certificate webhook. Instead of your self-signed certificate you'll be sending us the root certificate as inputFile.<br><a href="https://core.telegram.org/bots/webhooks#setting-a-verified-webhook-with-an-untrusted-root">Setting a verified webhook with an untrusted root</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="intermediate-certificates" href="#intermediate-certificates"><i class="anchor-icon"></i></a>Intermediate certificates</h4>
|
||
<p>Some verified certificates require an intermediate certificate. In this construction the provider of your verified certificate has used their root certificate to sign an intermediate certificate. This intermediate certificate is then used to sign your verified certificate. You'll need to provide the intermediate certificate for us to be able to verify the chain of trust. CA's that use this type of chain supply an intermediate certificate.<br><a href="https://core.telegram.org/bots/webhooks#supplying-an-intermediate-certificate">Supplying an intermediate certificate</a></p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="more-information" href="#more-information"><i class="anchor-icon"></i></a>More information</h4>
|
||
<p>Since we know webhooks can be a tad overwhelming, we’re working on a little digital assistant that’ll try and help you with the most common problems, it's not nearly perfect, but you may try using @CanOfWormsBot to check if your chain of certificates is installed correctly before contacting support.</p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="testing-your-bot" href="#testing-your-bot"><i class="anchor-icon"></i></a>Testing your bot</h4>
|
||
<p>We took the liberty of adding a <a href="https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates">set of example updates</a>. They come in handy when testing your bot, no matter which method of getting updates you might be using.</p>
|
||
</li>
|
||
<li><h4><a class="anchor" name="don-39t-panic" href="#don-39t-panic"><i class="anchor-icon"></i></a>Don't panic.</h4>
|
||
<p>If by now you're looking for your fishing gear because we've mentioned ports and hooks or you're about to Google what kind of bait URL and TLS exactly are, this guide might not be completely for you. You’re quite likely still a brilliant bot programmer, don’t worry. Perhaps this whole webhook thing is just new to you, not all is lost. If you currently have a working getUpdates situation, it's a good idea to pick up this guide again on a rainy Sunday afternoon and take your time to read up on some subjects around the internet. This <a href="http://www.douglasadams.com/creations/hhgg.html">guide</a> can only contain a finite amount of information after all.</p>
|
||
</li>
|
||
</ul>
|
||
<h3><a class="anchor" name="the-verbose-version" href="#the-verbose-version"><i class="anchor-icon"></i></a>The verbose version</h3>
|
||
<h5><a class="anchor" name="how-do-i-get-a-server-with-a-domain-name" href="#how-do-i-get-a-server-with-a-domain-name"><i class="anchor-icon"></i></a>How do I get a server with a domain name?</h5>
|
||
<p>If you use a webhook, we have to deliver requests to your bot to a server we can reach. So yes, you need a server we can connect to. It can be anywhere in the galaxy, if you ensure we can reach the server by domain name (or at least via IP for a self-signed certificate), it will work just fine.</p>
|
||
<p>There are quite a few ways to get this done, as a novice however it's likely that you're not directly jumping at the chance of crafting this from scratch. Actually, as a novice, we recommend you don't. It's likely to be a complex and long ride.</p>
|
||
<p><strong>If you got stuck here, make a choice:</strong></p>
|
||
<ul>
|
||
<li><p>You use getUpdates at the moment and it works, keep it that way. Especially if you're running your bot from a nice machine that does well. There is nothing wrong with using getUpdates.</p>
|
||
</li>
|
||
<li><p>Go with a hosted service and let a bunch of professionals worry about things like registering a domain, setting up DNS, a web server, securing it and so on.</p>
|
||
</li>
|
||
</ul>
|
||
<pre><code>If you're going with a hosted service, make sure to look for a hosting provider that
|
||
not only supports your code’s needs, for example: support for your PHP version,
|
||
but one that also handles SSL and allows you to create/deploy certificates.</code></pre>
|
||
<ul>
|
||
<li>Go crazy, dive on the internet and start reading. Once you’re confident that you’ve got all the basic theories down, find yourself a nice hosted VPS or roll your own machine at home and get back to us here.</li>
|
||
</ul>
|
||
<h5><a class="anchor" name="how-do-i-check-for-open-ports-or-limit-access-to-my-bot" href="#how-do-i-check-for-open-ports-or-limit-access-to-my-bot"><i class="anchor-icon"></i></a>How do I check for open ports or limit access to my bot?</h5>
|
||
<p>So you have the hosting thing down and all is good so far, however, when you enter the address of your bot in your browser it seems unreachable.</p>
|
||
<p>Explaining every firewall or web server solution in detail isn't possible for us, which we hope you understand. If you’re running a hosted solution, you’re more likely to have a nice UI where you configure these settings. Head to your configuration panel and check all of them. If you’re on a Linux based VPS with shell access, we have some tips for you:</p>
|
||
<ul>
|
||
<li>Make sure your bot process is indeed configured to listen on the port you're using.<br><code>netstat –ln | grep portnumber</code><br>Shows you if your bot is actually listening for incoming requests on the port you expect.<br><code>sudo lsof -i | grep process name</code><br>Is a simple way to check if that’s actually being listened on by the process your bot is using.</li>
|
||
</ul>
|
||
<ul>
|
||
<li>Make sure it’s listening correctly.<br>Your bot has to listen on the address you’ve exposed to the outside <code>(your public IP)</code>, it can also listen on all addresses <code>(*: or 0.0.0.0)</code>.<br>The <code>netstat</code> and <code>lsof</code>-commands mentioned above assist in checking this. If nothing shows up, it is time to check your configuration and fix it. Set the correct IP, make sure it’s listening on a supported port and fire away! Just use a Web Browser to check if you’re reachable. The problem can be in the configuration of your bot, your web server virtual host configuration, or the servers binding configuration.</li>
|
||
</ul>
|
||
<ul>
|
||
<li><p>If you still can’t reach your address, check your firewall.<br><code>sudo iptables –L</code><br><strong>OR</strong><br><code>sudo ufw status verbose</code> (Ubuntu)<br>Gives you some insight in the current firewall settings.</p>
|
||
</li>
|
||
<li><p>If it looks like you’re blocking incoming traffic, let’s fix that.<br><code>sudo iptables –A INPUT –p tcp –m tcp –dport portnumber -j ACCEPT</code><br><strong>OR</strong><br><code>sudo ufw allow portnumber/tcp</code><br>Allows incoming traffic on all interfaces to the specified tcp port.<br><code>sudo iptables –A INPUT –i interfacename –p tcp –m tcp –dport portnumber -j ACCEPT</code><br><strong>OR</strong><br><code>sudo ufw allow in on interfacename to any port portnumber proto tcp</code><br>Allows incoming traffic to a specific interface and a specific port from everywhere.<br><code>sudo ifconfig</code><br>Helps you find the interface with the public address you’re going to use.</p>
|
||
</li>
|
||
</ul>
|
||
<pre><code>If you use iptables, make sure to actually SAVE after changing the configuration.
|
||
On a Debian based system the iptables-persistent package is be a good option.
|
||
RHEL/CentOS offers a service iptables save -command.
|
||
A quick online search for "YOUROPERATINGSYSTEM save iptables" also helps.</code></pre>
|
||
<ul>
|
||
<li>If you’re just looking for some hints on how to limit incoming traffic:<br><code>sudo iptables –A INPUT –i interfacename –p tcp –m iprange -s 149.154.160.0/20,91.108.4.0/22 –dport portnumber -j ACCEPT</code><br><strong>OR</strong><pre><code>sudo ufw allow in on interfacename to any port portnumber proto tcp from 149.154.160.0/20
|
||
sudo ufw allow in on interfacename to any port portnumber proto tcp from 91.108.4.0/22</code></pre>
|
||
Allows incoming traffic to a specific interface and a specific port from a specific range of addresses. (ufw is using a subnet mask in the example, ranging from 192-255)</li>
|
||
</ul>
|
||
<p>That’s all for our examples. More information on best practices for setting up your firewall, on whichever operating system you prefer for your bot, is best found on the internet.</p>
|
||
<h5><a class="anchor" name="ssl-tls-what-is-it-and-why-do-i-have-to-handle-this-for-a-webhoo" href="#ssl-tls-what-is-it-and-why-do-i-have-to-handle-this-for-a-webhoo"><i class="anchor-icon"></i></a>SSL/TLS, what is it and why do I have to handle this for a webhook?</h5>
|
||
<p>You’re already familiar with it in some form or another. Whenever you see that (nicely green) lock in your browser bar, you know it’s reasonably safe to assume that you’ve landed on the site you actually wanted to visit. If you see the green lock, that's SSL/TLS in action. If you want to learn more about how SSL/TLS works in general, it's best to search the internet.</p>
|
||
<p>The main difference between getUpdates and a webhook is the way the connection takes place. getUpdates means you'll connect to our server, a webhook means we'll be connecting to your server instead. Connecting to your server has to be done secure, we have to know for sure it's you we're talking to after all. This means you'll have to handle all that server side encryption stuff, virtually presenting us with a green lock. If you use a web server for us to post to, you need to support SSL/TLS handling on the port/virtual host of your choice. An online search for “YOURWEBSERVER enable HTTPS” will help you.</p>
|
||
<p>Not using a regular web server? Have a look at our <a href="https://core.telegram.org/bots/samples">example page</a>, most examples there include code for handling SSL/TLS in a webhook setup.</p>
|
||
<h5><a class="anchor" name="how-do-i-check-that-im-handling-the-right-version" href="#how-do-i-check-that-im-handling-the-right-version"><i class="anchor-icon"></i></a>How do I check that I’m handling the right version?</h5>
|
||
<p>You just read up on the whole SSL/TLS stuff, figured out that it’s not all that bad to setup and we add some more requirements. Here are some tips to check if you’re indeed supporting at least TLS1.2.</p>
|
||
<ul>
|
||
<li><p>Several online services exist that allow you to check your certificate installation,<br>They give you an overview of your supported TLS versions/Cipher suites and other details. Search online for <strong>Symantec crypto report</strong> or <strong>Qualys ssl</strong>. Both supply tools to verify your setup.</p>
|
||
</li>
|
||
<li><p>Checking locally can also be done, in several ways, here are three options,</p>
|
||
<ul>
|
||
<li><p>Go simple:<br>Using Chrome as a browser? Open up the URL to your bot and inspect the certificate details. If you’re supporting TLS Chrome tells you so in the security overview tab. Other browsers are likely able to give you similar basic information.</p>
|
||
</li>
|
||
<li><p>Using curl:<br><code>curl --tlsv1.2 -v -k https://yourbotdomain:yourbotport/</code><br>You can add <code>--tlsv1.2</code> to force curl into using TLS1.2 when trying to connect. <code>-k</code> is optional and used to check against a self-signed certificate. <code>yourbotdomain</code> is the public hostname your webhook is running on. For local testing purposes you can also use the IP. <code>yourbotport</code> is the port you’re using.</p>
|
||
</li>
|
||
<li><p>Using OpenSSL<br><code>openssl s_client -tls1_2 -connect yourbotdomain:yourbotport -servername yourbotdomain</code><br>You can add <code>-tls1_2</code> to force OpenSSL into using TLS1.2 when trying to connect. <code>yourbotdomain</code> is the public hostname your webhook is running on. For local testing purposes you can also use the IP. <code>yourbotport</code> is the port you’re using. Note that https:// isn’t used for OpenSSL. <code>-servername</code> is optional, and included here for some shared hosters, which use SNI to route traffic to the correct domain. When SNI is used you’ll notice that your server appears to be returning a certificate for a different domain than your own. Adding <code>-servername yourbotdomain</code> ensures that SNI negotiation is done, and the correct certificate is returned.</p>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li><p>Some additional configuration pointers</p>
|
||
<ul>
|
||
<li>Forcing TLS in your virtual host on Apache:<br><code>SSLProtocol -all +TLSv1.2</code></li>
|
||
<li>Forcing TLS in your virtual host on Nginx:<br><code>ssl_protocols TLSv1.2;</code></li>
|
||
<li>Force TLS for your Java virtual machine through system properties:<br><code>-Dhttps.protocols=TLSv1.2 -Djdk.tls.client.protocols=TLSv1.2</code></li>
|
||
<li>Enabling ssl debug for your JVM:<br><code>-Djavax.net.debug=ssl,handshake,record</code></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>Other tools that may help in debugging issues:</p>
|
||
<ul>
|
||
<li><strong>Wireshark</strong>: excellent packet capturing</li>
|
||
<li><strong>Tcpdump</strong>: equally excellent and doesn’t need a GUI</li>
|
||
<li><strong>Charles</strong>: web debugging proxy</li>
|
||
<li><strong>Fiddler</strong>: web debugging proxy</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<h5><a class="anchor" name="a-certificate-where-do-i-get-one-and-how" href="#a-certificate-where-do-i-get-one-and-how"><i class="anchor-icon"></i></a>A certificate, where do I get one and how?</h5>
|
||
<p>You need a certificate, pick on of these types;</p>
|
||
<ul>
|
||
<li><a href="https://core.telegram.org/bots/webhooks#a-verified-supported-certificate">A verified, supported certificate</a></li>
|
||
<li><p><a href="https://core.telegram.org/bots/webhooks#a-self-signed-certificate">A self-signed certificate</a></p>
|
||
</li>
|
||
<li><h5><a class="anchor" name="a-verified-supported-certificate" href="#a-verified-supported-certificate"><i class="anchor-icon"></i></a>A verified, supported certificate</h5>
|
||
<p>Using a verified certificate means you already have, or will obtain, a certificate backed by a trusted certificate authority (CA). There are many ways to acquire a verified certificate, paid or free. Two popular examples of free suppliers are <strong>StartSSL</strong> and <strong>Let’s Encrypt</strong>. You’re welcome to pick another. Just make sure first the supplier is likely to be supported.<br>Check <a href="https://packages.ubuntu.com/bionic/all/ca-certificates/filelist">this list</a> before selecting a CA.<br>Once you’ve picked a CA and validated your identity with them, you can craft your certificate. This frequently starts by generating a CSR (Certificate Signing Request). Generating a CSR is done either through your host machine, or online via the tools provided by the CA.</p>
|
||
</li>
|
||
<li><p>Here is an example (PEM format output).</p>
|
||
<ul>
|
||
<li>Using OpenSSL:<br><code>openssl req -newkey rsa:2048 -keyout yourprivatekey.key -out yoursigningrequest.csr</code></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<pre><code>----
|
||
Generating a 2048 bit RSA private keywriting new private key to yourprivatekey.key
|
||
Enter PEM pass phrase: enter a password for your key here
|
||
Verifying - Enter PEM pass phrase: confirm the entered password
|
||
-----
|
||
You are about to be asked to enter information that will be incorporated
|
||
into your certificate request.
|
||
What you are about to enter is what is called a Distinguished Name or a DN.
|
||
There are quite a few fields but you can leave some blank
|
||
For some fields there will be a default value,If you enter '.',
|
||
the field will be left blank.-----
|
||
Country Name (2 letter code) [AU]:
|
||
State or Province Name (full name) [Some-State]:
|
||
Locality Name (eg, city) []:
|
||
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
|
||
Organizational Unit Name (eg, section) []:
|
||
Common Name (e.g. server FQDN or YOUR name) []: yourbotdomainname
|
||
Email Address []:
|
||
Please enter the following 'extra' attributes
|
||
to be sent with your certificate request
|
||
A challenge password []:
|
||
An optional company name []:
|
||
---</code></pre>
|
||
<ul>
|
||
<li><p>Another example:</p>
|
||
<ul>
|
||
<li>Using Java keytool:<br><code>keytool -genkey -alias yourbotdomainname -keyalg RSA -keystore yourkeystore.jks -keysize 2048</code></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<pre><code>---
|
||
Enter keystore password:
|
||
Re-enter new password:
|
||
What is your first and last name? [Unknown]: yourbotdomainname
|
||
What is the name of your organizational unit? [Unknown]:
|
||
What is the name of your organization? [Unknown]:
|
||
What is the name of your City or Locality? [Unknown]:
|
||
What is the name of your State or Province? [Unknown]:
|
||
What is the two-letter country code for this unit? [Unknown]:
|
||
Is CN=test.telegram.org, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
|
||
[no]: yes
|
||
Enter key password for yourbotdomainname
|
||
(RETURN if same as keystore password):
|
||
---</code></pre>
|
||
<p>This generates the initial keystore, from which you can then create a CSR like this:</p>
|
||
<p><code>keytool -certreq -alias yourbotdomainname -keystore yourkeystore.jks -file yourbotdomainname.csr</code></p>
|
||
<pre><code>---
|
||
Enter keystore password:
|
||
---</code></pre>
|
||
<p>To validate your certificate the Common Name (CN) has to match your webhook domain. Example, if you’re using <a href="https://www.example.com/example.php"><a href="https://www.example.com/example.php">https://www.example.com/example.php</a></a> as a webhook address, the certificate CN has to be <a href="http://www.example.com">www.example.com</a>.<br>So you need an <strong>exact match</strong> of the FQDN you’re setting for the webhook</p>
|
||
<p>There is an exception, if you’re using a SAN (Subject Alternative Name) the webhook address can either match the CN of your certificate, <strong>OR</strong> one of the SANs provided in the certificate. In most cases you’ll be using the CN.</p>
|
||
<p>Create your CSR and supply the contents of the file to your CA. Most CA’s are kind enough to give you an example command of the input format they expect.</p>
|
||
<p><code>cat yoursigningrequest.csr</code> <strong>or</strong> <code>cat yourbotdomainname.csr</code><br>Lets you have a look at the CSR we just generated:</p>
|
||
<div>
|
||
<a href="/file/811140281/1/5le8eVE7mPk.261973/25ba8c07609aef2310" target="_blank"><img src="/file/811140281/1/5le8eVE7mPk.261973/25ba8c07609aef2310" title="csrexample.jpg, 255.83Kb" height="60%" width="60%" class="dev_page_image" /></a>
|
||
</div>
|
||
|
||
<p>That doesn’t seem to informative, but we can deduce that the file is in PEM format (ASCII base64 encoded) and contains a certificate signing request. Luckily it is possible to look at the human readable contents of the CSR. Use the following commands to double check if all fields are set correctly.</p>
|
||
<ul>
|
||
<li><p>Using OpenSSL<br><code>openssl req -text -noout -verify -in yoursigningrequest.csr</code></p>
|
||
</li>
|
||
<li><p>Using Java keytool<br><code>keytool -printcertreq -v -file yourbotdomainname.csr</code></p>
|
||
</li>
|
||
</ul>
|
||
<p>Verify your CSR and supply it to your CA to get a certificate. We’ll use StartSSL as an example here. StartSSL allows you to set up to 5 names (SAN), Their intermediate certificate is also needed for a webhook to work, which makes for a nice complete example. </p>
|
||
<p>Go to the certificates wizard, enter the required hostname(s) for your SSL certificate (this is the CN you’ve also set in the CSR and an optional SAN).</p>
|
||
<div>
|
||
<a href="/file/811140045/1/wtVcG_IghfI.78937/51e72042b1df5f28b5" target="_blank"><img src="/file/811140045/1/wtVcG_IghfI.78937/51e72042b1df5f28b5" title="sslcertwiz.jpg, 77.09Kb" height="75%" width="75%" class="dev_page_image" /></a>
|
||
</div>
|
||
|
||
<p>In the example above we’ve chosen to set a CN <code>(test.telegram.org)</code>, but also a SAN <code>(sanexample.telegram.org)</code> The CN given has to match the CN used for generating the CSR.<br>Set your CN (and optional SAN) and copy the contents of the yoursigningrequest.csr file.</p>
|
||
<div>
|
||
<a href="/file/811140068/1/5qVIwLYnqd8.116971/87a6da7b70e377f899" target="_blank"><img src="/file/811140068/1/5qVIwLYnqd8.116971/87a6da7b70e377f899" title="sslcertwiz1.jpg, 114.23Kb" height="75%" width="75%" class="dev_page_image" /></a>
|
||
</div>
|
||
|
||
<p>Paste the contents, submit and you’re done.</p>
|
||
<div>
|
||
<a href="/file/811140069/2/MVKz66N9t4o.53664/7130b06124c18c9e94" target="_blank"><img src="/file/811140069/2/MVKz66N9t4o.53664/7130b06124c18c9e94" title="sslcertwiz2.jpg, 52.41Kb" height="75%" width="75%" class="dev_page_image" /></a>
|
||
</div>
|
||
|
||
<p>Now you can download the created certificate directly. In the example used above you’ll receive a zip file with several PEM certificates. The root, intermediate and yourdomain certificate.<br>You need the <code>intermediate</code> and <code>yourdomain</code> to set a webhook with a StartSSL certificate.</p>
|
||
<p>You can inspect the set of certificates you’ve just downloaded.</p>
|
||
<ul>
|
||
<li><p>Here are some example commands:</p>
|
||
<ul>
|
||
<li><p>Using OpenSSL:<br><code>openssl x509 -in yourdomain.crt -text -noout</code></p>
|
||
</li>
|
||
<li><p>Using Java keytool:<br><code>keytool -printcert -v -yourdomain.crt</code></p>
|
||
</li>
|
||
<li><p>Using Windows:<br>StartSSL supplies certificates in PEM format with a .crt extension, on Windows you can view the contents of them with a quick double click. Extract the files or open the “Otherserver.zip” and double click each of the certificates for inspection. The details tab supplies you with extra information.<br>Make sure you have a correct CN in the <code>Subject</code>-field of the <code>yourdomain</code>-certificate. If you're using a SAN, make sure that it is listed in the Subject <code>Alternative Name</code>-field.</p>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<div>
|
||
<a href="/file/811140010/2/omTlwQW_Wpk.133258/5db0b29d43f5558413" target="_blank"><img src="/file/811140010/2/omTlwQW_Wpk.133258/5db0b29d43f5558413" title="wincert.jpg, 130.13Kb" height="50%" width="50%" class="dev_page_image" /></a>
|
||
</div>
|
||
|
||
<p>With your fresh certificates at hand, you can now continue setting your webhook.</p>
|
||
<ul>
|
||
<li><h5><a class="anchor" name="a-self-signed-certificate" href="#a-self-signed-certificate"><i class="anchor-icon"></i></a>A self-signed certificate</h5>
|
||
<p>Using a self-signed certificate means you’ll forfeit on the chain of trust backed by a CA. Instead you are the CA. For this to work, a slight difference in setup is required. Because Telegram will have no chain of trust to verify your certificate, you have to use the generated public certificate as an input file when setting the webhook. Keep in mind that the certificate file has to be uploaded as <strong>multipart/form</strong> data in <strong>PEM encoded (ASCII BASE64)</strong> format.</p>
|
||
</li>
|
||
<li><p>First let’s generate some certificates:</p>
|
||
<ul>
|
||
<li><p>Using OpenSSL:<br><code>openssl req -newkey rsa:2048 -sha256 -nodes -keyout YOURPRIVATE.key -x509 -days 365 -out YOURPUBLIC.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=YOURDOMAIN.EXAMPLE"</code><br>You’ll end up with 2 files, a private key and the public certificate file. Use <strong>YOURPUBLIC.PEM</strong> as input file for setting the webhook.</p>
|
||
</li>
|
||
<li><p>Using Java keytool:<br><code>keytool -genkey -keyalg RSA -alias YOURDOMAIN.EXAMPLE -keystore YOURJKS.jks -storepass YOURPASSWORD -validity 360 -keysize 2048</code></p>
|
||
<pre><code>What is your first and last name?
|
||
[test.telegram.org]:
|
||
What is the name of your organizational unit?
|
||
[Unknown]:
|
||
What is the name of your organization?
|
||
[Unknown]:
|
||
What is the name of your City or Locality?
|
||
[Unknown]:
|
||
What is the name of your State or Province?
|
||
[Unknown]:
|
||
What is the two-letter country code for this unit?
|
||
[Unknown]:
|
||
Is CN=test.telegram.org, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
|
||
[no]: yes</code></pre>
|
||
<p>Once done you’ll need 2 more commands to export the public certificate file from the generated store (you’ll be using the store for your JVM and the PEM for setting the webhook)</p>
|
||
</li>
|
||
<li><p>Convert the JKS to pkcs12 (intermediate step for conversion to PEM):<br><code>keytool -importkeystore -srckeystore YOURJKS.jks -destkeystore YOURPKCS.p12 -srcstoretype jks -deststoretype pkcs12</code></p>
|
||
</li>
|
||
<li><p>Convert PKCS12 to PEM (requires OpenSSL)<br><code>openssl pkcs12 -in YOURPKCS.p12 -out YOURPEM.pem -nokeys</code></p>
|
||
</li>
|
||
<li><p>Using Windows:<br>Creating a self-signed certificate using Windows native utilities is also possible, although OpenSSL binaries for Windows are available online.<br><code>certreq -new TEMPLATE.txt RequestFileOut generates a CSR.</code></p>
|
||
</li>
|
||
<li><p>TEMPLATE.txt example file:</p>
|
||
<pre><code>[NewRequest]
|
||
; At least one value must be set in this section
|
||
Subject = "CN=DOMAIN.EXAMPLE"
|
||
KeyLength = 2048
|
||
KeyAlgorithm = RSA
|
||
HashAlgorithm = sha256
|
||
;MachineKeySet = true
|
||
RequestType = Cert
|
||
UseExistingKeySet=false ;generates a new private key (for export)
|
||
Exportable = true ;makes the private key exportable with the PFX</code></pre>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<p>A self-signed certificate is generated and installed, to use the certificate for a self-signed webhook you'll have to export it in PEM format.</p>
|
||
<ul>
|
||
<li><p>Windows continued:</p>
|
||
<ul>
|
||
<li><p>You can have a look at the certificates in your store with:<br><code>certutil -store -user my</code></p>
|
||
</li>
|
||
<li><p>To export the installed certificate in DER format (intermediate step for conversion to PEM):<br><code>certutil -user -store -split my SERIALNUMBER YOURDER.der</code></p>
|
||
</li>
|
||
<li><p>Now you can convert the certificate to PEM:<br><code>certutil -encode YOURDER.der YOURPEM.pem</code><br>Remember that only the public certificate is needed as input for the self-signed webhook certificate parameter.<br><code>certmgr.msc</code> can also be used as a GUI to export the public part of self-signed certificate to PEM.</p>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<p>After following the above you'll end up with a nice self-signed certificate. You’ll still have to set the webhook, and handle SSL correctly.</p>
|
||
<h5><a class="anchor" name="how-do-i-set-a-webhook-for-either-type" href="#how-do-i-set-a-webhook-for-either-type"><i class="anchor-icon"></i></a>How do I set a webhook for either type?</h5>
|
||
<p>The setWebhook method is needed for both types. For a verified certificate with a trusted root CA, it’s enough to use the setWebhook method with just the URL parameter.</p>
|
||
<ul>
|
||
<li>A curl example for a verified certificate:<br><code>curl -F "url=https://<YOURDOMAIN.EXAMPLE>/<WEBHOOKLOCATION>" https://api.telegram.org/bot<YOURTOKEN>/setWebhook</code></li>
|
||
</ul>
|
||
<p>For a self-signed certificate an extra parameter is needed, <code>certificate</code>, with the public certificate in PEM format as data.</p>
|
||
<ul>
|
||
<li>A curl example for a self-signed certificate:<br><code>curl -F "url=https://<YOURDOMAIN.EXAMPLE>/<WEBHOOKLOCATION>" -F "certificate=@<YOURCERTIFICATE>.pem" https://api.telegram.org/bot<YOURTOKEN>/setWebhook</code></li>
|
||
</ul>
|
||
<p>The <code>-F</code> means we’re using the <code>multipart/form-data</code>-type to supply the certificate, the type of the certificate parameter is <a href="https://core.telegram.org/bots/api#inputfile">inputFile</a>. Make sure that you’re supplying the correct type.</p>
|
||
<p>Both parameters for the setWebhook method are classed as optional. Calling the method with an empty URL parameter can be used to clear a previously set webhook.</p>
|
||
<ul>
|
||
<li>A curl example to clear a previous webhook :<br><code>curl -F "url=" https://api.telegram.org/bot<YOURTOKEN>/setWebhook</code></li>
|
||
</ul>
|
||
<p>Keep in mind that the URL parameter starts with <code>https://</code> when setting a webhook. By default that means we’re knocking at your door on port 443. If you want to use another port (80,88 or 8443), you’ll have to specify the port in the URL parameter.</p>
|
||
<ul>
|
||
<li>Example:<br><code>url=https://<YOURDOMAIN.EXAMPLE>:88/<WEBHOOKLOCATION></code></li>
|
||
</ul>
|
||
<h5><a class="anchor" name="setting-a-verified-webhook-with-an-untrusted-root" href="#setting-a-verified-webhook-with-an-untrusted-root"><i class="anchor-icon"></i></a>Setting a verified webhook with an untrusted root</h5>
|
||
<p>If you already have a verified certificate and our servers don’t trust your root CA, we have an alternative way for you to set a webhook. Instead of using the setWebhook method <strong>without</strong> the <code>certificate</code> parameter, you can use the self-signed method. Your CA's root certificate has to be used as an inputFile for the <code>certificate</code> parameter.</p>
|
||
<ul>
|
||
<li>A curl example to supply an untrusted root certificate:<br><code>curl -F "url=https://<YOURDOMAIN.EXAMPLE>" -F "certificate=@<YOURCAROOTCERTIFICATE>.pem" https://api.telegram.org/bot<YOURTOKEN>/setWebhook</code><br>Before you can do this, you need the root certificate of your certificate’s CA. Most CA’s supply their root certificates in several different formats (PEM/DER/etc.). Visit your CA’s website, and download the Root certificate indicated for your verified certificate.</li>
|
||
</ul>
|
||
<p>You can use these commands to quickly convert a DER formatted root certificate to PEM:</p>
|
||
<ul>
|
||
<li><p>Using OpenSSL:<br><code>openssl x509 -inform der -in root.cer -out root.pem</code></p>
|
||
</li>
|
||
<li><p>Using Java keytool:<br><code>keytool -import -alias Root -keystore YOURKEYSTORE.JKS -trustcacerts -file ROOTCERT.CER</code><br>The root certificate needs to be imported in your keystore first:<br><code>keytool -exportcert -alias Root -file <YOURROOTPEMFILE.PEM> -rfc -keystore YOURKEYSTORE.JKS</code></p>
|
||
</li>
|
||
</ul>
|
||
<p>Once done, set your webhook with the root-pem-file and you’ll be good to go. If you need more pointers, have a look at the <a href="https://core.telegram.org/bots/webhooks#a-self-signed-certificate">self-signed</a> part of this guide.</p>
|
||
<h5><a class="anchor" name="supplying-an-intermediate-certificate" href="#supplying-an-intermediate-certificate"><i class="anchor-icon"></i></a>Supplying an intermediate certificate</h5>
|
||
<p>Once you’ve crafted your certificate, your CA might present you with a nice bundle. Most bundles contain a root certificate, your public certificate and sometimes an <strong>intermediate</strong> certificate. StartSSL is one of many CA’s that’ll supply such an intermediate beast. This certificate has to be supplied in the chain of certificates you’re presenting to us when we connect to your server. If an intermediate was used to sign your certificate but isn’t supplied to our servers, we won’t be able to verify the chain of trust and your webhook will not work.</p>
|
||
<p>If your webhook isn’t working and you’re wondering if the chain is complete:</p>
|
||
<ul>
|
||
<li>Check with your certificate provider if you need an intermediate certificate.</li>
|
||
<li>Verify your certificate chain.<pre><code>Search online for Symantec crypto report or Qualys ssl.
|
||
Both supply tools to verify your setup.</code></pre>
|
||
</li>
|
||
</ul>
|
||
<p>Here’s an example of a complete chain, note that in this case 2 intermediate certificates have been supplied.</p>
|
||
<div>
|
||
<a href="/file/811140157/1/FsbXbc0yPJA.49297/5812f355ecfcda764a" target="_blank"><img src="/file/811140157/1/FsbXbc0yPJA.49297/5812f355ecfcda764a" title="startsslexample.jpg, 48.14Kb" height="75%" width="75%" class="dev_page_image" /></a>
|
||
</div>
|
||
|
||
<p>Even though your browser might not complain when visiting your page, an incomplete chain will not work for your webhook. If your chain is incomplete we have some tips to add them to your current setup:</p>
|
||
<ul>
|
||
<li><p>Apache:<br>Add the intermediate certificate to the end of the file configured in the <code>SSLCertificateFile</code> directive of your virtual host configuration. If you’re using an older version than Apache 2.4.8, you may use the <code>SSLCertificateChainFile</code> directive instead.</p>
|
||
</li>
|
||
<li><p>Nginx:<br>Add the intermediate certificate to the end of the file configured in the <code>ssl_certificate_key</code> directive of your virtual host configuration.</p>
|
||
</li>
|
||
<li><p>A quick command for doing this correctly:<br><code>cat your_domain_name.pem intermediate.pem >> bundle.pem</code><br>Make sure the order is correct, expect failure otherwise.</p>
|
||
</li>
|
||
<li><p>Java keytool:<br><code>keytool -import -trustcacerts -alias intermediate -file intermediate.pem -keystore YOURKEYSTORE.jks</code></p>
|
||
</li>
|
||
</ul>
|
||
<p>The end result of all this is a complete certificate chain, backed by either a root certificate we trust or, in the case of an untrusted root, a root certificate you're supplying to us. Make sure to verify your setup again after adding the intermediate, once done, you're good to go!</p>
|
||
<h5><a class="anchor" name="testing-your-bot-with-updates" href="#testing-your-bot-with-updates"><i class="anchor-icon"></i></a>Testing your bot with updates</h5>
|
||
<ul>
|
||
<li><p>Update examples<br>A set of example updates, which comes in handy for testing your bot.</p>
|
||
<ul>
|
||
<li><p>Message with text using curl:</p>
|
||
<pre><code>curl --tlsv1.2 -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test",
|
||
"username":"Test"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test",
|
||
"username":"Test"
|
||
},
|
||
"text":"/start"
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
<p><code>--tlsv1.2</code> will force using TLS1.2.</p>
|
||
</li>
|
||
<li><p>Message with text using Postman:</p>
|
||
<div>
|
||
<a href="/file/811140789/2/DmiZPh1t6z0.269328/98525b6835f0a91432" target="_blank"><img src="/file/811140789/2/DmiZPh1t6z0.269328/98525b6835f0a91432" title="postmanfakeupdate.jpg, 263.02Kb" class="dev_page_image" /></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li><p>More examples in curl:</p>
|
||
<ul>
|
||
<li>Message with text:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"type": "private",
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"text":"/start"
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Forwarded message:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"type": "private",
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"forward_from": {
|
||
"last_name":"Forward Lastname",
|
||
"id": 222222,
|
||
"first_name":"Forward Firstname"
|
||
},
|
||
"forward_date":1441645550,
|
||
"text":"/start"
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Forwarded channel message:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"forward_from": {
|
||
"id": -10000000000,
|
||
"type": "channel",
|
||
"title": "Test channel"
|
||
},
|
||
"forward_date":1441645550,
|
||
"text":"/start"
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Message with a reply:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"text":"/start",
|
||
"reply_to_message":{
|
||
"date":1441645000,
|
||
"chat":{
|
||
"last_name":"Reply Lastname",
|
||
"type": "private",
|
||
"id":1111112,
|
||
"first_name":"Reply Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1334,
|
||
"text":"Original"
|
||
}
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Edited message:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"edited_message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"text":"Edited text",
|
||
"edit_date": 1441646600
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Message with entities:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"text":"Bold and italics",
|
||
"entities": [
|
||
{
|
||
"type": "italic",
|
||
"offset": 9,
|
||
"length": 7
|
||
},
|
||
{
|
||
"type": "bold",
|
||
"offset": 0,
|
||
"length": 4
|
||
}
|
||
]
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Message with audio:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"audio": {
|
||
"file_id": "AwADBAADbXXXXXXXXXXXGBdhD2l6_XX",
|
||
"duration": 243,
|
||
"mime_type": "audio/mpeg",
|
||
"file_size": 3897500,
|
||
"title": "Test music file"
|
||
}
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Voice message:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"voice": {
|
||
"file_id": "AwADBAADbXXXXXXXXXXXGBdhD2l6_XX",
|
||
"duration": 5,
|
||
"mime_type": "audio/ogg",
|
||
"file_size": 23000
|
||
}
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Message with a document:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"message":{
|
||
"date":1441645532,
|
||
"chat":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"message_id":1365,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"document": {
|
||
"file_id": "AwADBAADbXXXXXXXXXXXGBdhD2l6_XX",
|
||
"file_name": "Testfile.pdf",
|
||
"mime_type": "application/pdf",
|
||
"file_size": 536392
|
||
}
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Inline query:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"inline_query":{
|
||
"id": 134567890097,
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"query": "inline query",
|
||
"offset": ""
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Chosen inline query:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"chosen_inline_result":{
|
||
"result_id": "12",
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"query": "inline query",
|
||
"inline_message_id": "1234csdbsk4839"
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
</li>
|
||
<li>Callback query:<pre><code>curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
|
||
"update_id":10000,
|
||
"callback_query":{
|
||
"id": "4382bfdwdsb323b2d9",
|
||
"from":{
|
||
"last_name":"Test Lastname",
|
||
"type": "private",
|
||
"id":1111111,
|
||
"first_name":"Test Firstname",
|
||
"username":"Testusername"
|
||
},
|
||
"data": "Data from button callback",
|
||
"inline_message_id": "1234csdbsk4839"
|
||
}
|
||
}' "https://YOUR.BOT.URL:YOURPORT/"</code></pre>
|
||
That's all we have for now!</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</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>
|
||
<li><a href="//telegram.org/privacy">Privacy</a></li>
|
||
<li><a href="//telegram.org/press">Press</a></li>
|
||
</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>
|
||
<li><a href="//telegram.org/android">Android</a></li>
|
||
<li><a href="//telegram.org/dl/web">Mobile Web</a></li>
|
||
</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">
|
||
<h5><a href="//telegram.org/press">Press</a></h5>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<script src="/js/main.js?47"></script>
|
||
<script src="/js/jquery.min.js?1"></script>
|
||
<script src="/js/bootstrap.min.js?1"></script>
|
||
|
||
<script>window.initDevPageNav&&initDevPageNav();
|
||
backToTopInit("Go up");
|
||
removePreloadInit();
|
||
</script>
|
||
</body>
|
||
</html>
|
||
|