alisoftware/phptgbot

PHP Telegram Bot

Installs: 12

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/alisoftware/phptgbot

0.1.5 2017-05-01 09:19 UTC

This package is not auto-updated.

Last update: 2025-10-26 07:26:03 UTC


README

PHP Telegram Bot

Installation

Using Composer

composer.json :

{
    "require": {
        "alisoftware/phptgbot": "*"
    }
}

index.php:

<?php
   require __DIR__ .'/vendor/autoload.php' ;
   use \Alisoftware\Phptgbot as Bot;
   
   Bot::setToken(''); 
   Bot::getMe();

Longpooling / Webhook

Example:

<?php
   require __DIR__ .'/vendor/autoload.php' ;
   use \Alisoftware\Phptgbot as Bot;
   
   Bot::setToken(''); 
   
   // webhook
   // Bot::setToken('TOKEN',true); 
   
   Bot::run(function($response){
      if ($response['error'] == false) 
      {
        $message = isset($response['message'])?$response['message']:false;
        $onChannel = isset($response['channel_post'])?$response['channel_post']:false;
        if ($message != false) onMessage($message);
        //if ($onChannel != false) onMessage($onChannel);
      }   
   });
   
   function onMessage($message){
     print_r($message);
     if ($message['text'] == 'ping') {
            Bot::send('message','<b>PONG!</b>');
        }
   }