Course Content
Introduction to CodeIgniter
CodeIgniter is a powerful PHP framework built for developers who need a simple and elegant toolkit to create full-featured web applications.
MVC (Model-View-Controller)
MVC stands for Model-View-Controller. MVC is an application design model consisting of three interconnected parts. They include the model (data), the view (user interface), and the controller (processes that handle input).
The Session class allows you to maintain a user’s "state" and track their activity while they browse your site.
URI Routing
There is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:
Forms and Input
Forms provide a way for users to interact with the application and submit data.
Composer is dependency manager in PHP. it allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
You can enable CSRF protection by modifying your application/config/config.php file
Working with Database
Like any other framework, we need to interact with the database very often and CodeIgniter makes this job easy for us. It provides a rich set of functionalities to interact with the database.
DataTables is a table enhancing plug-in for the jQuery Javascript library that helps in adding sorting, paging, and filtering abilities to plain HTML tables with minimal effort. The main goal is to enhance the accessibility of data in normal HTML tables.
PhpSpreadsheet is a PHP library for reading and writing spreadsheet files. Importing Excel and CSV into MySQL help to save the user time and avoid repetitive work.
Payment Gateway
Razorpay and PayTM Payment Gateway
WhatsApp Chatbot and Telegram Chatbot
CodeIgniter 3
About Lesson

Telegram is a popular cloud-based messaging Russian app. This app is available for Android, iOS, and Windows. Using this app users can send messages, audio, videos, and files. Telegram app stored data on the cloud server and Bot is the outstanding feature of it. More important Telegram app has a feature for optional end-to-end encrypted secret chats.

How a Telegram Bot Works

Telegram Bot is an automated software application that does some tasks repeatedly. This application runs inside the telegram, Using bot API you can manage HTTP requests. You can integrate telegram with another third-party web service, send messages, accept payment.

Create a Telegram Bot Step by Step

Open your Telegram app and search for botfather, it’s a bot itself. It will let you create a telegram bot. Click on the Start option.

Telegram Bot

You can see multiple options on-screen like /newbot, /mybots, /token, /revoke etc.

Click or Type /newbot command on it and it asks for choose a bot name. Enter any relevant bot name, don’t use space in bot name.

Now you will receive a message that the bot is created successfully and the HTTP API token shows. This token is used to authorize the telegram bot API calls. Keep note it down for future use.

Telegram Bot

Test Telegram API Call

To check the API response, let execute a sample API call using the ‘getMe’ method. Just enter below Web URL in the browser. Must enter your bot token in that URL. This will show your bot account a detailed response.{token}/getMe

Get Messages sent to your Telegram Bot

There are two API methods to get an update from your bot.

  • getUpdates
  • setWebhook

getUpdates Telegram API Method

This method is used to receive incoming messages from users. It receives messages in JSON format.


class Chatbot extends CI_Controller {
	public function __construct() {

	public function get_update() {
		$link   = ''.$token.'';
		$update = file_get_contents($link.'/getUpdates');
		$response = json_decode($update, TRUE);
	    $chat_id = $response['result'][0]['message']['chat']['id'];
	    $message = 'Hello There';
	    $parameters = [
	    	'chat_id' => $chat_id, 
	    	'text'  => $message,
	    $url = $link.'/sendMessage?'.http_build_query($parameters); 

Whenever you execute the above code, it will post a “Hello There” message on your bot. To send a message to the user you have to run this code repeatedly, this is the manual process.

To get this task automate you can use the second-way setWebhook.

setWebhook Telegram API Method

In this method telegram automatically execute the server script. Every time the bot gets a new notification, it sends a webhook response on your set webhook URL. This is the most convenient way to create your Telegram bot.

To automate the chatbot, First set the webhook URL via the setWebhook API method. Use the below web URL to do that, must pass a valid secure web page link in the URL parameter.{token}/setWebhook?

After executing this link in the web browser, you will get a successful response.

{"ok":true,"result":true,"description":"Webhook is already set"}

To receive the telegram bot response you need to get a webhook response in your web server Chatbot.php controller file. Check the below code example.


class Chatbot extends CI_Controller {
	public function __construct() {

	public function callback() {
	    $link   = ''.$token.'';
          $getupdate = file_get_contents('php://input'); // for webhook
        $update         = json_decode($getupdate, TRUE);
        $chatid         = $update['message']['chat']['id'];
        $req_message    = $update["message"]["text"];   // message from user
	    $chat_id = $response['result'][0]['message']['chat']['id'];
	    $res_message = 'Chatbot message';

	    $parameter = [
	        'chat_id'   => $chatid, 
		    'text'      => $res_message

        $request_url = $link.'/sendMessage?'.http_build_query($parameter); 


Whenever anyone writes a message on your bot then this webhook posts “Chatbot message” on your bot as a reply. This is an automated process, doesn’t need any manual action.

Using a Telegram bot API, we have successfully created a chatbot.

To see the complete Bot API description, check this page: