This is my Facebook bot for answering coding questions. You may ask questions in the form
How to [task description] in [programming language]?
such as
- How do I format timestamps in Java?
- How can I find the largest number of in an array in Swift?
- What is the difference between null and undefined in JavaScript?
and it will send you code snippets and/or explanations such as
What about:
let numbers = [1, 6, 3, 9, 4, 6]
numbers.minElement()
numbers.maxElement()
Click below to watch a demo of my bot in YouTube.
- 2016 May 21: New Feature. My bot can now extract code blocks from the answer and create a link to a paste service for you to download the code.
- 2016 May 20: Facebook has approved my page for the permission of sending messages to users. You may message my bot for coding questions from here.
You need several API keys to use this bot.
- FB_PAGE_ID:
- Create a Facebook page from https://developers.facebook.com/apps/
- Go to your page.
- Your page id is under Settings -> Page Info -> Facebook Page ID.
- FB_PAGE_TOKEN:
- Visit your page from https://developers.facebook.com
- Find your token under Meseenger -> Page Access Token.
- FB_VERIFY_TOKEN: Any string of your choice.
- WIT_TOKEN: Create a wit app from https://wit.ai/home and find your Server Access Token from Settings.
You may create a Wit story like the following.
There are two ways to deploy this app to Heroku, automatic deploys or manual deploys.
After deployment, follow the steps below to setup Facebook Webhooks.
- Create a Heroku app if you do not have one.
- Visit your page from https://developers.facebook.com
- Go to Webhooks from the side menu.
- Set your Callback URL to the following and your Verify Token to your FB_VERIFY_TOKEN
https://your-heroku-app-id.herokuapp.com/fb
You need to configure your environment variables FB_PAGE_ID, FB_PAGE_TOKEN, FB_VERIFY_TOKEN, WIT_TOKEN under Settings of your Heroku app.
heroku create
git push heroku master
You need to configure environment variables before testing.
export FB_PAGE_ID=YOUR_FACEBOOK_PAGE_ID
export FB_PAGE_TOKEN=YOUR_FACEBOOK_PAGE_TOKEN
export FB_VERIFY_TOKEN=YOUR_FACEBOOK_VERIFY_TOKEN
export WIT_TOKEN=YOUR_WIT_TOKEN
npm test
node src/bot
I reused soruce code and configurations from: