waitingcheung / messenger-bot

Facebook messenger bot for answering coding questions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

messenger-bot

Build Status codecov license

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 to message my bot.

Demo

Click below to watch a demo of my bot in YouTube.

IMAGE ALT TEXT HERE

Update

  • 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.

Configuration

API Keys

You need several API keys to use this bot.

Wit Story

You may create a Wit story like the following.

Deployment to Heroku

There are two ways to deploy this app to Heroku, automatic deploys or manual deploys.

Automatic Deploys

Deploy

After deployment, follow the steps below to setup Facebook Webhooks.

Manual Deploys

Facebook Webhooks

  1. Create a Heroku app if you do not have one.
  2. Visit your page from https://developers.facebook.com
  3. Go to Webhooks from the side menu.
  4. Set your Callback URL to the following and your Verify Token to your FB_VERIFY_TOKEN
https://your-heroku-app-id.herokuapp.com/fb

Heroku Environment Variables

You need to configure your environment variables FB_PAGE_ID, FB_PAGE_TOKEN, FB_VERIFY_TOKEN, WIT_TOKEN under Settings of your Heroku app.

Deployment

heroku create
git push heroku master

Testing

You need to configure environment variables before testing.

Environment Variables

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

Unit Testing

npm test

Bot Testing

node src/bot

Credit

I reused soruce code and configurations from:

About

Facebook messenger bot for answering coding questions

License:MIT License


Languages

Language:JavaScript 100.0%