• Stars
    star
    158
  • Rank 237,131 (Top 5 %)
  • Language
    JavaScript
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Wit-Faebook Messenger Example

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!

More Repositories

1

DeepLearningZeroToAll

TensorFlow Basic Tutorial Labs
Jupyter Notebook
4,470
star
2

PyTorchZeroToAll

Simple PyTorch Tutorials Zero to ALL!
Python
3,759
star
3

word-rnn-tensorflow

Multi-layer Recurrent Neural Networks (LSTM, RNN) for word-level language models in Python using TensorFlow.
Python
1,305
star
4

deep_architecture_genealogy

Deep Learning Architecture Genealogy Project
Python
1,219
star
5

DeepLearningStars

Top Deep Learning Projects based on their Stars!
Python
384
star
6

effective_python_notebook

Jupyter Notebook
263
star
7

ReinforcementZeroToAll

Python
242
star
8

es-gpt

Python
206
star
9

KaggleZeroToAll

Kaggle problem solving
Jupyter Notebook
168
star
10

ml

Course Web page
HTML
141
star
11

kakao-gpt

124
star
12

GoogleCloudMLExamples

Python
71
star
13

line-gpt

40
star
14

book_writer

Python
38
star
15

smile_more

Check your face and make sure you smile using Google Vision API.
Python
37
star
16

PythonZeroToAll

Jupyter Notebook
30
star
17

digital-human

JavaScript
27
star
18

llama-up-data

26
star
19

FacebookSpamOut

Facebook (group) spam out
PHP
24
star
20

line-papago-bot

Simple Line/Kakao-Papago Translation Bot.
Python
24
star
21

gpt3-krtranslated-qa

20
star
22

gpt-py-review

Python
19
star
23

nsmlZeroToAll

Python
18
star
24

gpt3-python-doc-qa

16
star
25

chatgpt-askup-search-plugin

AskUp Search ChatGPT Plugin
Python
16
star
26

llm_gpu_cal

๐Ÿ”ฎ LLM GPU Calculator
Python
14
star
27

clova-up

Python
10
star
28

deep-facebook-commenter

9
star
29

DialogflowZeroToAll

Dialogflow Simple Tutorials
8
star
30

comp1021

comp1021 repository
6
star
31

assembly

Open assembly information
HTML
6
star
32

translation_coverage

Automatically check the rates between alpha VS other (unicode)
Python
6
star
33

FacebookGroupMemberPics

PHP
6
star
34

sagemaker-aihub

Jupyter Notebook
5
star
35

FacebookProfileOverlay

HTML
5
star
36

bible-friend

Kakai/Line bot for quick bible search
Python
5
star
37

PythonWithTurtle

Basic python programming with turtle graphics
5
star
38

askup_info

Python
4
star
39

gpt-plugin-bible-talk

Python
4
star
40

alexa-ask-facebook

Python
3
star
41

slack_diffusion

Python
3
star
42

mediapipe-facedetection

Python
2
star
43

codemirror-materialui-sveltekit

Svelte
1
star
44

faq_search

Python
1
star
45

askup-info

1
star
46

ask

1
star
47

info_masker

1
star
48

toy_fc

Python
1
star
49

solar-paralegal

LLMxLaw Hackathon
Python
1
star