alxmsl/telegrambotclient 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

alxmsl/telegrambotclient

Composer 安装命令:

composer require alxmsl/telegrambotclient

包简介

Powerful client for Telegram Bot API

README 文档

README

License Latest Stable Version Total Downloads

Build Status Scrutinizer Code Quality Code Coverage Dependency Status

Powerful client for Telegram Bot API

Advantages

  1. Lightweight. You could use only two classes for work: API client and response
  2. Powerful. Same time you could use all 16 Bot API types and all 13 Bot API methods
  3. composer support makes installation simplified
  4. Independent namespace helps to use Bot API client on different projects and frameworks
  5. CLI utility helps you to test Bot API interactions

Installation

For simplified usage all what you need is require packet via composer

    $ composer require alxmsl/telegrambotclient

In third-party projects, require packet in your composer.json

    "alxmsl/telegrambotclient": "*"

...and update composer: composer update

Usages

First what you need is client instance. Just create it

    use alxmsl\Telegram\Bot\Client;
    $Client = new Client('123456789:Y0uR5EcREtT0KEn');

....then you could call bot methods directly and got API response string

    $result = $Client->call(<method name>, <call parameters>);
    printf("%s\n", $result);

...or use methods wrappers

    $updates = $Client->getUpdates(0, 1);
    var_dump($updates);

Method wrappers helps you to return specific result types as described in API documentation. For example, using getUpdates you be returned array of Update instances, sendMessage wrapper returns you Message object etc.

    use alxmsl\Telegram\Bot\Client;
    use alxmsl\Telegram\Bot\Type\Message;
    
    $Client  = new Client('123456789:Y0uR5EcREtT0KEn');
    $Message = $Client->sendMessage(34567, 'hello');
    ($Message instanceof Message); // that's TRUE 

When something wrong, wrapper throws UnsuccessfulException. For example code

    $Client = new Client('123456789:Br0KEnT0kEN');
    try {
        $Message = $Client->getMe();
    } catch (UnsuccessfulException $Ex) {
        printf("%s\n%s", $Ex->getCode(), $Ex->getMessage());
    }

is showed you

401
Error: Unauthorized

Console usage

You could use script call.php to call Telegram Bot API directly

    $ php bin/call.php -h
    Using: /usr/local/bin/php bin/call.php [-h|--help] -m|--method [-p|--parameters] -t|--token
    -h, --help  - show help
    -m, --method  - bot method name
    -p, --parameters  - method calls parameters
    -t, --token  - authentication token

Using utility you could test your bot's authentication token

    $ php bin/call.php -t='123456789:Y0uR5EcREtT0KEn' -m='getMe' 
    {"ok":true,"result":{"id":123456789,"first_name":"alxmslClientBot","username":"alxmslClientBot"}}

When something wrong^ utility will show you error response from Bot API

    $ php bin/call.php -t='123456789:Br0KEnT0kEN' -m='getMe' 
    {"ok":false,"error_code":401,"description":"Error: Unauthorized"}

... got updates etc.

    $ php bin/call.php -t='123456789:Y0uR5EcREtT0KEn' -m='getUpdates' -p='{"limit":1}' 
    {"ok":true,"result":[{"update_id":7654321,"message":{"message_id":2,"from":{"id":34567,"first_name":"Alexey","last_name":"Maslov"},"chat":{"id":34567,"first_name":"Alexey","last_name":"Maslov"},"date":1435870467,"text":"\/start"}}]}

Tests

For completely tests running just call phpunit command

    $ phpunit
    PHPUnit 4.7.5 by Sebastian Bergmann and contributors.
    
    Runtime:	PHP 5.5.23
    
    ................
    
    Time: 190 ms, Memory: 9.00Mb
    
    OK (16 tests, 784 assertions)

License

Copyright 2015 Alexey Maslov alexey.y.maslov@gmail.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

alxmsl/telegrambotclient 适用场景与选型建议

alxmsl/telegrambotclient 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 78 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「bot」 「telegram」 「bot api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alxmsl/telegrambotclient 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alxmsl/telegrambotclient 我们能提供哪些服务?
定制开发 / 二次开发

基于 alxmsl/telegrambotclient 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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