Convert your wordpress site into an AI-based chatbot.
In the below image, I have deployed a WordPress chatbot on MessengerX platform based on the Mozilla Blog website. I have written the steps below. If you are a WordPress website owner then contact the MessengerX team they have the right thing for you.
So, in this article I will be deploying a chatbot, pointing it to a Wordpress site and it will provide us with realtime news, articles. As the MessengerX platform has made it easy to create a chatbot and get realtime data directly from the WordPress website and serve the users.
I will be using
- Wordpress Chatbot created by MessengerX platform.
- ngrok (optional)
- API Key, which you can get from MessengerX or by emailing them here.
- screen, we will use the screen to run programs in the background. Do read this article.
Placing the API Key and target Wordpress URL
So, open chatbot.py and replace the following with your data. You can also pass it as an environment variable instead.
name = os.environ.get('WP_BOT_NAME', '<Your-Chatbot-Name>') domain = os.environ.get('WP_BOT_BASE_URL', '<Wordpress-website-URL>') machaao_api_token = os.environ.get('MACHAAO_API_TOKEN', '<Api-Key>')
Installing requirements files for running the chatbot.
We will be installing the dependencies for the chatbot. If you have installed other versions of pymongo then you need to uninstall it and install pymongo v3.7.2 for better working.
pip3 install -r requirements.txt pip3 uninstall pymongo pip3 install pymongo==3.7.2
Running flask server and downloading nltk files
nltk is a python library for natural language processing and flask server will be used to scrap the data from wordpress site and server the scraped data to users using chatbot.
screen python3 chatbot.py
Output
resetting db file if exists initiating a wordpress bot with name -> abhi.wpbot, base_url -> https://blog.mozilla.org/, machaao_base_url -> https://ganglia-dev.machaao.com, token -> e35d31e0-a3c2-11ea-bd5b-03e4990f9f5b, db_uri -> None [nltk_data] Downloading package stopwords to [nltk_data] /home/abhishek/nltk_data... [nltk_data] Package stopwords is already up-to-date! [nltk_data] Downloading package averaged_perceptron_tagger to [nltk_data] /home/abhishek/nltk_data... [nltk_data] Package averaged_perceptron_tagger is already up-to- [nltk_data] date! * Serving Flask app "chatbot" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: off * Running on https://0.0.0.0:5000/ (Press CTRL+C to quit)
Pressing Ctrl+a then d, will detach the current screen and the program will run in the background.
Exposing the localhost to public DNS using ngrok (OPTIONAL).
I am running locally thats why using ngrok. When deploying on production then skip this step and add PORT 5000 to inbound traffic.
ngrok helps you to serve the localhost to public DNS. So just download and setup ngrok.
sudo snap install ngrok ngrok authtoken <YOUR_AUTH_TOKEN>
Now create a screen and run ngrok server.
screen ngrok http 5000
Output:
ngrok by @inconshreveable (Ctrl+C to quit) Session Status online Account [email protected] (Plan: Free) Version 2.3.35 Region United States (us) Web Interface https://127.0.0.1:4040 Forwarding https://6bfb1e7e56bd.ngrok.io -> https://localhost:5000 Forwarding https://6bfb1e7e56bd.ngrok.io -> https://localhost:5000 Connections ttl opn rt1 rt5 p50 p90 15 0 0.00 0.00 11.88 14.03
Press Ctrl+a then d. It will detach the current screen and the program will run in the background
NOTE: Copy the forwarding url, you will use it ahead.
Deploying on MessengeX platform.
I sent a POST request to the API of MessengerX platform. You can use the curl command on the terminal or use POSTMAN or similar tool.f everything went well, the chatbot is deployed now.
To see the chatbot visit this URL
https://dev.messengerx.io/<YOUR_BOT_NAME> OR https://ganglia-dev.machaao.com/<YOUR_BOT_NAME>
If you are a WordPress site owner then I would recommend this chatbot for the website.
Integrate it with zero coding required.
Do check out other deployed chatbots on MessengerX.
- https://dev.messengerx.io/reddit.bot
- https://dev.messengerx.io/asviral
- https://dev.messengerx.io/techcrunch
- https://dev.messengerx.io/bello.news
For questions and feedback, please join our community https://gitter.im/messengerx-io/community
For the production server, Gunicorn or uWSGI server is recommended.