alisoftware / phptgbot

PHP Telegram Bot

0.1.5 2017-05-01 09:19 UTC

This package is not auto-updated.

Last update: 2024-09-29 02:34:07 UTC


README

PHP Telegram Bot

安装

使用Composer

composer.json :

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

index.php:

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

长轮询 / Webhook

示例

<?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>');
        }
   }