Giter VIP home page Giter VIP logo

wit-facebook's Introduction

Wit-Facebook

Build Status Codacy Badge

Wit.ai and Facebook Messenger Integration Example

Initial Installation

Fork this repository and clone.

git clone https://github.com/{forked}/Wit-Facebook.git
cd Wit-Facebook
npm install

Configuration

Wit Setting

Go to https://wit.ai/home and create a wit app for you. Read https://wit.ai/docs/quickstart and see a demo at: https://wit.ai/sungkim/weather/stories. Then, go to the setting in your wit app and get the token id.

image

Test the bot.js with your WIT_TOKEN, and make sure the bot is working.

 $WIT_TOKEN=insert_token_here node bot

You can type your text, and see bot's response.

 Bot testing mode.
> What is the weather?                        # your msg
Executing merge action
Executing say with message: Where exactly?
Where exactly?                                # bot
> In Seoul?                                   # your msg
Executing merge action
Executing action: fetch-weather
Executing say with message: I see it’s sunny in Seoul today!
I see it’s sunny in Seoul today!              # bot
>

Facebook Page Creation

First you need to make a Facebook Page at https://www.facebook.com/pages/create/?ref_type=pages_browser, since the messenger bot will be connected to your facebook page.

Facebook App Creation

image

  • Add email, select category, an add web site. (Any URL is OK):

image

Facebook Messenger Setting

image

  • Select Messenger and get started:

image

  • Select the page you have created and get the Page Access Token:

image

Launch Server in Heroku

  • Run heroku create and push to heroku:
cd Wit-Facebook
heroku create
git push heroku master
  • Alternatively, click the button below:

Deploy

  • You need to set WIT_TOKEN and FB_PAGE_TOKEN. You can set your FB_VERIFY_TOKEN which is a token used to verify the server. The default value is "just_do_it". Set the WIT_TOKEN, FB_PAGE_TOKEN, and FB_VERIFY_TOKEN config variables.

image

  • Make sure "Deploy to Heroku" is green and click the "View" button:

image

  • If it is set correctly, you will see something like this from https://{yourspecificedname}.herokuapp.com/: "Only those who will risk going too far can possibly find out how far one can go." - T.S. Eliot"

Facebook Webhooks Setting

image

  • Select "Setup Webhooks", and you will see callback URL and verify token. For the callback URL put your Hherokuapp URL + "/webhook". For example, my callback URL is https://fbwitbot.herokuapp.com/webhook.

  • Type the Verify Token that you set in the Heruku app setting. If you haven't set, the default value is "just_do_it".

  • Click all items in the Subscription Fields.

image

  • Then, you will see the green complete!

image

  • You may need to select the Facebook Page one more time and get the access token.

image

  • You need to fire this command to activate your messanger.
curl -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=<PAGE_ACCESS_TOKEN>"
  • You may see:
{"success":true}
  • Finally, go to the Facebook page you created/selected, and talk to your bot. Enjoy!

image

image

Testing

Jest

npm test

Bot testing

$WIT_TOKEN=insert_token_here node bot

Server testing

First, run the server

 $WIT_TOKEN=insert_token_here node index

In other shell, fire this command:

$curl -X POST -H "Content-Type: application/json" -d @__tests__/msg.json http://localhost:8445/webhook

You will see something like this:

I'm wating for you @8445

Executing merge action
Executing action: fetch-weather
Executing say with message: I see it’s sunny in Hong Kong today!
I see it’s sunny in Hong Kong today!
Oops! An error occurred while forwarding the response to USER_ID : An active access token must be used to query information about the current user.
Waiting for futher messages.

The USER_ID error is OK, but make sure the bot says, "I see it’s sunny in Hong Kong today!".

Credit

I reused soruce code and configuration from:

Contribution

We welcome your comments and PRs!

wit-facebook's People

Contributors

hunkim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wit-facebook's Issues

No 'getForecast' action found.

When I run 'node bot' and ask "What's the weather like in Rome?" I have the error

"[error] No 'getForecast' action found."

No response from wit.ai bot

I have deployed the wit nodejs sdk on heroku. When asking any question(hows weather in india?) from FB Messenger, i am getting no response. Is there any change to be made in package.json file ?

Model not found error on bot test

When running the bot test:

WIT_TOKEN=xxx node bot

I get:

Bot testing mode.
> what is the weather?
[error] [converse] Error: Model not found (404)
[error] Model not found (404)

Any ideas?

Does not seem to work anymore

Hi,

I've set up a messenger bot on Heroku which worked fine. But since a few days it doesn't respond to any messages even though I didn't change a thing.

Error: Could not find access token

When I run the app it gives the "could not find access token error"

Error: Could not find access token, learn more at https://wit.ai/docs
    at validate (/Volumes/Macintosh HD 2/GitHub Cloned Repos/node-wit.ai/node_modules/node-wit/lib/wit.js:210:11)
    at new Wit (/Volumes/Macintosh HD 2/GitHub Cloned Repos/node-wit.ai/node_modules/node-wit/lib/wit.js:24:45)
    at Object.getWit (/Volumes/Macintosh HD 2/GitHub Cloned Repos/node-wit.ai/bot.js:82:10)
    at Object.<anonymous> (/Volumes/Macintosh HD 2/GitHub Cloned Repos/node-wit.ai/app.js:13:17)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:148:18)

As far as I know my access token is there on the const.js file

Bot not replying for other users except owner!

Is this implementation local only? As I am the owner of the FB page and app, bot replies me perfectly while when other users try to interact they do not get any answer!
Can you please help me with this?
Thanks!

Error: The 'send' action is missing

Hi! I have created my chatbot based on this code, and it has worked very well! Until now...
When I update my bot, I get the following error in heroku logs:
"The 'send' action is missing".

I have never had a 'send' action. My actions are "say", "merge" and "error".

I also got an authentication error which was solved by changing:
"return new Wit(Config.WIT_TOKEN, actions);"
to
"return new Wit({ accessToken: Config.WIT_TOKEN, actions: actions });"

Is anyone else familiar with this? It has to be a problem with the version I'm using, but I have tried to fix this all day.

Thanks in advance!

Quick instruction

image

Add a new app:
image

Select WWW platform:
image

Name it and click "Create New Facebook App ID":
image

Add email and select category:
image

Add website (any website is OK):

image

From https://developers.facebook.com/apps/, select the created app:

image

Select Messenger and get statred:
image

Select the page you have created and get the Page Acess Token:
image

Click Deploy Button in our gitrepos README.md

image

Set the WIT_TOKEN, FB_PAGE_TOKEN, and FB_VERIFY_TOKEN.
image

Make sure it's sucess and view the app:
image

You may see something like this from https://{yourspecificedname}.herokuapp.com/:
""Only those who will risk going too far can possibly find out how far one can go." - T.S. Eliot"

Final step is put this server name in the facebok app page. From https://developers.facebook.com/apps/, select your app and messenger. You will see Webhooks:

image

Select "Setup Webhooks", and you will see callback URL and verify token. For the callback URL put your herokuapp URL + "/webhook". For example, my callback URL is https://fbwitbot.herokuapp.com/webhook.

Type the Verify Token
that you set. If you haven't set, the default value is "just_do_it".

Click all items in the Subscription Fields.

image

Then, you will see green complete!
image

You may need to select the page one more time:

curl -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=<PAGE_ACCESS_TOKEN>"

You may see:
{"success":true}

Finally, go to the Facebook page, you created/selected and send a message there:
image

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.