Skip to content

Commit

Permalink
updated README and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hunkim committed Apr 23, 2016
1 parent a5f6c83 commit 5ac3fb4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 72 deletions.
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Wit-Facebook
Wit-Facebook Messenger Example
Wit-Facebook Messenger Example
## Initial Installation
Fork this repository and clone.

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

## Configuration
## 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.
Then, go to the setting in your wit app and get the token id.

![image](https://cloud.githubusercontent.com/assets/901975/14757067/58f03050-0922-11e6-813d-831df8614303.png)

Test the bot.js with your WIT_TOKEN, and make sure the bot is working.
```bash
$WIT_TOKEN=insert_token_here node bot
$WIT_TOKEN=insert_token_here node bot
```

You can type your text, and see bot's response.
Expand All @@ -41,7 +41,7 @@ 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
### Facebook App Creation

* Add a new app at https://developers.facebook.com/quickstarts/?platform=web. Name it and click "Create New Facebook App ID":

Expand All @@ -51,7 +51,6 @@ First you need to make a Facebook Page at https://www.facebook.com/pages/create/

![image](https://cloud.githubusercontent.com/assets/901975/14749960/ef969b94-08f4-11e6-9fa6-3294a47fcf4e.png)


### Facebook Messenger Setting

* From https://developers.facebook.com/apps/, select the created app:
Expand All @@ -66,7 +65,7 @@ First you need to make a Facebook Page at https://www.facebook.com/pages/create/

![image](https://cloud.githubusercontent.com/assets/901975/14757285/78e65248-0924-11e6-9ffb-e6226a7d434f.png)

### Launch Server in Heruku
### Launch Server in Heruku

* Run heroku create and push to heroku:

Expand All @@ -91,23 +90,25 @@ git push heroku master
* 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

* 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:

![image](https://cloud.githubusercontent.com/assets/901975/14750370/0d98de98-08f7-11e6-8c6b-85733dab4fb4.png)

* 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.
* 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".
* 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](https://cloud.githubusercontent.com/assets/901975/14750713/c64e4ee0-08f8-11e6-8745-2ebc746ae367.png)

* Then, you will see the green complete!
* Then, you will see the green complete!

![image](https://cloud.githubusercontent.com/assets/901975/14750734/e59c1016-08f8-11e6-9333-fbb7c92dd342.png)

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

![image](https://cloud.githubusercontent.com/assets/901975/14757285/78e65248-0924-11e6-9ffb-e6226a7d434f.png)

Expand All @@ -116,7 +117,7 @@ git push heroku master
```bash
curl -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=<PAGE_ACCESS_TOKEN>"
```
* You may see:
* You may see:
```bash
{"success":true}
```
Expand All @@ -127,18 +128,16 @@ curl -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=<P

![image](https://cloud.githubusercontent.com/assets/901975/14751164/2a485e2a-08fb-11e6-9a98-fd79bb0773f7.png)



## Testing
### Bot testing
```bash
$WIT_TOKEN=insert_token_here node bot
$WIT_TOKEN=insert_token_here node bot
```

### Server testing
First, run the server
```bash
$WIT_TOKEN=insert_token_here node index
$WIT_TOKEN=insert_token_here node index
```
In other shell, fire this command:
```bash
Expand All @@ -156,18 +155,14 @@ 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!".

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:
* https://github.com/wit-ai/node-wit
* https://github.com/jw84/messenger-bot-tutorial
* https://developers.facebook.com/docs/messenger-platform/quickstart

## Contribution
We welcome your comments and PRs!



## Contribution
We welcome your comments and PRs!
93 changes: 45 additions & 48 deletions README_KR.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# Wit-Facebook
Wit 봇 엔진과 Facebook 메신저 연동 한번에 해보기
Wit 봇 엔진과 Facebook 메신저 연동 한번에 해보기

## 기본 설치
먼저 포크 한다음 클론
먼저 이 프로젝트를 포크 한다음 클론 합니다. npm/node가 설치 되어 있다고 가정합니다. "nam install” 을 실행하여 필요한 node_module을 다운 받습니다.
```bash
git clone https://github.com/{forked}/Wit-Facebook.git
cd Wit-Facebook
npm install
```
```

## 설정
### Wit 만들기
## 설정
### Wit 만들기

우선 https://wit.ai/home 로 가서 엡을 하나 만듭니다. 여기 https://wit.ai/docs/quickstart 를 보시고 실제 만들이전 날씨 엡 예제를 보세요. https://wit.ai/sungkim/weather/stories.
우선 https://wit.ai/home 로 가서 엡을 만듭니다. https://wit.ai/docs/quickstart 를 보시고 실제 만들이전 날씨 엡 예제를 봅니다. https://wit.ai/sungkim/weather/stories.

만드신 엡의 설정페이지에 가셔서 중요한 토큰 아이디를 가져옵니다.
만든 Wit 엡의 설정페이지에 가서 토큰 아이디를 가져옵니다.

![image](https://cloud.githubusercontent.com/assets/901975/14757067/58f03050-0922-11e6-813d-831df8614303.png)

이 토큰 아이디를 이용해서 코컬에서 bot.js를 이용해서 잘 되는지 테스트 해봅니다. 본인의 Wit스토리를 바꾸면 bot.js를 같이 바꾸어 준다음 데스트.
이 토큰 아이디를 이용해서 local에서 bot.js를 이용해서 Wit엡이 잘 동작하는지 테스트 해봅니다. 본인의 Wit스토리를 바꾸면 bot.js를 같이 바꾸어 준다음 반복해서 test합니다.

```bash
$WIT_TOKEN=insert_token_here node bot
$WIT_TOKEN=insert_token_here node bot.js
```

봇에게 말을 걸면 답을 해줍니다.
아래와 같이 봇에게 말을 걸면 답을 해줍니다.

```bash
Bot testing mode.
Expand All @@ -40,19 +41,18 @@ I see it’s sunny in Seoul today! # bot
```

### Facebook 페이지 만들기
우선 https://www.facebook.com/pages/create/?ref_type=pages_browser 에서 페이지를 하나 만듭니다. 메신저 봇은 바로 이 페이지와 연결됩니다.
우선 https://www.facebook.com/pages/create/?ref_type=pages_browser 에서 페이지를 만듭니다. 메신저 봇은 바로 이 페이지와 연결됩니다.

### Facebook 엡 만들기
### Facebook 엡 만들기

* https://developers.facebook.com/quickstarts/?platform=web 에 가서 이름을 지정하고 "Create New Facebook App ID"을 눌러줍니다.
* https://developers.facebook.com/quickstarts/?platform=web 에 가서 이름을 지정하고 "Create New Facebook App ID”를 눌러줍니다.

![image](https://cloud.githubusercontent.com/assets/901975/14749905/b557bf80-08f4-11e6-8218-2dd8dc7d529c.png)

* 이메일, 분류, 그리고 웹페이지 URL(아무 URL)을 넣어 줍니다.
* 이메일, 분류, 그리고 웹페이지 URL(아무 URL)을 입력합니다.

![image](https://cloud.githubusercontent.com/assets/901975/14749960/ef969b94-08f4-11e6-9fa6-3294a47fcf4e.png)


### Facebook 메신저 설정

* https://developers.facebook.com/apps/에 가서 만들어 둔 엡을 선택합니다.
Expand All @@ -63,22 +63,22 @@ I see it’s sunny in Seoul today! # bot

![image](https://cloud.githubusercontent.com/assets/901975/14750051/6733be3e-08f5-11e6-9da7-a35eb2720298.png)

* 메신저를 어느 Facebook 페이지랑 연결 시킬 것인지 선택한 다음 Page Access Token을 가져옵니다.
* 메신저를 어느 Facebook 페이지랑 연결 시킬 것인지 선택한 다음 해당하는 Page Access Token을 가져옵니다.

![image](https://cloud.githubusercontent.com/assets/901975/14757285/78e65248-0924-11e6-9ffb-e6226a7d434f.png)

### 서버를 Heruku 에서 돌리기
heroku.com는 본인의 프로그램을 5개 까지 무료로 deploy 해주므로 이 서비스를 이용, 우리 봇 서버를 돌립니다. 자세한 설명은 heroku.com.
heroku.com는 본인의 프로그램을 5개 까지 무료로 deploy 해주므로 이 서비스를 이용하여 우리 봇 서버를 돌립니다. 자세한 heroic 사용법은 heroku.com 참조.

* 'heroku create' 명령을 실행한 다음 heroku로 푸쉬 합니다.
* 'heroku create' 명령을 실행한 다음 heroku로 push하여 deploy 합니다.

```bash
cd Wit-Facebook
heroku create
git push heroku master
```

* 더 쉬운 방법은 아래 Heroku버턴을 누르시면 쉽게 할수 있습니다.
* 더 쉬운 방법은 아래 Heroku 버턴을 누르시면 쉽게 deploy 할수 있습니다. (이 방법을 추천합니다.)

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

Expand All @@ -87,68 +87,69 @@ git push heroku master

![image](https://cloud.githubusercontent.com/assets/901975/14750245/627a5d20-08f6-11e6-9672-f19b3719eb2b.png)

* 설정후 Deploy 한다음 "Deploy to Heroku" 이 초록으로 된것을 확인한 다음 "View" 버턴을 눌러 서버로 갑니다.
* 설정후 Deploy 한다음 "Deploy to Heroku" 이 초록으로 된것을 확인한 다음 "View" 버턴을 눌러 서버를 연결해 봅니다.

![image](https://cloud.githubusercontent.com/assets/901975/14750332/d59fad46-08f6-11e6-9f24-16fff6b98898.png)

* If it is set correctly, you will see something like this from https://{yourspecificedname}.herokuapp.com/:
* 설정이 잘 되었으면 여러분의 서버 (https://{yourspecificedname}.herokuapp.com/) 에서 다음의 메시지를 보낼 것입니다.
"Only those who will risk going too far can possibly find out how far one can go." - T.S. Eliot"

* 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:
### Facebook Webhooks 설정
* 마지막 설정은 메신저 Webhooks을 설정하는 것입니다. https://developers.facebook.com/apps/가셔서 Facebook 엡을 선택하시고 messenger를 선택합니다. 여기에서 Webhooks을 선택해줍니다.

![image](https://cloud.githubusercontent.com/assets/901975/14750370/0d98de98-08f7-11e6-8c6b-85733dab4fb4.png)

* 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.
* "Setup Webhooks"을 하고 callback URL에 Heroku 엡 URL "/webhook"를 추가한 URL을 넣어 줍니다. 예를 들어 https://fbwitbot.herokuapp.com/webhook 을 callback URL에 넣어 줍니다.

* Type the Verify Token that you set in the Heruku app setting. If you haven't set, the default value is "just_do_it".
* 그런다음 지정한 Verify Token 을 입력합니다. 지정하지 않으셨다면 기본값은 "just_do_it" 입니다.

* Click all items in the Subscription Fields.
* Subscription Fields는 모든 항목을 체크합니다.

![image](https://cloud.githubusercontent.com/assets/901975/14750713/c64e4ee0-08f8-11e6-8745-2ebc746ae367.png)

* Then, you will see the green complete!
* 그럼, 초록색 complete 글씨가 보일것입니다!

![image](https://cloud.githubusercontent.com/assets/901975/14750734/e59c1016-08f8-11e6-9333-fbb7c92dd342.png)

* You may need to select the Facebook Page one more time and get the access token.
* 엡 메신저 설정에서 페이지를 한번더 선택해서 PAGE_ACCESS_TOKEN 을 가져옵니다.

![image](https://cloud.githubusercontent.com/assets/901975/14757285/78e65248-0924-11e6-9ffb-e6226a7d434f.png)

* You need to fire this command to activate your messanger.
* 다음 명령을 보내 페이지를 엡을 등록을 합니다.

```bash
curl -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=<PAGE_ACCESS_TOKEN>"
```
* You may see:
* You may see:
```bash
{"success":true}
```

* Finally, go to the Facebook page you created/selected, and talk to your bot. Enjoy!
* 모든 설정이 끝났습니다. Facebook 페이지로 가서 메시지를 보내봅니다. 여러분들이 설정한 봇이 답을 할것입니다.

![image](https://cloud.githubusercontent.com/assets/901975/14750786/20ddf0a4-08f9-11e6-9c9c-719d1020e5d8.png)

![image](https://cloud.githubusercontent.com/assets/901975/14751164/2a485e2a-08fb-11e6-9a98-fd79bb0773f7.png)



## Testing
### Bot testing
### 개별 봇 테스팅
아래 명령으로 봇의 기능을 테스트 할수 있습니다.
```bash
$WIT_TOKEN=insert_token_here node bot
$WIT_TOKEN=insert_token_here node bot
```

### Server testing
First, run the server
### 서버 테스트
우선 서버를 로컬에서 실행시킵니다.

```bash
$WIT_TOKEN=insert_token_here node index
$WIT_TOKEN=insert_token_here node index
```
In other shell, fire this command:
그런다음 다른 shell이나 창에서 아래 명령으로 가상 메시지를 보내 봅니다.
```bash
$curl -X POST -H "Content-Type: application/json" -d @test/msg.json http://localhost:8445/webhook
```

You will see something like this:
서버가 다음과 같이 응답하면 정상입니다.
```
I'm wating for you @8445
Expand All @@ -159,18 +160,14 @@ 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!".

USER_ID 관련 에러가 나는 것은 정상입니다. 그러나 봇의 응답이 예상한 응답인지 확인 하시면 됩니다. 서버나 봇을 프로그램을 수정후 deploy 하시기 전에 테스트 하시면 좋습니다.

## Credit
I reused soruce code and configuration from:
## 참고자료
아래 프로젝트의 코드와 설정을 재사용하거나 참고하였습니다:
* https://github.com/wit-ai/node-wit
* https://github.com/jw84/messenger-bot-tutorial
* https://developers.facebook.com/docs/messenger-platform/quickstart

## Contribution
We welcome your comments and PRs!



## 도움 요청
여러분들의 커멘트와 PR은 언제나 환영합니다.

0 comments on commit 5ac3fb4

Please sign in to comment.