Suche senden
Hochladen
챗봇 시작해보기
•
60 gefällt mir
•
21,726 views
성일 한
Folgen
ABCD 의 11월 세미나 자료입니다. :)
Weniger lesen
Mehr lesen
Software
Melden
Teilen
Melden
Teilen
1 von 71
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
Watson and Crick model
Watson and Crick model
Zoology Explorer
Pakistan – the problems and solutions regarding terrorism and 4thGW
Pakistan – the problems and solutions regarding terrorism and 4thGW
Zaid Hamid
Molecular Biology Revision-Part1
Molecular Biology Revision-Part1
Namrata Chhabra
Nucleic acid and its chemistry - DNA, RNA, DNA as genetic material
Nucleic acid and its chemistry - DNA, RNA, DNA as genetic material
Dhanuja Kumar
Nucleic acids
Nucleic acids
Dr. Nibedita Ayan
Matriks
Matriks
Fatimah Abdul Khalid
Poradnik m ii b
Poradnik m ii b
Grupa PTWP S.A.
Lecture on nucleic acid and proteins
Lecture on nucleic acid and proteins
Marilen Parungao
Empfohlen
Watson and Crick model
Watson and Crick model
Zoology Explorer
Pakistan – the problems and solutions regarding terrorism and 4thGW
Pakistan – the problems and solutions regarding terrorism and 4thGW
Zaid Hamid
Molecular Biology Revision-Part1
Molecular Biology Revision-Part1
Namrata Chhabra
Nucleic acid and its chemistry - DNA, RNA, DNA as genetic material
Nucleic acid and its chemistry - DNA, RNA, DNA as genetic material
Dhanuja Kumar
Nucleic acids
Nucleic acids
Dr. Nibedita Ayan
Matriks
Matriks
Fatimah Abdul Khalid
Poradnik m ii b
Poradnik m ii b
Grupa PTWP S.A.
Lecture on nucleic acid and proteins
Lecture on nucleic acid and proteins
Marilen Parungao
Structure and forms of dna&rna
Structure and forms of dna&rna
Rachana Eshwaran
Nota formula dan persamaan kimia
Nota formula dan persamaan kimia
Saonah Zabali
DNA CHEMISTRY
DNA CHEMISTRY
Shamim Akram
Kimia kertas 2
Kimia kertas 2
Nasran Syahiran
Terrorism in pakistan
Terrorism in pakistan
iamttak
Zia ul hak by faiz
Zia ul hak by faiz
Bahria University ,
Modul kimia pro x kssm 2022 FORM 4
Modul kimia pro x kssm 2022 FORM 4
Cikgu Marzuqi
Pak us relations by Dhuddy.Com
Pak us relations by Dhuddy.Com
dhuddybadsha
20170227 파이썬으로 챗봇_만들기
20170227 파이썬으로 챗봇_만들기
Kim Sungdong
챗봇 개발을 위한 네이버 랩스 api
챗봇 개발을 위한 네이버 랩스 api
NAVER D2
Developing Korean Chatbot 101
Developing Korean Chatbot 101
Jaemin Cho
Python 으로 Slackbot 개발하기
Python 으로 Slackbot 개발하기
성일 한
부동산 텔레그램봇 사내공유 @Tech
부동산 텔레그램봇 사내공유 @Tech
HoChul Shin
왓슨 컨버세이션으로 챗봇 만들기 ! WCS 활용법
왓슨 컨버세이션으로 챗봇 만들기 ! WCS 활용법
HyeonJeong Jo
한양대학교 스마트창작터 사업계획서_중고거래 구매대행 서비스 Buying_오세훈
한양대학교 스마트창작터 사업계획서_중고거래 구매대행 서비스 Buying_오세훈
세훈 오
사업계획서 알음알음 포스코기술투자
사업계획서 알음알음 포스코기술투자
Sangmo Kang
29th Meetup 실습 설명 및 실습 자료 링크
29th Meetup 실습 설명 및 실습 자료 링크
HyeonJeong Jo
[트래블챗] Ai기반 챗봇 커머스 플랫폼 사업계획서 20170213_f
[트래블챗] Ai기반 챗봇 커머스 플랫폼 사업계획서 20170213_f
Lee Hansub
채팅 소스부터 Https 주소까지
채팅 소스부터 Https 주소까지
Kenu, GwangNam Heo
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
기동 이
Node js[stg]onimusha 20140822
Node js[stg]onimusha 20140822
병헌 정
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4
성일 한
Weitere ähnliche Inhalte
Was ist angesagt?
Structure and forms of dna&rna
Structure and forms of dna&rna
Rachana Eshwaran
Nota formula dan persamaan kimia
Nota formula dan persamaan kimia
Saonah Zabali
DNA CHEMISTRY
DNA CHEMISTRY
Shamim Akram
Kimia kertas 2
Kimia kertas 2
Nasran Syahiran
Terrorism in pakistan
Terrorism in pakistan
iamttak
Zia ul hak by faiz
Zia ul hak by faiz
Bahria University ,
Modul kimia pro x kssm 2022 FORM 4
Modul kimia pro x kssm 2022 FORM 4
Cikgu Marzuqi
Pak us relations by Dhuddy.Com
Pak us relations by Dhuddy.Com
dhuddybadsha
Was ist angesagt?
(8)
Structure and forms of dna&rna
Structure and forms of dna&rna
Nota formula dan persamaan kimia
Nota formula dan persamaan kimia
DNA CHEMISTRY
DNA CHEMISTRY
Kimia kertas 2
Kimia kertas 2
Terrorism in pakistan
Terrorism in pakistan
Zia ul hak by faiz
Zia ul hak by faiz
Modul kimia pro x kssm 2022 FORM 4
Modul kimia pro x kssm 2022 FORM 4
Pak us relations by Dhuddy.Com
Pak us relations by Dhuddy.Com
Andere mochten auch
20170227 파이썬으로 챗봇_만들기
20170227 파이썬으로 챗봇_만들기
Kim Sungdong
챗봇 개발을 위한 네이버 랩스 api
챗봇 개발을 위한 네이버 랩스 api
NAVER D2
Developing Korean Chatbot 101
Developing Korean Chatbot 101
Jaemin Cho
Python 으로 Slackbot 개발하기
Python 으로 Slackbot 개발하기
성일 한
부동산 텔레그램봇 사내공유 @Tech
부동산 텔레그램봇 사내공유 @Tech
HoChul Shin
왓슨 컨버세이션으로 챗봇 만들기 ! WCS 활용법
왓슨 컨버세이션으로 챗봇 만들기 ! WCS 활용법
HyeonJeong Jo
한양대학교 스마트창작터 사업계획서_중고거래 구매대행 서비스 Buying_오세훈
한양대학교 스마트창작터 사업계획서_중고거래 구매대행 서비스 Buying_오세훈
세훈 오
사업계획서 알음알음 포스코기술투자
사업계획서 알음알음 포스코기술투자
Sangmo Kang
29th Meetup 실습 설명 및 실습 자료 링크
29th Meetup 실습 설명 및 실습 자료 링크
HyeonJeong Jo
[트래블챗] Ai기반 챗봇 커머스 플랫폼 사업계획서 20170213_f
[트래블챗] Ai기반 챗봇 커머스 플랫폼 사업계획서 20170213_f
Lee Hansub
Andere mochten auch
(10)
20170227 파이썬으로 챗봇_만들기
20170227 파이썬으로 챗봇_만들기
챗봇 개발을 위한 네이버 랩스 api
챗봇 개발을 위한 네이버 랩스 api
Developing Korean Chatbot 101
Developing Korean Chatbot 101
Python 으로 Slackbot 개발하기
Python 으로 Slackbot 개발하기
부동산 텔레그램봇 사내공유 @Tech
부동산 텔레그램봇 사내공유 @Tech
왓슨 컨버세이션으로 챗봇 만들기 ! WCS 활용법
왓슨 컨버세이션으로 챗봇 만들기 ! WCS 활용법
한양대학교 스마트창작터 사업계획서_중고거래 구매대행 서비스 Buying_오세훈
한양대학교 스마트창작터 사업계획서_중고거래 구매대행 서비스 Buying_오세훈
사업계획서 알음알음 포스코기술투자
사업계획서 알음알음 포스코기술투자
29th Meetup 실습 설명 및 실습 자료 링크
29th Meetup 실습 설명 및 실습 자료 링크
[트래블챗] Ai기반 챗봇 커머스 플랫폼 사업계획서 20170213_f
[트래블챗] Ai기반 챗봇 커머스 플랫폼 사업계획서 20170213_f
Ähnlich wie 챗봇 시작해보기
채팅 소스부터 Https 주소까지
채팅 소스부터 Https 주소까지
Kenu, GwangNam Heo
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
기동 이
Node js[stg]onimusha 20140822
Node js[stg]onimusha 20140822
병헌 정
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4
성일 한
Nodejs express
Nodejs express
Hyosung Jeon
FE로 취업 전에 알았으면 좋았을 것들
FE로 취업 전에 알았으면 좋았을 것들
Taegon Kim
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptx
wonyong hwang
Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발
Jay Park
진짜기초 Node.js
진짜기초 Node.js
Woo Jin Kim
조은 - AMP PWA 101 [WSConf.Seoul.2017. Vol.2]
조은 - AMP PWA 101 [WSConf.Seoul.2017. Vol.2]
WSConf.
One-day-codelab
One-day-codelab
WebFrameworks
Node.js and react
Node.js and react
HyungKuIm
Startup JavaScript 9 - Socket.IO 실시간 통신
Startup JavaScript 9 - Socket.IO 실시간 통신
Circulus
chatbot-seminar-1806
chatbot-seminar-1806
juneyoungdev
Do IoT Yourself! - 사물 간의 연결을 위한 Open API
Do IoT Yourself! - 사물 간의 연결을 위한 Open API
Hyunghun Cho
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
GDG Korea
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
John Kim
Node.js 심화과정
Node.js 심화과정
Seokyou (Kevin) Hong
캠프앱 개발 사례를 통해 본 하이브리드앱 어디까지 | Devon 2012
캠프앱 개발 사례를 통해 본 하이브리드앱 어디까지 | Devon 2012
Daum DNA
Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)
Sungjoon Yoon
Ähnlich wie 챗봇 시작해보기
(20)
채팅 소스부터 Https 주소까지
채팅 소스부터 Https 주소까지
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Node js[stg]onimusha 20140822
Node js[stg]onimusha 20140822
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4
Nodejs express
Nodejs express
FE로 취업 전에 알았으면 좋았을 것들
FE로 취업 전에 알았으면 좋았을 것들
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptx
Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발
진짜기초 Node.js
진짜기초 Node.js
조은 - AMP PWA 101 [WSConf.Seoul.2017. Vol.2]
조은 - AMP PWA 101 [WSConf.Seoul.2017. Vol.2]
One-day-codelab
One-day-codelab
Node.js and react
Node.js and react
Startup JavaScript 9 - Socket.IO 실시간 통신
Startup JavaScript 9 - Socket.IO 실시간 통신
chatbot-seminar-1806
chatbot-seminar-1806
Do IoT Yourself! - 사물 간의 연결을 위한 Open API
Do IoT Yourself! - 사물 간의 연결을 위한 Open API
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
Node.js 심화과정
Node.js 심화과정
캠프앱 개발 사례를 통해 본 하이브리드앱 어디까지 | Devon 2012
캠프앱 개발 사례를 통해 본 하이브리드앱 어디까지 | Devon 2012
Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)
Mehr von 성일 한
파이어베이스 스터디
파이어베이스 스터디
성일 한
Vuejs 시작하기
Vuejs 시작하기
성일 한
Electron 개발하기
Electron 개발하기
성일 한
2016 ABCD 소개
2016 ABCD 소개
성일 한
Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5
성일 한
Laravel 로 배우는 서버사이드 #4
Laravel 로 배우는 서버사이드 #4
성일 한
Laravel 로 배우는 서버사이드 #3
Laravel 로 배우는 서버사이드 #3
성일 한
Laravel 로 배우는 서버사이드 #2
Laravel 로 배우는 서버사이드 #2
성일 한
Laravel 로 배우는 서버사이드 #1
Laravel 로 배우는 서버사이드 #1
성일 한
인플루언서 마케팅 (INFLUENCER MARKETING)
인플루언서 마케팅 (INFLUENCER MARKETING)
성일 한
Ionic으로 모바일앱 만들기 #5
Ionic으로 모바일앱 만들기 #5
성일 한
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4
성일 한
Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3
성일 한
Ionic으로 모바일앱 만들기 #2
Ionic으로 모바일앱 만들기 #2
성일 한
Ionic으로 모바일앱 만들기 #1
Ionic으로 모바일앱 만들기 #1
성일 한
처음배우는 자바스크립트, 제이쿼리 #3
처음배우는 자바스크립트, 제이쿼리 #3
성일 한
처음배우는 자바스크립트, 제이쿼리 #2
처음배우는 자바스크립트, 제이쿼리 #2
성일 한
처음배우는 자바스크립트, 제이쿼리 #1
처음배우는 자바스크립트, 제이쿼리 #1
성일 한
CSS 선택자와 디버그
CSS 선택자와 디버그
성일 한
워드프레스 기초 (ABCD) #2
워드프레스 기초 (ABCD) #2
성일 한
Mehr von 성일 한
(20)
파이어베이스 스터디
파이어베이스 스터디
Vuejs 시작하기
Vuejs 시작하기
Electron 개발하기
Electron 개발하기
2016 ABCD 소개
2016 ABCD 소개
Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #4
Laravel 로 배우는 서버사이드 #4
Laravel 로 배우는 서버사이드 #3
Laravel 로 배우는 서버사이드 #3
Laravel 로 배우는 서버사이드 #2
Laravel 로 배우는 서버사이드 #2
Laravel 로 배우는 서버사이드 #1
Laravel 로 배우는 서버사이드 #1
인플루언서 마케팅 (INFLUENCER MARKETING)
인플루언서 마케팅 (INFLUENCER MARKETING)
Ionic으로 모바일앱 만들기 #5
Ionic으로 모바일앱 만들기 #5
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #2
Ionic으로 모바일앱 만들기 #2
Ionic으로 모바일앱 만들기 #1
Ionic으로 모바일앱 만들기 #1
처음배우는 자바스크립트, 제이쿼리 #3
처음배우는 자바스크립트, 제이쿼리 #3
처음배우는 자바스크립트, 제이쿼리 #2
처음배우는 자바스크립트, 제이쿼리 #2
처음배우는 자바스크립트, 제이쿼리 #1
처음배우는 자바스크립트, 제이쿼리 #1
CSS 선택자와 디버그
CSS 선택자와 디버그
워드프레스 기초 (ABCD) #2
워드프레스 기초 (ABCD) #2
챗봇 시작해보기
1.
챗봇 시작해보기 파이썬과 노드로
만들어 보는 챗봇 (Slack, facebook..) ABCD, 한성일
2.
0. 챗봇이란?
3.
챗봇이란? 고객의 요청을 대신
응답해주는 채팅로봇 인공지능 빅데이터 자연어처리 프로그래밍 나이가 어떻게 되 시나요? 텍스트 음성 … 묻지 마세요.. 응답요청 Chatbot 머신러닝
4.
챗봇 예 심심이 페이스북
챗봇
5.
어디에 쓸까요? 가장 쉽게
떠오르는 곳은 콜 센터입니다.
6.
또 어디가 있을까요? 물건주문,
호텔예약, 비서…
7.
생각보다 간단할지 모릅니다.
8.
1. 챗봇 플로우
9.
챗봇 프레임웍 http://kitt.ai/ https://dev.botframework.com/
10.
챗봇 플랫폼 라인 슬렉 텔레그램
페이스북
11.
일반적인 챗봇 플로우 http://www.lds.com/coepost/enabling-a-smart-user-experience-using-chatbots/
12.
슬랙과 페이스북 API
를 이용해서 챗봇을 만들어보겠습니다. 간단한..
13.
2. 파이썬으로 슬렉챗봇
만들기
14.
선작업 1. 파이썬 설치 https://realpython.com/blog/python/getting-started-with-the-slack-api-using-python-and-flask/ 참고 2.
슬랙 커뮤니티 생성
15.
VIRTUAL ENV 설정 $
mkdir abcd-python-slack-bot $ virtualenv venv $ source venv/bin/activate (venv)$ pip install slackclient==1.0.0
16.
토큰생성 https://api.slack.com/web
17.
토큰생성 https://api.slack.com/docs/oauth-test-tokens
18.
토큰을 환경 변수로
지정 (venv)$ export SLACK_TOKEN=‘생성된 토큰'
19.
ngrok 을 이용
외부 오픈 SSL 주소 생성 https://ngrok.com/download (venv)$ ./ngrok http 5000 로컬 서버를 SSL 로 외부 오픈..
20.
WEBHOOK https://api.slack.com/outgoing-webhooks
21.
WEBHOOK https://abcds.slack.com/apps/new/A0F7VRG6Q-outgoing-webhooks
22.
INTEGRATION SETTINGS https://abcds.slack.com/services/B37GEBQBZ?added=1 ngrok 으로
생성된 주소 + /webhook 사용될 채널 웹훅 토큰
23.
WEBHOOK (venv)$ export SLACK_WEBHOOK_SECRET=‘생성된
웹훅 토큰'
24.
FLASK 설치 (venv)$ pip
install flask
25.
RECEIVE.PY # -*- coding:
utf-8 -*- import os from flask import Flask, request, Response from slackclient import SlackClient app = Flask(__name__) SLACK_WEBHOOK_SECRET = os.environ.get('SLACK_WEBHOOK_SECRET') SLACK_TOKEN = os.environ.get('SLACK_TOKEN', None) slack_client = SlackClient(SLACK_TOKEN) def send_message(channel_id, message): slack_client.api_call( "chat.postMessage", channel=channel_id, text=message, username='abcdBot', icon_emoji=':monkey_face:' ) @app.route('/webhook', methods=['POST']) def inbound(): print("get " + request.form.get('token')) print("username " + request.form.get('user_name')) username = request.form.get('user_name') if request.form.get('token') == SLACK_WEBHOOK_SECRET and username != 'slackbot': channel_name = request.form.get('channel_name') channel_id = request.form.get('channel_id') username = request.form.get('user_name') text = request.form.get('text') inbound_message = username + " in " + channel_name + " says: " + text send_message(channel_id, unicode("따라쟁이 ", 'utf-8') + " " + text) print(inbound_message) return Response(), 200 @app.route('/', methods=['GET']) def test(): return Response('It works!') if __name__ == "__main__": app.run(debug=True) receive.py
26.
RECEIVE.PY (venv)$ python receive.py
27.
구동화면
28.
실제 서버를 설정해서
포팅해봅시다.
29.
3. 노드로 페이스북
챗봇 만들기 (HEROKU)
30.
선작업 http://x-team.com/2016/04/how-to-get-started-with-facebook-messenger-bots/ nodejs 설치 참고 https://nodejs.org/ko/download/
31.
선작업 heroku 가입이 되어있어야
함 https://heroku.com/ https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up heroku CLI 가 설치되어있어야 함
32.
프로젝트 생성 $ mkdir
abcd-node-bot $ cd abcd-node-bot/ $ npm init $ npm install express body-parser request --save { "name": "testbot", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1", "start": "node index.js" }, "author": "", "license": "ISC", "dependencies": { "body-parser": "^1.15.2", "express": "^4.14.0", "request": "^2.79.0" } }
33.
express 설치 $ npm
install express body-parser request --save
34.
INDEX.JS 생성 index.js 생성 var
express = require('express'); var bodyParser = require('body-parser'); var request = require('request'); var app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use(bodyParser.json()); app.listen((process.env.PORT || 3000)); // Server frontpage app.get('/', function (req, res) { res.send('잘돈다.'); }); // Facebook Webhook app.get('/webhook', function (req, res) { console.log(req.query['hub.verify_token']); if (req.query['hub.verify_token'] === 'abcd_verify_token') { // webhook 설정에 입력된 토큰 res.send(req.query['hub.challenge']); } else { res.send('Invalid verify token'); } }); node index.js
35.
HEROKU 생성 $ heroku
login
36.
로컬 GIT 설정 $
git init $ heroku create $ git add . $ git commit -m ‘ABCD 노드 봇 첫번째 커밋' $ git push heroku master .gitignore node_modules
37.
작동확인 https://warm-spire-76279.herokuapp.com/
38.
페이스북 페이지 만들기 https://www.facebook.com/pages/create/
39.
페이지 생성 완료
40.
앱생성 https://developers.facebook.com/quickstarts/ 기본설정으로 앱생성
41.
제품추가
42.
토큰생성
43.
토큰생성
44.
WEB HOOK 설정 https://developers.facebook.com/ heroku
경로
45.
WEB HOOK 설정 페이지를
선택해주세요!
46.
WEBHOOK 설정
47.
PAGE_ACCESS_TOKEN 설정 PAGE_ACCESS_TOKEN
48.
토큰 유효성 확인 https://warm-spire-76279.herokuapp.com/webhook? hub.verify_token=abcd_verify_token
49.
따라하기 봇 테스트
50.
KITTEN https://placekitten.com/ kitten 300 200
51.
따라하기 & 키튼
봇 소스 1 var express = require('express'); var bodyParser = require('body-parser'); var request = require('request'); var app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use(bodyParser.json()); app.listen((process.env.PORT || 3000)); // Server frontpage app.get('/', function (req, res) { res.send('This is TestBot Server'); }); // Facebook Webhook app.get('/webhook', function (req, res) { console.log(req.query['hub.verify_token']); if (req.query['hub.verify_token'] === 'abcd_verify_token') { // webhook 설정에 입력된 토큰 res.send(req.query['hub.challenge']); } else { res.send('Invalid verify token'); } });
52.
따라하기 & 키튼
봇 소스 2 // handler receiving messages app.post('/webhook', function (req, res) { var events = req.body.entry[0].messaging; for (i = 0; i < events.length; i++) { var event = events[i]; if (event.message && event.message.text) { if (!kittenMessage(event.sender.id, event.message.text)) { sendMessage(event.sender.id, {text: event.message.text}); } } else if (event.postback) { console.log("Postback received: " + JSON.stringify(event.postback)); } } res.sendStatus(200); }); // generic function sending messages function sendMessage(recipientId, message) { request({ url: 'https://graph.facebook.com/v2.6/me/messages', qs: {access_token: process.env.PAGE_ACCESS_TOKEN}, method: 'POST', json: { recipient: {id: recipientId}, message: message, } }, function(error, response, body) { if (error) { console.log('Error sending message: ', error); } else if (response.body.error) { console.log('Error: ', response.body.error); } }); };
53.
따라하기 & 키튼
봇 소스 3 // send rich message with kitten function kittenMessage(recipientId, text) { text = text || ""; var values = text.split(' '); if (values.length === 3 && values[0] === 'kitten') { if (Number(values[1]) > 0 && Number(values[2]) > 0) { var imageUrl = "https://placekitten.com/" + Number(values[1]) + "/" + Number(values[2]); message = { "attachment": { "type": "template", "payload": { "template_type": "generic", "elements": [{ "title": "Kitten", "subtitle": "Cute kitten picture", "image_url": imageUrl , "buttons": [{ "type": "web_url", "url": imageUrl, "title": "Show kitten" }, { "type": "postback", "title": "I like this", "payload": "User " + recipientId + " likes kitten " + imageUrl, }] }] } } }; sendMessage(recipientId, message); return true; } } return false; };
54.
4. 조금 더해보기
55.
더하기봇
56.
더하기 봇 소스
#1 var express = require('express'); var bodyParser = require('body-parser'); var request = require('request'); var app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use(bodyParser.json()); app.listen((process.env.PORT || 3000)); // Server frontpage app.get('/', function (req, res) { res.send('This is TestBot Server'); }); app.get('/forecast', function (req, res) { forecast.get([35.9335, 139.6181], function(err, weather) { if(err) return console.dir(err); console.dir(weather); console.dir(weather.latitude); console.log("weather.latitude " + weather.latitude); console.log("오늘 " + weather.timezone + "의 날씨는 " + weather.currently.summary + "입니다. "); }); res.send('forecast'); });
57.
더하기 봇 소스
#2 // Facebook Webhook app.get('/webhook', function (req, res) { if (req.query['hub.verify_token'] === 'abcd_verify_token') { res.send(req.query['hub.challenge']); } else { res.send('Invalid verify token'); } }); // handler receiving messages app.post('/webhook', function (req, res) { var events = req.body.entry[0].messaging; for (i = 0; i < events.length; i++) { var event = events[i]; if (event.message && event.message.text) { addMessage(event.sender.id, event.message.text); } } res.sendStatus(200); });
58.
더하기 봇 소스
#3 // generic function sending messages function sendMessage(recipientId, message) { request({ url: 'https://graph.facebook.com/v2.6/me/messages', qs: {access_token: process.env.PAGE_ACCESS_TOKEN}, method: 'POST', json: { recipient: {id: recipientId}, message: message, } }, function(error, response, body) { if (error) { console.log('Error sending message: ', error); } else if (response.body.error) { console.log('Error: ', response.body.error); } }); }; function addMessage(recipientId, text) { text = text || ""; var values = text.split(' '); if (values.length === 3 && values[0] === 'add') { if (Number(values[1]) > 0 && Number(values[2]) > 0) { addText = values[1] + " + " + values[2] + " = " + (Number(values[1]) + Number(values[2])); message = {text: addText}; sendMessage(recipientId, message); } } };
59.
FORECAST 설치 $ npm
install --save forecast
60.
날씨봇 https://darksky.net/dev/
61.
FORECAST KEY
62.
날씨앱 테스트
63.
날씨 봇 소스
#1 var express = require('express'); var bodyParser = require('body-parser'); var request = require('request'); var app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use(bodyParser.json()); app.listen((process.env.PORT || 3000)); var Forecast = require('forecast'); // Initialize var forecast = new Forecast({ service: 'darksky', key: ‘your-api-key‘, units: 'celcius', cache: true, // Cache API requests ttl: { minutes: 27, seconds: 45 } });
64.
날씨 봇 소스
#2 // Server frontpage app.get('/', function (req, res) { res.send('This is TestBot Server'); }); app.get('/forecast', function (req, res) { forecast.get([35.9335, 139.6181], function(err, weather) { if(err) return console.dir(err); console.dir(weather); }); res.send('forecast'); }); // Facebook Webhook app.get('/webhook', function (req, res) { if (req.query['hub.verify_token'] === 'abcd_verify_token') { res.send(req.query['hub.challenge']); } else { res.send('Invalid verify token'); } });
65.
날씨 봇 소스
#3 // handler receiving messages app.post('/webhook', function (req, res) { var events = req.body.entry[0].messaging; for (i = 0; i < events.length; i++) { var event = events[i]; if (event.message && event.message.text) { weatherMessage(event.sender.id, event.message.text); } } res.sendStatus(200); }); // generic function sending messages function sendMessage(recipientId, message) { request({ url: 'https://graph.facebook.com/v2.6/me/messages', qs: {access_token: process.env.PAGE_ACCESS_TOKEN}, method: 'POST', json: { recipient: {id: recipientId}, message: message, } }, function(error, response, body) { if (error) { console.log('Error sending message: ', error); } else if (response.body.error) { console.log('Error: ', response.body.error); } }); };
66.
날씨 봇 소스
#4 function weatherMessage(recipientId, text){ text = text || ""; var values = text.split(' '); if (values[0] === '날씨') { forecast.get([35.9335, 139.6181], function(err, weather) { console.log(weather); weatherText = "오늘 " + weather.timezone + "의 날씨는 " + weather.currently.summary + "입니다. "; message = {text: weatherText}; sendMessage(recipientId, message); }); } }
67.
더하기와 날씨봇을 확장해
보세요.
68.
또 어떤걸 해보고
싶으신가요? 머신러닝, 자연어처리, 음성인식…
69.
파이썬 https://github.com/snowkiwi/slack-python-bot-tutorial 소스는 이곳을 참고하세요. 노드 https://github.com/snowkiwi/facebook-node-bot
70.
Q & A
71.
수고하셨습니다. :) ABCD http://abcds.kr https://www.facebook.com/groups/562787713823026/ 한성일 https://www.facebook.com/jamie.han.16 iheart79@gmail.com
Jetzt herunterladen