Hi Geeks! Before we start to create Fully Responsive Telegram Bot, we must ensure the following resources.
- A Webserver with PHP and MySQL.
- Program O – PHP I AIML Chatbot.
- SSL Certificate (HTTPS) to your web server (Don’t worry about it, I’ll explain how to setup free SSL to your site)
Step 1: Set up Your Telegram Bot
Chat with Botfather to create your bot
On Telegram search @BotFather or you can start conversation by navigating through following link t.me/botfather
Start conversation with the botfather by typing /start the botfather replies you with set of commands that you can use with your bot.
Choose a username to your bot
Now type /newbot. The bot father will ask you to choose a name for your bot. Enter the desired name you want, for example I have named as Chitti.
On next step the bot father will ask you to choose a username for your bot, the bot name must end with
botfor example I gave Chitti2Bot.
When you’re done the botfather will leave you a congratulation message with access token which is the secret key of your bot and do not share with anyone. Finally you can set description and profile picture for your bot if you need. Type /help for the commands. Now your telegram bot is ready but it won’t respond now proceed to next step.
Step 2: Install Program O
The second step is to install Program O Chatbot. Program O is an Artificial Intelligence Chat bot written in PHP with MySQL. It has in-built Chatbot API. Therefore it is helpful to integrate with our Bot. Read our full guide How to Install Program O – PHP | AIML Chatbot.
Step 3: Add Free SSL to your site
SSL is Secured Socket Layer (Adds https to our site) helps to transfer encrypted data between server and client. It is important that your url must start with HTTPS to work with telegram bot webhooks. Therefore you need valid SSL Certificate. Don’t worry about that, read our guide How to Setup Free SSL Cloudflare For Your Website.
Step 4: Setting Up Webhook with PHP
PHP Webhook Script
Now we need to setup php script that integrates with Program O and Telegram bot webhook. The following gist will do the work you need to replace with
- ‘BOT TOKEN‘ with Telegram Bot token sent by bot father.
- bot_id with your Program O bot id and
- siteurl with the url where you’ve installed Program O.
Note: Make sure that you’ve uploaded AIML files in Program O to put your bot to work.
Upload Script to Server
Now upload the script to the server, it is recomended to choose a secret url location to place your script. For example:1https://example.com/kjnhsdfs54sdfs54sdfsf5sfd64haddsf/telebot.php
Binding Script URL with Telegram
Open your favourite text editor and write down the following URL with your own info.1https://api.telegram.org/bot[BOT_TOKEN]/setwebhook?url=[WEB_LOCATION_OF_THE_SCRIPT]
Now open up browser and paste the url link and hit enter. When everything goes right you will receive a confirmation message that “Webhook was set”.
Step 5: Test Your Fully Responsive Telegram Bot
Finally its time to test your Fully Responsive Telegram Bot, Open your Telegram App and send message to your bot. The bot will respond as follow
You can even add your bot to the telegram group. To make it work in the group you should send message with prefix
Test our demo telegram bot @Chitti2Bot
If the bot doesn’t work, double check you’ve followed all the step or feel free to ask in the comment box below.