How to add an AI chatbot to a Laravel app

A practical plan for adding an AI chatbot to an existing Laravel app: answering from your own data, permissions, queues, logging and a human handoff.

Adding an AI chatbot to a Laravel app is mostly ordinary Laravel work. The model call is a few lines. The parts that decide whether the chatbot is useful or embarrassing are the ones around it: what it is allowed to know, what it is allowed to do, and what happens when it doesn't know.

This guide is the plan I follow when I add a chatbot to an existing Laravel application.

1. Decide what the chatbot is for

Write down the five to ten questions customers or staff ask most, and the action each one leads to. "What are your opening hours?" needs an answer. "Can I move my appointment to Friday?" needs a lookup and a change in your database. A chatbot that only answers FAQs is a much smaller job than one that books, cancels and updates records, so decide this first.

2. Answer from your own content, not the model's memory

A general model does not know your prices, policies or stock. Give it your content at question time instead:

  • Collect the sources: service pages, FAQs, policy documents, product data.
  • Split them into short passages and store them with an embedding (a numeric fingerprint of the text) so similar passages can be found quickly.
  • For each question, fetch the few most relevant passages and send only those to the model, with an instruction to answer from them and say when the answer isn't there.

This pattern is usually called retrieval-augmented generation (RAG). It keeps answers tied to your content and makes "I don't know" a normal, safe answer.

3. Use your existing permissions

If the chatbot can look up orders or bookings, it must do so as the signed-in user, through the same models and policies the rest of the app uses. Never give the model a database connection or a raw SQL tool. Expose a small set of actions instead, such as "find my next booking" or "list my open invoices", each written as a normal Laravel service method that checks authorisation.

4. Keep the request out of the page load

Model calls can take several seconds. Send the question to a queued job, stream or poll for the answer, and set sensible timeouts and retries. A slow provider should never slow down the rest of your app.

5. Log everything and set limits

Store each conversation: the question, the passages used, the answer and any action taken. Add per-user and per-day limits, and an alert when usage rises. Logs are how you find wrong answers and missing content, and limits are how you avoid a surprise bill or abuse of a public chat box.

6. Hand off to a person

Every chatbot needs a clear way out: "Talk to a person" sends the conversation to email, your helpdesk or WhatsApp with the history attached. Questions the bot couldn't answer are also your list of content to add next.

7. Keep the provider swappable

Wrap the model in one service class with a simple interface such as "answer this question with these passages". Then moving between OpenAI, Claude or another model, or using a cheaper model for simple questions, is a configuration change rather than a rewrite.

8. Launch small

Start with the top questions and one action, on one channel. Review real conversations every week for the first month, fix the content gaps, then add the next action or channel.

Common mistakes

  • Letting the model answer from its own general knowledge about your business.
  • Giving the chatbot more access than the user it is talking to.
  • Calling the model during the web request with no timeout.
  • No logs, so nobody knows what the bot told customers.
  • No human handoff, so hard questions end in a loop.

Need help adding one?

I build AI chatbots inside existing Laravel, Node.js and React apps, connected to your real data and permissions. See AI chatbot development, or book a call to talk through your app.

Need help with your project?

Learn more about ai chatbot development for websites, whatsapp and apps or get in touch to discuss your project.

Contact Me