1 / 17

kakao bot

kakao bot

kwanlae
Télécharger la présentation

kakao bot

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 카카오봇 15분만에 만들기 슬랙봇을 만들었다면... voidopennet@gmail.com

  2. • 몸을 만들자. • 정신을 만들자. • 몸을 꾸미자. • 지능은 그대로 • https://speakerdeck.com/kwanlae/slack-bot-in-30- minutes “지능을 만들자” 참고하세요.

  3. 몸을 만들자.

  4. • 카카오톡 옐로아이디가 있어야 합니다. • http://yellowid.kakao.com 에 접속하셔 서 옐로아이디를 만들어주세요.(발급 받 기까지 며칠이 걸릴 수도 있습니다.) • 자동응답 API 를 이용하여 봇을 만듭니다. • 자동응답 API 관련 문서는 https:// github.com/plusfriend/auto_reply 를 참 고하시면 됩니다.

  5. 몸을 만들었습니다.

  6. 정신을 만들자.

  7. • 다음을 입력합니다. $ touch kakao.js $ npm install body-parser express request --save

  8. • 선호하는 IDE 를 열고, package.json 파 일의 scripts 를 다음처럼 수정합니다. { … "scripts": { "slack": "node bot.js", "kakao": "node kakao.js" }, … }

  9. • kakao.js 파일에 다음을 입력합니다. https://github.com/kwanlae/slackbot30Minutes/blob/master/kakao.js const bodyParser = require('body-parser'); const express = require('express'); const request = require('request'); const app = express(); app.set('port', (process.env.PORT || 9090)); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: false})); app.get('/keyboard', (req, res) => { console.log(req.headers); }); res.json({type: 'text'}); const QUERIES = { } '안녕': '안녕, 난 봇이야.' const ACTIONS = { plus: (result) => { const {x, y} = result.parameters; const sum = Number(x) + Number(y); }, return `${sum} 일거야.`; } 'input.unknown': (result) => { } return result.fulfillment.speech; app.post('/message', (req, res) => { const response = (text) => { } return res.json({ }); message: {text: text}, keyboard: {type: 'text'} const query = req.body.content; if (QUERIES[query]) { } return response(QUERIES[query]); const options = { } url: 'https://api.api.ai/v1/query?v=20150910', method: 'POST', 'headers': { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': `Bearer ${process.env.APIAI}` }, json: { query: query, lang: 'en', sessionId: new Date().getTime() } request(options, (err, resp, body) => { console.log(body); const {result, result: {action}} = body; const text = ACTIONS[action](result); }); }); response(text); app.listen(app.get('port'), () => { }); console.log(`app listening on port ${app.get('port')}`);

  10. • 터미널 창에서 다음을 입력합니다. $ APIAI=... npm run kakao • ... 에는 api.ai token 을 넣어야 합니다.

  11. 정신을 만들었습니다.

  12. 몸을 꾸미자.

  13. • 지금까지의 모든 코드를 외부 hosting server 에 deploy 하거나, • ngrok 을 이용하여 localhost 를 외부(여 기서는 kakao 서버) 에서 접속가능하도록 터널링 해 둡니다. • 터널링 방법은, • 웹브라우저창에 http://ngrok.com 를 입력한 후 나오는 안내에 따라 ngrok 파 일을 다운로드 후 설치합니다. • 터미널을 열고, 다음을 입력합니다. $ ngrok http 9090 • https://....ngrok.io 주소를 복사합니다.

  14. • 카카오톡 옐로우페이지를 접속 / 로그인 후 [자동응답 > 자동응답 API] 메뉴의 “정 보수정” 버튼을 클릭하여 앱 URL 아래 input box 에 복사한 https://... 주소를 붙여 넣습니다. • [저장] 버튼을 클릭합니다.

  15. • [API TEST] 버튼을 클릭하여, Required* 항목이 200 OK 가 되는지 확인합니다. • Optional 항목은 코딩하지 않았기에 404 Not Found 로 나오는 것이 맞습니다. :)

  16. • 슬랙봇과 같은 질문을 던져서 카카오 봇도 같은 답변을 주는지 확인합니다.

  17. 몸 꾸미기와 테스트를 했습니다.

More Related