Skip to content

naziks/telegran

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegran

Modern Telegram bot template. Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots by sending them command messages in private or group chats. These accounts serve as an interface for code running somewhere on your server.

Table of Content

  1. Pre-Requirements
  2. Quich Start
  3. Variables
  4. Telegram Class Methods
  5. Template structure

Pre-Requirements

  1. PHP Hosting
  2. SSL Certificate (If you don't have it, you can use Cloudflare)
  3. CURL IS NOT REQUIRED

Quick Start

  1. Clone template to your website
  2. Create bot via BotFather
  3. Open var.php and edit this:
define("TOKEN", "BOT_TOKEN");        // (REQUIRED) BOT_TOKEN
define('ADMIN_ID', 'YOUR_ID');       // (OPTIONAL) YOUR ID

$_FEATURES = Array(
	"debug"      => false,       // (OPTIONAL) YOUR_ID OR FALSE
	"db_enabled" => false        // (OPTIONAL) TRUE OR FALSE
);

$_DATABASE_CONFIG = Array(
	"host" => "localhost",       // DATABASE HOST
	"username" => "username",    // DATABASE USER
	"password" => "password",    // DATABASE USER PASSWORD
	"database_name" => "db_name" // DATABASE NAME
);
  1. Set Webhook
  2. The End!

Variables

Location Variable Description
GLOBAL $tg Telegram Object
GLOBAL $db Database Object
GLOBAL $_DATA Webhook Income Data
~GLOBAL $_M Message Object
SIMPLE_MESSAGE $_T Message Text exploded by space
~GLOBAL $_CID Telegram Message Chat Id
INLINE_BUTTON $_QID Callback Query ID
INLINE_BUTTON $_QDATA Callback Query DATA exploded by ";"

Telegram Class Methods

Using:

$tg->METHOD_NAME($PARAM_1, $PARAM_2, ..., $PARAM_N)
Name PARAMS Return
sendRequest (String) Method, (Array) Params Array Telegram API Response
buildInlineButton Inline Button Array
buildReplyButton Reply Button Array
buildInlineKeyboard (Array) of InlineButtons String JSON
buildReplyKeyboard (Array) of ReplyButtons, Array of params String JSON
buildForceReply (Array) of params String JSON
removeReplyKeyboard (Array) of params String JSON
buildInlineLine (Array) of params Array
buildInlineQueryResult (Array) of params String JSON

Template structure

ROOT:
├── classes  
│   ├── tg.class.php // Telegram API class
│   └── db.class.php // Database class
├── query_type 
│   ├── inline_button.php  // Message type inline button
│   ├── inline_message.php // Message type inline query  
│   └── simple_message.php // Message type simple message  
├── lang.php // language file
├── bot.php  // Main file, requested by WebHook
├── var.php  // Main variables of bot
└── lang.php // language file