Building Chatbot Interfaces using botMafia

Abhijith J
2 min readApr 2, 2021

BotMafia is a service that provides chatbot developers with a set of chatbot themes so that the developers can solely focus on the server-side of their chatbot. It is so easy that you can set up your chatbot in a couple of minutes

Visit https://botmafiaproject.herokuapp.com/

Login to Botmafia with your email address and click on Create New Bot. Once you do that, you will be asked to fill up a form involving the bot-name, bot-URL, and bot information. When specifying bot information, you have to understand that it will be the first message given to the user when they access your chatbot. It should be more like an introduction to what your bot does.

A note on Bot URL

When you set up your bot server, you might need to make your local server accessible from the internet. For this, you can use multiple tools. The one that Botmafia prefers is Ngrok.

Once you download and install Ngrok, type in the following command

$ ngrok http <your-port-number>

Suppose, if your port number is 3000, then it would be ngrok http 3000

Ngrok will tunnel your local server and you will be able to access it from the internet. Copy the https link that you see on the Ngrok command line and paste it into BotMafia bot-url textbox. You can always edit the bot-url when you deploy globally.

Sample Python Code

Once you enter a message and hit send, a POST request will be made to your server containing a JSON message.

{msg:”Sample Text”}

Extract the msg from the above JSON and write the code that will process the query.

from flask import Flask,request,jsonifyfrom flask_cors import CORS, cross_originapp = Flask(__name__)cors = CORS(app, resources={r"/": {"origins": "*"}})app.config['CORS_HEADERS'] = 'Content-Type'@app.route("/",methods=['GET','POST'])@cross_origin(origin='*',headers=['Content- Type','Authorization'])def index():    if request.method == "POST":          print(request.get_json())          message = {'body':'Hello, Testing my bot!'}          return jsonify(message)if __name__ == "__main__":          app.run(debug=True,port=3000)

This sample code is written in Flask. The basic idea of this code is that it will look for POST requests and once it gets it will return the appropriate message in a JSON format that looks like message = {‘body’:’Response!’}

Also, make sure to disable CORS. Disabling CORS will be different for different frameworks. In python, disabling CORS is as given in the above code.

Happy Hacking!!

--

--