Building an Oxford House Chat Bot

So I decided I wanted to build a chat bot, specifically for Oxford House; which will allow natural language queries concerning the rules and data associated with the particular house and organization in my locale.

After looking into this a bit, and experimenting with some more naive implementations using selenium and other automation solutions, I found a few video tutorials online that suggested a more professional approach. After all I do not want to get banned from platforms or services because of improper implementation.

So the desired front-end, for this project, at this point in time, is Facebook Messenger. Specifically, the messenger attached to my SparkOne() Labs page. Here are two tutorials I will be following in order to implement this.

  1. https://www.youtube.com/watch?v=RP8nhiiQnTc — Flask app running on NGinx on a Digital Ocean droplet
  2. https://www.youtube.com/watch?v=OL5fC7RpK4Y&list=PL7eGS_IL1eWSMHUeVmIbZ2G7UQ3KLoqR9&index=13&t=2245s — Facebook Messenger API with Webhook
  3. https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04 — Quick and easy way to deploy flask nginx and SSL with certbot
  4. https://www.freenom.com/en/index.html — Free domains

So after reviewing these excellent video tutorials, I decided to follow this implementation. I already have a domain, sparkonelabs.com, so I created a subdomain through the hostgator cPanel and pointed to the reserved IP of the DO droplet which was created for this project.

This involved creating an A record for the subdomain. The subdomain is webhook.sparkonelabs.com

Ok, so two droplets were created, but was having trouble with getting Nginx and uwsgi to talk to each other.

In the meantime I went on github and searched for a python based FB messenger webhook project with a python base and found the following:

  1. https://github.com/iTeam-S/Ampalibe?tab=readme-ov-file — A quick easy FB messenger boilerplate
  2. https://ngrok.com/ — A reverse tunnel solution for deploying localhost with https for testing

Well here we are and I feel pretty dumb. A week! Just to get some webhooks and API calls to work…

Anyway, the following script was created and run against an Ampalibe server running on localhost at port 4555:

#!/bin/bash
CHALLENGE_ACCEPTED = 'ok'
echo "This script tests the webhook located at localhost:4555, proper functioning will generate a console print 'CHALLENGE_ACCEPTED'"
curl -X GET "localhost:4555?hub.verify_token=8af92b1dc35e60f7&hub.challenge=CHALLENGE_ACCEPTED&hub.mode=subscribe"

So the verification function works, and the proper Verification request type is GET.

Anyway, There is another line to the testing, and it crashes the Ampalibe server with a key-error, however… Worrying about that is co-lateral with the issue at hand. Obviously the problem here is not with the webhook. It is working, or at least working enough when I send the message template from the localhost.

In order to determine if the problem is with a local firewall, I can run the same test from the VPS droplet, with localhost’s port 4555 open. However, I suspect that the FB messenger app itself it not sending out the requests these webhooks are expecting, in fact not sending out any requests at all.

Leave a Reply

Your email address will not be published. Required fields are marked *