Create a bot with CloudFlare

If you want to use a normal hosting, the only usable way is to use a WebHook. The WebHook will call your script when your Bot has a new message. Each message sent to a private chat activates the WebHook, but only those that start with the '/' character (the commands) in groups.

The problem is that (at the time) Telegram requires a SSL certificate that can not be self-signed.

Do not despair though, thanks to CloudFlare you can work around this limitation.

You need:

  • A domain name
  • Change your domain name servers

First, create a CloudFlare account (it's free). Click Add site and enter your domain name. Wait until you'll get the new nameservers. Replace them with the default ones for your domain. Now in your cloudflare account click Crypto and and set SSL to Flexible. From now on the connection between Telegram and Cloudflare will be over HTTPS with a valid certificate and the WebHook will work.

Wait a little bit and set the WebHook typing on your browser*BOT_ID*/setWebhook?url=https://*domain*/*script_name*.php

Now try to write a message to your bot, it should work.

This article is my 3rd oldest. It is 184 words long, and it’s got 5 comments for now.