Fork the repository (https://help.github.com/en/github/getting-started-with-github/fork-a-repo). A fork is a personal copy of the repository.
Go to your repositories and clone your fork of this repository (https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository). Cloning is synonymous with downloading in this context.
Navigate to the root directory for the project, leetcode-reminder-bot. Create a copy of secret_example.yaml called secret.yaml.
- Navigate to https://developers.facebook.com/.
- Go to
My Apps(top-right) and click onLeetcode Reminder Bot. - On the left panel under
Products, click onMessengerand thenSettings. - Now focusing on the center of the page, scroll down to the section titled
Access Tokens. - Hit
Generate Token. Insecret.yaml, forPAGE_ACCESS_TOKEN: Get_From_FB_APIreplaceGet_From_FB_APIwith the token. Don't close this page, we'll return to it shortly.
- Download
ngrokfrom https://ngrok.com/download. - Open a separate terminal window and navigate to where the
ngrokprogram is. Run./ngrok http 5000, which will runngrokcontinuously. We'll return to this after the next section.
We're going to fucking it run it now.
- Make sure you have Python 3.6.8 installed.
- Go back to the root of the directory.
- Run
pip3 install -r requirements.txtto install the requirements. - Run
python3 app.py.
Leave it running in the background
- In
secret.yaml, forVERIFY_TOKEN: Made_Up_Phrase_You_Set_In_The_FB_API_When_You_Set_Your_Endpoint, replace the filler string with some made up token, e.g.AndrewLiIsBetterThanAndrewDing. - Go back to the terminal running
ngrok. The output should expose a URL, for exampleForwarding http://d59cf242.ngrok.io -> http://localhost:5000. COPY THEHTTPSURL NOT THEHTTPURL (they're basically identical but only https will work). - Go back to the FB Dev page you were on. Directly below the
Access Tokenssection should be theWebhookssection. - Hit
Edit URLand paste your exposed URL, such ashttps://dbf2d510.ngrok.iointo theCallback URLfield. In theVerify Tokenfield, paste the token you mae up earlier. Save.
What's happening here is you're exposing an IP, which should be 5000 (remember http://localhost:5000 from the ngrok output?) by default, for external access, however this is IP is local and can only be used internally on your computer. ngrok forwards or maps that IP to a random URL owned by their company, such as http://d59cf242.ngrok.io, which can be accessed externally by people, such as Facebook.
We need a database to store our users.
Navigate to https://brew.sh/ and read about Homebrew, I'm too lazy to explain it lol. Follow the installation steps in a new terminal window. We need this to install some shit.
Postgres, psql, postgresql, or whatever the fuck you want to call it is a kind of database management system, similar to MySQL for example. Run brew install postgresql to install it.
What is an alias? If you find yourself typing the same long ass command a million times, you can make an alias that runs the command, which saves you time. For example, alias run-that-shit='python3 main.py --arg1 flag1 --arg2 flag2 --arg420 flag420' means you can run run-that-shit instead of python3 main.py --arg1 flag1 --arg2 flag2 --arg420 flag420. Time. Saved.
Use emacs or vi to edit your ~/.bashrc file to contain the following lines:
alias psql-start='pg_ctl -D /usr/local/var/postgres start'
alias psql-stop='pg_ctl -D /usr/local/var/postgres stop'
Run psql-start to start postgres. It runs in the backgorund until you run psql-stop.
In a nutshell, have you ever run something your personal laptop and had it work and then had it fail on a school lab machine because of a different operating system? docker allows us to run a "containerized environment", which means you can specify the operating system and versions of technology you are using, ensuring that the same code works across different machines.
- Run
brew install docker docker-compose docker-machine xhyve docker-machine-driver-xhyveto installdockerand friends. - Install Docker Desktop from here: https://www.docker.com/products/docker-desktop.
- Run Docker Desktop (probably just called Docker in your applications) and wait for its status to change to "Running" which can monitored from the drop down from clicking on the whale on the OS X task bar.
- Open a new terminal window and navigate to
leetcode-reminder-bot/pg. - Run
docker-compose up -d. This uses thedocker-compose.yamlfile to create a new container running a PSQL image specified to run version 10 on port 5433 with usernameadminand passwordpassword. This is only available locally, so it's not a security threat. - Run
./seed-db.shto create the appropriate columns and rows in the database. - Download http://www.psequel.com/. To connect to the database,
Hostshould belocalhost,Usershould beadmin,Passwordshould bepassword.Databaseshould bepostgres.Portshould be5433Use SSLandUse SSH Tunnelingshould both be unchecked. Connect and take a look around.
Open Facebook messenger from your phone. You can't do it from the desktop version because you're an admin for the page and if you try to message the page, it just logs you in as the page. Message Leetcode Reminder Bot from your phone.
Run git add . to add to current commit.
Run git commit -m "message describing change here" to stage change.
Run git push to push changes to GitHub.
Holy shit we're done. Finish my side-project now, Leah!