我一直在尝试与 botman 发送电子邮件。以防 botman 无法回答用户。将向管理员发送一封电子邮件,以便他自己回答。该功能工作得很好(我已经测试过了)但是当我尝试将它添加到botman的发送消息功能时它不起作用。这是我的功能:
/**
* @Route("/message", name="message")
*/
function foobar(Request $request, BotInfoRepository $botInfoRepository, MailerInterface $mailer): Response
{
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
$config = [];
// Create BotMan instance
$adapter = new FilesystemAdapter();
$botman = BotManFactory::create($config, new SymfonyCache($adapter));
// Create BotMan instance
$adapter = new FilesystemAdapter();
$botman = BotManFactory::create($config, new SymfonyCache($adapter));
$test = true;
$botman->hears('{question}', function (BotMAn $bot, $question) {
$result = $this->getDoctrine()->getRepository(BotInfo::class)->findOneBy(["question" => $question]);
if ($result != null) {
$bot->reply($result->getReponse());
} else {
//$message= $bot->getMessage();
$bot->reply('chatbot can not answer you');
$test = false;
}
});
if ($test == false) {
$email = (new Email())
->from('sender@gmail.com')
->to('reciever@gmail.com')
->subject('Question')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
$mailer->send($email);
$test = true;
}
// Start listening
$botman->listen();
return new Response();
}