patel/chatbot-bundle

A reusable Symfony chatbot bundle

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:CSS

Type:symfony-bundle

1.0.0 2025-06-09 04:54 UTC

This package is auto-updated.

Last update: 2025-06-09 06:59:01 UTC


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

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

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

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! πŸ€–