quiec/boting 问题修复 & 功能扩展

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

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

quiec/boting

Composer 安装命令:

composer require quiec/boting

包简介

Simple but powerful and Async(multi-thread) Telegram Bot library

README 文档

README

Simple yet Powerful.

🇹🇷 Türkçe | 🇬🇧 English

Boting, The best Telegram Bot library for fast and asynchronous bot with PHP.

Features

  • %100 Async (😳)
  • Always compatible with the latest BotAPI
  • Single file, small size, simple to upload.
  • File download/upload
  • Events
  • WebHook & GetUpdates support

Requirements

If you can install Guzzle, you can use it easily.

Install

If you have Composer, you can install it very easily:

composer require quiec/boting

If you want to use the beta version:

composer require quiec/boting:dev-master

If Composer is not installed, you can easily install it Here.

Get Update

You can get Update with two ways;

Webhook

If you are going to receive Updates with Webhook method, just add "true" to the handler.

...
$Bot->Handler("Token", true);

Get Updates

This method is used by default. You don't need to add anything extra.

...
$Bot->Handler("Token");

Events

With the new feature added to Boting 2.0, you can now add convenience commands and capture message types with on.

$bot->command

The command, must be regex.

Example (Let's catch /start command):

$Bot->command("/\/start/m", function ($Update, $Match) use ($Bot) {
    $ChatId = $Update["message"]["chat"]["id"]; 
    $Bot->sendMessage(["chat_id" => $ChatId, "text" => "Started bot."]);
});

Let's add another command handler:

$Bot->command("/[!.\/]start/m", function ($Update, $Match) use ($Bot) {
    $ChatId = $Update["message"]["chat"]["id"]; 
    $Bot->sendMessage(["chat_id" => $ChatId, "text" => "Started bot."]);
});

The bot will now also respond to /start,!Start,.start commands.

$bot->on

The bot will execute the function if a message of the specified type arrives.

No match is used, On.

Example (If the photo comes):

$Bot->on("photo", function ($Update) use ($Bot) {
    $ChatId = $Update["message"]["chat"]["id"]; 
    $Bot->sendMessage(["chat_id" => $ChatId, "text" => "Photo came"]);
});

You can look at the On Types here.

$bot->answer

You can use the answer function to answer inline_query or callback_query.

Example (Let's answer inline):

$Bot->answer("inline_query", function ($Update) use ($Bot) {
    $Bir = ["type" => "article", "id" => 0, "title" => "test", "input_message_content" => ["message_text" => "This bot created by Boting..."]];
    $Bot->answerInlineQuery(["inline_query_id" => $Update["inline_query"]["id"], "results" => json_encode([$Bir])]);    
});

Special Events

If you do not want to use ready-made functions, you can define your own function.

❗️Type true if you are going to use Webhook or false if you will get it with GetUpdates.

$Main = function ($Update) {...};
$Bot->Handler("Token", false, $Main);

Example (A function that responds to the /start message):

<?php
require __DIR__ . '/vendor/autoload.php'; //We include the base of the bot.
use Boting\Boting; // We say we want to use the base.

$Bot = new Boting(); // We start the base.
$Main = function ($Update) use ($Bot) { // We create a function called Main.
    if (!empty($Update["message"])) { // We check if a message has arrived.
        $Mesaj = $Update["message"]["text"]; // We throw the message into the variable.
        $ChatId = $Update["message"]["chat"]["id"]; // We get the chat id to send messages.

        if ($Mesaj === "/start") { // We check if the message is start.
            $Bot->sendMessage(["chat_id" => $ChatId, "text" => "You started the bot."]); // We use the sendMessage function.
        }
    }
};
$Bot->Handler("Here ur bot token", false, $Main); // We define our bot token and function.

Commands

Commands are the same as BotAPI commands. You can use BotAPI commands in the same way.

Let's give an example you wanted to send a message,We look at the required parameters from BotAPI.

We need chat_id and text. So let's write our code.

$Bot->sendMessage(["chat_id" => "@fusuf", "text" => "Hello!"]);

The process is complete. Commands return Array, after operation.

Examples

We can show this file as a very good example of using the library. Also a code that responds to a simple /start message:

<?php
require __DIR__ . '/vendor/autoload.php'; //We include the base of the bot.
use Boting\Boting; // We say we want to use the base.

$Bot = new Boting(); // We start the base.
$Bot->command("/[!.\/]start/m", function ($Update, $Match) use ($Bot) {
    $ChatId = $Update["message"]["chat"]["id"]; 
    $Bot->sendMessage(["chat_id" => $ChatId, "text" => "Started bot."]);
});
$Bot->Handler("Here ur bot token"); // We define our bot token.

Licence

This project is completely open source and protected under MIT license. Please refer to the LICENSE.md file

Contact

You can contact me on Telegram or open Issue.

quiec/boting 适用场景与选型建议

quiec/boting 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.37k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2020 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 4
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-05