Telegram
Telegram API made for php (Simple usage)
How to use?
- Download the project & place
Telegram
folder tp your project directory (For example i set mywebhook inhttps://Urmom.com/MyBot/Main.php
and i should placeTelegram
folder intoMyBot
directory!) - Now we need something like ths in our
Main.php
:
/* Important for define variable $bot */
use Telegram\Bot;
/* Important to require all classes */
spl_autoload_register(function ($class){require_once __DIR__ . '/' . str_replace('\\', '/', $class) . '.php';});
/* Definition of our bot class! REPLACE TOKEN WITH YOUR BOT TOKEN! */
$bot = new Bot("TOKEN");
- Now we need to check what message is ? I mean is message that sent by user a media or a text ? to do this we should use something like :
/**
* With this method you can check if message sent by user is instance of Text
* You can also try others like :
* issetMedia() : To check if message is instance of Document/Audio/Photo/Video/Sticker/Gif
* Or you can try them one by one : issetMessage() or issetDocument or issetAudio or issetVideo or issetPhoto
*/
if ($bot->issetMessage()) {
/* Here is the message that user sent */
$text = $bot->message()->text();
/* If message is /start */
if ($text === '/start') {
/* Sending a message with some text formats */
$bot->message()->send("```Hello```\n, _welcome to_ *UR BOT*!"/* I think now you now how to use text formats in telegram */);
/**
* Another message with another text formats
* null value in below input is for chat_id, sometimes you want to send a message to another chats (Like your group/Channel/OtherBotUsers)!
* true value in below input is for replying bot to the message that user sent (Default is false!)
* false value in below input is for replying user to the message that bot sent (Force_reply, Default is false)
*/
$bot->message()->send("Hope [you](tg://settings) *like* it!", null, true, false);
}
}
- SetWebhook and make sure your host have activated ssl, Specially thanks for those who report bugs & problems in issues ;)