定制 paranoiasystem/telegrambot-php-library 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

paranoiasystem/telegrambot-php-library

最新稳定版本:1.0.3

Composer 安装命令:

composer require paranoiasystem/telegrambot-php-library

包简介

TelegramBot PHP unofficial library.

README 文档

README

Travis Packagist Total Downloads GitHub license

TelegramBot is an unofficial library in PHP for use the Telegram APIs for bot

Install

Via Composer

$ composer require paranoiasystem/telegrambot-php-library

Usage

Send Message

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

	$bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

	$bot->sendMessage('chat_id', 'text');

Send Photo

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

	$bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

	$bot->sendPhoto('chat_id', 'path_to_photo');

	//or

	$bot->sendPhoto('chat_id', array('file_id'  => 'file_id_value'));

Bot Example

Set WebHook

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

    $bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

    $response = $bot->setWebhook("https://url.to/hook.php"); //only https

	if($response->description == "Webhook was set")
		echo "Ok! The bot is ready!";
	else{
		echo "Ops! Error <br>";
		print_r($response);
	}
?>

BotCore (hook.php)

<?php
	namespace Telegram;

    require_once __DIR__ . '/vendor/autoload.php'; 

    $bot = new TelegramBot('YOUR_BOT_API_TOKEN', 'YOUR_BOT_USERNAME');

    $response = $bot->hook();

	$comand = $response->message->text;

	if(substr($comand, 0, strlen("/echo")) === "/echo")
		$bot->sendMessage($response->message->chat->id, str_replace("/echo", "", $comand));

	if(substr($comand, 0, strlen("/img")) === "/img")
		$bot->sendPhoto($response->message->chat->id, 'path_to_photo');
?>

统计信息

  • 总下载量: 68
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2015-07-25