Basic Facebook bot (will chat with you using random phrases you set up) using Flask and Python. You can start with this bot as a basic app to build something more difficult and useful.
- Sublime Text + Terminal
- Clone this repo: https://github.com/udodihor/flask-fb-bot
- Heroku free account and Heroku CLI
- Facebook account (to use Facebook Developer Center)
- 30 min of your timeBot app
You can just clone a source code from this repo. Only few things you will need to change (Token Variables). After copying current code, go to your Terminal, open the project folder and run the following command:
$ pip install -r requirements.txtSo now, you can run a flask app using terminal (in project folder):
$ python app.pyIf all goes well, you might see a URL to the Flask App. To test it, copy and paste this link to the browser or just type: http://localhost:5000
You will see an error: Invalid verification token.
1. Set up a Facebook Application
1.1. Create app
Go to: https://developers.facebook.com/apps Create a new application with a random name. Next, when prompted on the next page for the type of product you are building, click the “Set Up” button on the Messenger option.
After you were redirected on the Settings page, you need to select or create a specific Facebook Page (Public community or other) to assign to your bot.
Now, you need to Generate Token for your app and actually paste this FB token to your application in 
app.pyACCESS_TOKEN = 'GENERATED_TOKEN_FROM_FACEBOOK'Next, in the 
VERIFY_TOKENTESTINGTOKEN2. Create a Heroku account
Register on Heroku. It's free.
3. Setup Heroku CLI
Go to your terminal, and paste following command:
$ brew tap heroku/brew && brew install heroku
or download and install automatically here.
After Heroku CLI is successfully installed, we could create our first heroku application! 👏
4. Heroku app creation
In your terminal, run next command:
$ heroku login and push any button.
You'll be redirected to default browser app and asked for login to your heroku account. After successful login, go back to your terminal window. Now you're logged in. To create new app, run command:
$ heroku createHeroku will automatically create a new application instance in your account. After creation, you will see a git URL to your heroku app (we will deploy our bot there).
Finally, to deploy the app, paste next command in your terminal:
$ git push heroku master⚠️ NOTE: If you cloned this repo, it will work fine. If you just downloaded the files from GitHub, you will need to initiate git repo, and create first commit and only then start to push your code to heroku:
$ git init.$ git add -A && git commint -m "First commit"After that, copy the URL of your heroku web-app you previously created. You can check it in your heroku account (go into the created application, and find an "Open" button).
5. Set up Webhook
Here, you will need to paste URL to your heroku app (we copied it in previous step), and into another field put the value (
VERIFY_TOKEN = YOUR_CREATED_VALUEIf you've did all right, Facebook will test this callback and add this to the app. After that, for the subscription fields, be sure to check the 
messagesmessaging_postbacksmessage_deliveriesmessaging_pre_checkoutsSo, it was a final step. Go to your messages in Facebook, create a new message and send it to previously created community/group.
Enjoy & Thank you! 👏 🙌
Alternative deployment, using ngrok is here
Feel free to ask me here or on reddit
