承接 tigris/telegram-bot-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tigris/telegram-bot-api

Composer 安装命令:

composer require tigris/telegram-bot-api

包简介

Lightweight PHP7 client for a Telegram Bot API

README 文档

README

Build Status Join the chat at https://gitter.im/tigris-php/tigris GitHub license

Lightweight PHP7 client for a Telegram Bot API

Overview

Current API version: 3.2

Requirements:

  • PHP 7
  • Guzzle 6

Installation

Composer

The preferred way to install this extension is through Composer.

Either run

php composer.phar require tigris/telegram-bot-api

or add

"tigris/telegram-bot-api": "*"

to the require section of your composer.json

Usage

Getting started

First you need to create api client instance

$httpClient = new \GuzzleHttp\Client();
$apiClient = new \Tigris\Telegram\ApiClient($httpClient);
$apiClient->setApiToken('CHANGEME');

Create api wrapper instance

$apiWrapper = new \Tigris\Telegram\ApiWrapper($apiClient);

Use api wrapper methods mapped directly to the Telegram Bot API

$apiWrapper->sendChatAction([
    'chat_id' => 123,
    'action' => \Tigris\Telegram\Helpers\ChatAction::TYPING,
]);
$apiWrapper->sendMessage([
    'chat_id' => 123
    'text' => 'Hello, World!',
    'parse_mode' => \Tigris\Telegram\Helpers\ParseMode::HTML,
]);                        

Type mapping

Please note that every method call response call is being parsed into the corresponding type. We offer PHP classes for all of the API objects. For example, sendMessage() call would return an instance of \Tigris\Telegram\Types\Message objects. Objects, arrays, nested arrays, scalar values are fully supported by the type parser.

Getting updates

// Get array of the \Tigris\Telegram\Types\Updates\Update
$updates = $apiWrapper->getUpdates([
    'offset' => $this->offset,
]);

// Process received updates
foreach ($updates as $update) {
    $this->offset = $update->update_id + 1;
    $this->setLastOffset($this->offset);
    $this->processUpdate($update);
}                     

Handling errors

By default every mapped method returns null value if an error occurs. You can change this behavior by adding callable error handler to your ApiWrapper instance.

$apiWrapper->setErrorHandler(function (\Exception $e) use ($logger) {
    $logger->log($e);         
});

Going further

Please feel free to investigate the source code. All the api methods and types are fully documented. Please contact us in the gitter chat channel: https://gitter.im/tigris-php/tigris

License

MIT

统计信息

  • 总下载量: 1.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固