Skip to content
Advertisement

How to integrate python chatbot to a website

I have created a chatbot in python. I have also created a UI in html, css and js and connected the python chatbot to ui using flask. This is how it looks.

UI Image

How to flow goes is when a user inputs in the chat ui, the content is sent to flask and from flask to python file. The python file provides a response to flask app which passes the response to ui file where it is shown.

Now, the question is I have a different website and I want to integrate the UI created to this website. How can I do this?

Advertisement

Answer

So, if you have the front-end and back-end separately, then what you have to do, is make request to your back-end that runs on a separate server and the front-end on other. Since you are using flask, this might be the sample of route:

@app.route("/chat")
def chat():
    message = request.args["message"]
    reply = "Something to reply"
    return reply

Then, in the front-end you can make requests with JQuery

$.ajax({
  type: "GET",
  url: "yourdomain.com/chat"
  data: {
    message: "The message from the client side"
  },
  success: (data)=> {
    //  do something with the reply here
  }
})
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement