kukymbr/telegramer

用于操作Telegram机器人API方法的实用工具

v0.1.2 2019-11-20 09:15 UTC

This package is not auto-updated.

Last update: 2024-09-19 08:35:57 UTC


README

用于从php访问Telegram机器人API的包

要求

Telegramer需要PHP 7.0及以上版本。

安装

安装Telegramer的推荐方式是通过Composer。

$ composer require kukymbr/telegramer

使用方法

<?php

use \Kukymbr\Telegramer\Connection;
use \Kukymbr\Telegramer\Bot;
use \Kukymbr\Telegramer\Response;
use \Kukymbr\Telegramer\Notifier;

$connection = new Connection();
// You can set your cURL options here.
// For example, proxy settings.
$connection->setOptArray([]);

$bot = new Bot('12345:YourBotToken', $connection);

// Send a request to API method via magic
$me = $bot->getMe();

/**
 * @var Response $me
 */
if ($me->isOk()) {
    // Do something with the result 
    var_dump($me->result());
}

$notifier = new Notifier($bot);
$notifier->addChat(123456);

$notifier->send('Some message from the site');
$notifier->sendMap(
    [
        'New request #123',
        'name' => 'John',
        'phone' => '+123456789'
    ],
    [
        'name' => 'User name',
        'phone' => 'User phone'    
    ]
);

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。