{"id":15633213,"url":"https://github.com/hunkim/wit-facebook","last_synced_at":"2025-04-09T20:08:26.978Z","repository":{"id":98203228,"uuid":"56869841","full_name":"hunkim/Wit-Facebook","owner":"hunkim","description":"Wit-Faebook Messenger Example ","archived":false,"fork":false,"pushed_at":"2016-07-21T12:43:59.000Z","size":32,"stargazers_count":157,"open_issues_count":7,"forks_count":257,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-09T20:08:21.005Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hunkim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-22T16:29:39.000Z","updated_at":"2025-03-12T17:57:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"f564772f-1873-4e4d-9e3e-10406bb38806","html_url":"https://github.com/hunkim/Wit-Facebook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunkim%2FWit-Facebook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunkim%2FWit-Facebook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunkim%2FWit-Facebook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunkim%2FWit-Facebook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hunkim","download_url":"https://codeload.github.com/hunkim/Wit-Facebook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103873,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T10:47:32.199Z","updated_at":"2025-04-09T20:08:26.954Z","avatar_url":"https://github.com/hunkim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wit-Facebook\n[![Build Status](https://travis-ci.org/hunkim/Wit-Facebook.svg?branch=master)](https://travis-ci.org/hunkim/Wit-Facebook)\n[![Codacy Badge](https://api.codacy.com/project/badge/grade/7442b6c4eb6b48a890d751c0da5a3b6d)](https://www.codacy.com/app/hunkim/Wit-Facebook)\n\nWit.ai and Facebook Messenger Integration Example\n## Initial Installation\nFork this repository and clone.\n\n```bash\ngit clone https://github.com/{forked}/Wit-Facebook.git\ncd Wit-Facebook\nnpm install\n ```\n\n## Configuration\n### Wit Setting\n\nGo 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.\nThen, go to the setting in your wit app and get the token id.\n\n![image](https://cloud.githubusercontent.com/assets/901975/14757067/58f03050-0922-11e6-813d-831df8614303.png)\n\nTest the bot.js with your WIT_TOKEN, and make sure the bot is working.\n```bash\n $WIT_TOKEN=insert_token_here node bot\n ```\n\n You can type your text, and see bot's response.\n\n```bash\n Bot testing mode.\n\u003e What is the weather?                        # your msg\nExecuting merge action\nExecuting say with message: Where exactly?\nWhere exactly?                                # bot\n\u003e In Seoul?                                   # your msg\nExecuting merge action\nExecuting action: fetch-weather\nExecuting say with message: I see it’s sunny in Seoul today!\nI see it’s sunny in Seoul today!              # bot\n\u003e\n```\n\n### Facebook Page Creation\nFirst 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.\n\n### Facebook App Creation\n\n* Add a new app at https://developers.facebook.com/quickstarts/?platform=web. Name it and click  \"Create New Facebook App ID\":\n\n![image](https://cloud.githubusercontent.com/assets/901975/14749905/b557bf80-08f4-11e6-8218-2dd8dc7d529c.png)\n\n* Add email, select category, an add web site. (Any URL is OK):\n\n![image](https://cloud.githubusercontent.com/assets/901975/14749960/ef969b94-08f4-11e6-9fa6-3294a47fcf4e.png)\n\n### Facebook Messenger Setting\n\n* From https://developers.facebook.com/apps/, select the created app:\n\n![image](https://cloud.githubusercontent.com/assets/901975/14757262/32399512-0924-11e6-924f-6b52d6303ecf.png)\n\n* Select Messenger and get started:\n\n![image](https://cloud.githubusercontent.com/assets/901975/14750051/6733be3e-08f5-11e6-9da7-a35eb2720298.png)\n\n* Select the page you have created and get the Page Access Token:\n\n![image](https://cloud.githubusercontent.com/assets/901975/14757285/78e65248-0924-11e6-9ffb-e6226a7d434f.png)\n\n### Launch Server in Heroku\n\n* Run heroku create and push to heroku:\n\n```bash\ncd Wit-Facebook\nheroku create\ngit push heroku master\n```\n\n* Alternatively, click the button below:\n\n[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)\n\n* 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.\n\n![image](https://cloud.githubusercontent.com/assets/901975/14750245/627a5d20-08f6-11e6-9672-f19b3719eb2b.png)\n\n* Make sure \"Deploy to Heroku\" is green and click the \"View\" button:\n\n![image](https://cloud.githubusercontent.com/assets/901975/14750332/d59fad46-08f6-11e6-9f24-16fff6b98898.png)\n\n* If it is set correctly, you will see something like this from https://{yourspecificedname}.herokuapp.com/:\n\"Only those who will risk going too far can possibly find out how far one can go.\" - T.S. Eliot\"\n\n### Facebook Webhooks Setting\n\n* The final step is to put this server URL in the Facebook app setting. From https://developers.facebook.com/apps/, select your app and messenger. You will see Webhooks:\n\n![image](https://cloud.githubusercontent.com/assets/901975/14750370/0d98de98-08f7-11e6-8c6b-85733dab4fb4.png)\n\n* 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.\n\n* Type the Verify Token that you set in the Heruku app setting. If you haven't set, the default value is \"just_do_it\".\n\n* Click all items in the Subscription Fields.\n\n![image](https://cloud.githubusercontent.com/assets/901975/14750713/c64e4ee0-08f8-11e6-8745-2ebc746ae367.png)\n\n* Then, you will see the green complete!\n\n![image](https://cloud.githubusercontent.com/assets/901975/14750734/e59c1016-08f8-11e6-9333-fbb7c92dd342.png)\n\n* You may need to select the Facebook Page one more time and get the access token.\n\n![image](https://cloud.githubusercontent.com/assets/901975/14757285/78e65248-0924-11e6-9ffb-e6226a7d434f.png)\n\n* You need to fire this command to activate your messanger.\n\n```bash\ncurl -X POST \"https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=\u003cPAGE_ACCESS_TOKEN\u003e\"\n```\n* You may see:\n```bash\n{\"success\":true}\n```\n\n* Finally, go to the Facebook page you created/selected, and talk to your bot. Enjoy!\n\n![image](https://cloud.githubusercontent.com/assets/901975/14750786/20ddf0a4-08f9-11e6-9c9c-719d1020e5d8.png)\n\n![image](https://cloud.githubusercontent.com/assets/901975/14751164/2a485e2a-08fb-11e6-9a98-fd79bb0773f7.png)\n\n## Testing\n\n### Jest\n ```bash\n npm test\n ```\n\n### Bot testing\n ```bash\n $WIT_TOKEN=insert_token_here node bot\n ```\n\n### Server testing\nFirst, run the server\n```bash\n $WIT_TOKEN=insert_token_here node index\n ```\n In other shell, fire this command:\n ```bash\n $curl -X POST -H \"Content-Type: application/json\" -d @__tests__/msg.json http://localhost:8445/webhook\n```\n\nYou will see something like this:\n```\nI'm wating for you @8445\n\nExecuting merge action\nExecuting action: fetch-weather\nExecuting say with message: I see it’s sunny in Hong Kong today!\nI see it’s sunny in Hong Kong today!\nOops! An error occurred while forwarding the response to USER_ID : An active access token must be used to query information about the current user.\nWaiting for futher messages.\n```\n\nThe USER_ID error is OK, but make sure the bot says, \"I see it’s sunny in Hong Kong today!\".\n\n## Credit\nI reused soruce code and configuration from:\n* https://github.com/wit-ai/node-wit\n* https://github.com/jw84/messenger-bot-tutorial\n* https://developers.facebook.com/docs/messenger-platform/quickstart\n\n## Contribution\nWe welcome your comments and PRs!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunkim%2Fwit-facebook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhunkim%2Fwit-facebook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunkim%2Fwit-facebook/lists"}