use App\Http\Controllers\BotManController;
use BotMan\BotMan\Messages\Conversations\Conversation;
$botman = resolve('botman');
$botman->hears('Начать', function($bot) {
$bot->startConversation(new OnboardingConversation);
}); //this works
$botman->fallback(function($bot) {
$bot->startConversation(new OnboardingConversation);
}); //this worksuse App\Http\Controllers\BotManController;
use BotMan\BotMan\Messages\Conversations\Conversation;
$botman = resolve('botman');
$botman->group(['driver' => [VkCommunityCallbackDriver::class]], function($botman) {
$botman->hears('Начать', function($bot) {
$bot->startConversation(new OnboardingConversation);
}); //this NOT works
$botman->fallback(function($bot) {
$bot->startConversation(new OnboardingConversation);
}); //this works
});我所想做的--例如VK和Telegram的通用机器人,但我需要检查目标平台黑名单中的用户是否有,所以如果“驱动程序”类似于botman的"MatchingMiddleware“,我不明白为什么听到在"Group”内部不起作用,这是网站上的官方例子:官方botman视频教程截图。
此示例也不起作用:https://botman.io/2.0/receiving#command-groups-drivers
在VK驱动程序网站上没有关于"Group":https://github.com/yageorgiy/botman-vk-community-callback-driver的信息
发布于 2021-08-26 18:47:48
UPDATE:我检查了Marcel视频和他的工作流程,在Botman视频中有很多次他在崇高文本编辑器中使用了一些神奇的键,所以我搜索它,它是PHP,所以我通过Tools->Command Pallete安装了崇高文本和PHP,然后单击了VkCommunityCallbackDriver,然后单击了Tools->Command和命令PHP :Find,下面的代码出现了:
use BotMan\Drivers\VK\VkCommunityCallbackDriver;
use BotMan\Drivers\Telegram\TelegramDriver;魔术起作用了,现在驱动程序的组方法起作用了,我仍然不明白为什么文档或视频课程中没有显示这一点,好像组方法不是主要的方法一样。
我仍然不明白为什么它不是从“盒子”,因为我总是认为编码器使用这种复杂的解决方案,以方便生活。但是在2天的空搜索之后,我感到很累,所以我根据Botman https://beyondco.de/course/build-a-chatbot/middleware-system/matching-middleware的官方视频教程编写了定制的中间件来“只听到”VK驱动程序。
App\Middleware\VkMatchingMiddleware.php
<?php
namespace App\Middleware;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Interfaces\Middleware\Matching;
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
class VkMatchingMiddleware implements Matching
{
/**
* Handle a captured message.
*
* @param IncomingMessage $message
* @param callable $next
* @param BotMan $bot
*
* @return mixed
*/
public function matching(IncomingMessage $message, $pattern, $regexMatched)
{
return $regexMatched && isset($message->getExtras()["client_info"]);
}
}Routes\botman.php
<?php
use App\Http\Controllers\BotManController;
use BotMan\BotMan\Messages\Conversations\Conversation;
use App\Middleware\VkMatchingMiddleware;
$VkMatchingMiddleware = new VkMatchingMiddleware();
$botman = resolve('botman');
$botman->hears('Begin', function($bot) {
$extras = $bot->getMessage()->getExtras();
$bot->reply(print_r($extras, 1));
})->middleware($VkMatchingMiddleware);
$botman->fallback(function($bot) {
$bot->reply('fallback');
});如果有人知道为什么它是这样工作,但不是从香草,我会很高兴看到解释。
https://stackoverflow.com/questions/68939203
复制相似问题