yooznet/chatgenius

一个用于与Telegram API交互的PHP库。

1.0.0 2024-09-03 08:57 UTC

This package is not auto-updated.

Last update: 2024-10-02 07:43:13 UTC


README

ChatGenius是一个用于与Telegram API交互的PHP包。本README提供了安装、配置和使用此包来发送消息、回复用户和创建自定义键盘的说明。

安装

要安装此包,请使用Composer

composer require yooznet/chatgenius:^1.0.0

设置

首先,在您的项目中包含必要的类

use ChatGenius\TelegramAction;
use App\Classes\user\Handler;

使用您的机器人令牌创建一个新的TelegramAction实例

$telegram = new TelegramAction('Your_Token_Here');
$update = new HandleUpdate();

发送消息

要发送消息,请使用以下代码

$telegram->ChatID($update->chat_id)
         ->Text('Welcome to our world!')
         ->sendMessage();

回复用户消息

要回复用户的消息,首先检查是否存在message_id,然后使用Reply类

use ChatGenius\Reply;

$reply = $update->message_id ? new Reply(message_id: $update->message_id) : null;

$telegram->ChatID($update->chat_id)
         ->Reply($reply)
         ->Text('Welcome to our world!')
         ->sendMessage();

创建按钮

内嵌键盘

要创建带有按钮的内嵌键盘

use ChatGenius\Keyboard;

$keyboard = new Keyboard(
    type: 'InlineKeyboardMarkup',
    inlineKeyboard: [
        [
            ['text' => 'test', 'callback_data' => 'test'],
            ['text' => 'test2', 'callback_data' => 'test2'],
        ],
    ]
);

回复键盘

要创建常规回复键盘

$keyboard = new Keyboard(
    type: 'ReplyKeyboardMarkup',
    keyboard: [
        ['test']
    ],
    resizeKeyboard: true,
    oneTimeKeyboard: true
);

移除键盘

要移除键盘

$keyboard = new Keyboard(
    type: 'ReplyKeyboardRemove',
    removeKeyboard: true
);

带有键盘发送消息

要发送带有自定义键盘的消息

$telegram->ChatID($update->chat_id)
         ->Text('Welcome to our world!')
         ->ReplyMarkup($keyboard)
         ->sendMessage();

贡献您可以提交问题或拉取请求来为此项目做出贡献。

许可协议本项目受MIT许可协议许可。有关详细信息,请参阅LICENSE文件。

联系方式如有任何疑问或反馈,请联系mail@yooznet.online