radyakaze / telebot
0.1
2015-08-17 05:30 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2022-02-01 12:50:20 UTC
README
此包已过时,请使用 PHPTelebot 代替。它更新且更好。
TeleBot - PHP Telegram Bot
基于官方 Telegram Bot API 的简单 Telegram Bot
要求
- PHP 5.3+
- Telegram Bot API 访问令牌 - 与 @BotFather 联系并生成一个。 文档。
安装
通过 Composer 安装
您可以直接通过运行此命令添加包
$ composer require radyakaze/telebot
用法
您必须设置 WebHook
创建 set.php 并放置
<?php $token = 'BOT TOKEN'; $botname = 'BOT USERNAME'; require __DIR__.'/vendor/autoload.php'; $tg = new TeleBot\Api($token, $botname); $tg->setWebhook('https://domain/path_to_hook.php');
然后通过浏览器打开 set.php
创建 hook.php 并放置
<?php $token = 'BOT TOKEN'; $botname = 'BOT USERNAME'; require __DIR__.'/vendor/autoload.php'; $tg = new TeleBot\Api($token, $botname); // Simple command : /hello => Hello world! $tg->cmd('hello', 'Hello world!'); // Simple command with parameter : /echo telebot => telebot $tg->cmd('echo', function($text){ if (isset($text)) { return $text; } else { return '/echo <text>'; } }); $tg->run();
发送照片
$tg->cmd('upload', array( 'type' => 'photo', 'send' => 'path/to/photo.jpg' ); // OR $tg->cmd('upload2', function($text) { return array( 'type' => 'photo', 'send' => 'path/to/photo.jpg' ) });
发送位置
<?php $tg->cmd('myloc', function($text) { return array( 'type' => 'location', 'send' => array(-7.61, 109.51) // Gombong, Kebumen, Indonesia, you can integrate with google maps api ) });
可用类型
- text, optional: web_preview (default: true)
- photo, optional: caption
- video, optional: caption
- document
- audio
- location, required: send as array($latitude, $longitude)
许可
TeleBot 在 MIT 许可下
致谢
由 Radya 创建。