patel/chatbot-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

patel/chatbot-bundle

Composer 安装命令:

composer require patel/chatbot-bundle

包简介

A reusable Symfony chatbot bundle

README 文档

README

Chatbot Bundle

A Symfony bundle that provides a menu-based chatbot widget with category management and FAQ functionality. The chatbot appears as a floating button on the right side of your website and allows users to browse categories and get answers to frequently asked questions.

Features

  • 🤖 Interactive chatbot widget
  • 📁 Category management system
  • ❓ FAQ management with category-wise organization
  • 🎨 Floating button interface design
  • 🔧 Easy integration with existing Symfony projects

Installation

Step 1: Add Configuration

Create the file config/packages/chatbot.yaml: Create the file config/packages/chatbot.yaml and set the user_question_entity parameter to the fully qualified namespace of your user question entity class.

chatbot:
    role: ROLE_CHATBOT_ADMIN
    user_question_entity: App\Entity\UserQuestion

Step 2: Install the Bundle

Install the chatbot bundle using Composer:

composer require patel/chatbot-bundle

Step 3: Register the Bundle

Add the bundle to your config/bundles.php file:

return [
    // ... other bundles
    Chatbot\ChatbotBundle::class => ['all' => true],
];

Step 4: User-Submitted Questions

Users can submit their own questions through the chatbot. Admins can respond and choose to publish them in the FAQ. Users receive email notifications when their question is answered.

Implement ChatbotUserInterface

In your user entity (e.g., Admin):

use Chatbot\Security\ChatbotUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

class Admin implements ChatbotUserInterface
{
    #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserQuestion::class)]
    private Collection $questions;

    public function __construct()
    {
        $this->questions = new ArrayCollection();
    }

    public function getQuestions(): Collection
    {
        return $this->questions;
    }
}

Create a UserQuestion Entity

namespace App\Entity;

use Chatbot\Entity\ChatbotUserQuestion as BaseQuestion;
use Chatbot\Security\ChatbotUserInterface;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'chatbot_user_question')]
class UserQuestion extends BaseQuestion
{
    #[ORM\ManyToOne(targetEntity: Admin::class, inversedBy: 'questions')]
    #[ORM\JoinColumn(nullable: false)]
    private ChatbotUserInterface $user;

    public function getUser(): ChatbotUserInterface
    {
        return $this->user;
    }

    public function setUser(ChatbotUserInterface $user): static
    {
        $this->user = $user;
        return $this;
    }
}

Create a UserQuestionRepository Repository

declare(strict_types=1);

namespace App\Repository;

use App\Entity\UserQuestion;
use Chatbot\Repository\UserQuestionRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<ClientNote>
 */
class UserQuestionRepository extends ServiceEntityRepository implements UserQuestionRepositoryInterface
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, UserQuestion::class);
    }
}

Configure Email Notifications

Set the FROM_EMAIL in your .env:

FROM_EMAIL="your@email.com"

Step 5: Install Assets

php bin/console assets:install --symlink

This will publish necessary asset files to the public/bundles/ directory.

Step 6: Create and Run Migrations

Generate and execute the database migrations:

php bin/console make:migration
php bin/console doctrine:migrations:migrate

Step 7: Include the Chatbot Widget and isUserLoggedIn

Include the widget in your base template (templates/base.html.twig):

<body>
    {{ include('@Chatbot/chatbot_widget.html.twig') }}
    <!-- Your content -->
</body>

Add in script tag:

<script>
    const isUserLoggedIn = {{ app.user is not null ? 'true' : 'false' }};
</script>

Step 8: Add Routes

Add the following to config/routes.yaml:

chatbot_bundle:
  resource: '@ChatbotBundle/Resources/config/routes.yaml'

Step 9: Add in your services.yaml

Chatbot\Repository\UserQuestionRepositoryInterface: '@App\Repository\UserQuestionRepository'

Usage

Category Management

Visit /chatbot/category to:

  • Add new categories
  • Edit or delete existing ones

FAQ Management

Visit /chatbot/faq to:

  • Add new FAQs with answers
  • Edit or remove outdated questions
  • Assign FAQs to categories

User Interaction

  • Users click the chatbot button on the website
  • Categories are shown
  • Clicking a category reveals related FAQs
  • Users can ask their own questions

Customizing Templates

Step 1: Locate Original Templates

  • vendor/patel/chatbot-bundle/src/Resources/views/category/
  • vendor/patel/chatbot-bundle/src/Resources/views/faq/

Step 2: Create Override Directories

mkdir -p templates/bundles/ChatbotBundle/category
mkdir -p templates/bundles/ChatbotBundle/faq

Step 3: Copy Templates

cp vendor/patel/chatbot-bundle/src/Resources/views/category/index.html.twig templates/bundles/ChatbotBundle/category/
cp vendor/patel/chatbot-bundle/src/Resources/views/faq/index.html.twig templates/bundles/ChatbotBundle/faq/

Step 4: Clear Cache

php bin/console cache:clear

Available Routes

Path Name Purpose
/chatbot chatbot Chatbot homepage
/chatbot/user-questions chatbot_user_questions_index Manage user-submitted questions
/chatbot/category chatbot_category_index Manage categories
/chatbot/faq chatbot_faq_index Manage FAQs
/chatbot/widget chatbot_widget Display chatbot widget
/chatbot/faqs/{categoryid} chatbot_faqs_by_category Get FAQs by category (AJAX/API)

Flow Diagram

1. 📂 Category Management (Admin Panel)

Category CRUD

2. ❓ FAQ Management (Admin Panel)

FAQ CRUD

3. User Queries Management (Admin Panel)

Queries CRUD

4. 🤖 Chatbot Interface

Chatbot Icon Show Categories Show FAQs Show ASK Questions

Customization

Styling

Override default styles using your own CSS targeting the chatbot’s class names.

Templates

As explained above, copy templates from the bundle and place them in:

  • templates/bundles/ChatbotBundle/category/
  • templates/bundles/ChatbotBundle/faq/

Requirements

  • PHP 8.2 or higher
  • Symfony 6 or higher
  • Doctrine ORM
  • Twig

Troubleshooting

Assets Not Loading

  • Run php bin/console assets:install --symlink
  • Check public/bundles/chatbot/ exists
  • Ensure proper file permissions

Database Errors

  • Verify DB configuration
  • Run: php bin/console doctrine:schema:validate
  • Run: php bin/console cache:clear

Twig Template Errors

  • Check twig.yaml is correctly set up
  • Verify config/bundles.php includes the bundle
  • Clear the Twig cache
  • composer require twig/string-extra

Contributing

We welcome contributions! Feel free to open issues or submit pull requests for new features or bug fixes.

License

This bundle is open-source and licensed under the MIT License.

Support

If you need help or have questions, feel free to open an issue on GitHub or contact the development team.

Happy chatting! 🤖

patel/chatbot-bundle 适用场景与选型建议

patel/chatbot-bundle 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 patel/chatbot-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 patel/chatbot-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 patel/chatbot-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-09