mboretto / messenger-bot
PHP 消息机器人
0.1.1
2017-01-17 22:02 UTC
Requires
- php: >=5.5.0
- ext-curl: *
- guzzlehttp/guzzle: ~6.0
- illuminate/support: ~5.0
- monolog/monolog: ^1.19
- symfony/http-foundation: >=3.0 <3.2
Requires (Dev)
- phpunit/phpunit: ~4.8
- squizlabs/php_codesniffer: ~2.5
This package is not auto-updated.
Last update: 2024-09-29 02:08:47 UTC
README
Php 封装了 Facebook Messenger 平台。受到 irazasyed/telegram-bot-sdk 和 akalongman/php-telegram-bot 的启发;
安装
-
库安装
composer require mboretto/messenger-bot
-
编辑 [hook.php]((https://github.com/mbroretto/messenger-bot/examples/hook.example.php) 文件,用您的 Facebook 凭据。
-
将 webhook 指向您的 https 域名。
功能
- 通用模板、按钮模板、线程设置、按钮、快速回复、获取用户信息和命令...
- 如果字符超过限制,则自动分割消息
中间件
有时您需要为每个传入的消息对象执行一些例程。为了做到这一点,您可以利用中间件层。中间件实例需要实现 Middleware\Layer 类。中间件可以在核心功能之前或之后
<?php
namespace MBoretto\MessengerBot\Middleware;
use \Closure;
use \MBoretto\MessengerBot\Objects\Messaging;
class BeforeGetUser extends Layer
{
public function handle(Messaging $messaging, Closure $next)
{
//My routine
return $next($messaging);
}
}
。
<?php
namespace MBoretto\MessengerBot\Middleware;
use \Closure;
use \MBoretto\MessengerBot\Objects\Messaging;
class BeforeGetUser extends Layer
{
public function handle(Messaging $messaging, Closure $next)
{
$messaging = $next($messaging);
//My routine
return $messaging;
}
}
然后按照示例中的说明,将中间件添加到您的 hook 文件中。
中间件灵感来自 Lumen/Laravel 管道。
命令
命令需要在 hook.php 中注册,并且必须是 Commmand.php 的实例。
- 当接收到 Postback 更新时,CommandBus 会检查 payload 是否与 postback 命令的名称匹配。如果发生这种情况,则执行该命令,否则由 GenericPostbackCommand.php 处理。
- 简单文本消息由 GenericMessageCommand.php 处理
- 初始化命令在设置 webhook 时每次执行
附加信息
如有任何问题、反馈、建议或疑问,请使用问题跟踪器 此处。