首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Botman与VK社区回调驱动程序在组内听到不工作

Botman与VK社区回调驱动程序在组内听到不工作
EN

Stack Overflow用户
提问于 2021-08-26 13:13:25
回答 1查看 136关注 0票数 0
  1. hearsfallback都很好:
代码语言:javascript
复制
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 works
  1. 在带有VK驱动程序的组内,侦听无效,但回退工作:
代码语言:javascript
复制
use 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的信息

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-26 18:47:48

UPDATE:我检查了Marcel视频和他的工作流程,在Botman视频中有很多次他在崇高文本编辑器中使用了一些神奇的键,所以我搜索它,它是PHP,所以我通过Tools->Command Pallete安装了崇高文本和PHP,然后单击了VkCommunityCallbackDriver,然后单击了Tools->Command和命令PHP :Find,下面的代码出现了:

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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');
});

如果有人知道为什么它是这样工作,但不是从香草,我会很高兴看到解释。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68939203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档