전체소스는 GitHub branch develop-base에서 확인할 수 있습니다.
해당 프로필은 하번 설정하면 변경이 불가능합니다. 이 작업이 완료되면 2 ~ 3일 이후에 옐로우아이디가 발급됩니다. 발급되기 전까지 Node API 서버를 구성합니다. 자세한 설명은 아래에 있습니다.
API형 자동읍답 설정하기 선택
앱 등록 절차를 진행합니다.
앱등록시 반드시 keyboard API가 동작해야합니다. 아래의 노드 서버 설정을 완료하고 API TEST를 진행합니다.
출저 : 카카오톡 플러스친구/옐로아이디 API v. 2.0 개요
12345678910
router.get('/keyboard', (req, res) => { const menu = { type: 'buttons', buttons: ["메뉴1", "메뉴2", "메뉴3"] }; res.set({ 'content-type': 'application/json' }).send(JSON.stringify(menu));});
12345678
{ "type": "buttons", "buttons": [ "메뉴1", "메뉴2", "메뉴3" ]}
1234567891011121314151617181920212223
router.post('/message', (req, res) => { const _obj = { user_key: req.body.user_key, type: req.body.type, content: req.body.content }; let massage = { "message": { "text": '응답 메세지...' }, "keyboard": { "type": "buttons", "buttons": [ "메뉴1", "메뉴2", "메뉴3" ] } }; res.set({ 'content-type': 'application/json' }).send(JSON.stringify(massage));});
let massage ={…}에 따라서 메세지 형태가 결정됩니다
let massage ={…}
12345678910111213
{ "message": { "text": "메뉴1를 선택했습니다." }, "keyboard": { "type": "buttons", "buttons": [ "메뉴1", "메뉴2", "메뉴3", ] }}
12345678910111213141516171819
{ "message": { "text": "메뉴2를 선택했습니다.", "message_button": { "label": "라벨입니다.", "url": "https://cheese10yun.github.io/" } }, "keyboard": { "type": "buttons", "buttons": [ "메뉴1", "메뉴2", "메뉴3", "메뉴4", "메뉴5" ] }}
12345678910111213141516171819202122
{ "message": { "text": "메뉴3를 선택했습니다.", "photo": { "url": "http://i.imgur.com/tvuH0ZJ.png", "width": 640, "height": 480 }, "message_button": { "label": "라벨입니다", "url": "https://cheese10yun.github.io/" } }, "keyboard": { "type": "buttons", "buttons": [ "메뉴1", "메뉴2", "메뉴3", ] }}
라벨을 터치하면 등록된 URL 주소로 이동합니다.
1234567891011121314151617
router.post('/friend', (req, res) => { const user_key = req.body.user_key; console.log(`${user_key}님이 쳇팅방에 참가했습니다.`); res.set({ 'content-type': 'application/json' }).send(JSON.stringify({success:true}));});router.delete('/friend', (req, res) => { const user_key = req.body.user_key; console.log(`${user_key}님이 쳇팅방을 차단했습니다.`); res.set({ 'content-type': 'application/json' }).send(JSON.stringify({success:true}));});
router.delete('/chat_room/:user_key', (req, res) => { const user_key = req.params.user_key; console.log(`${user_key}님이 쳇팅방에서 나갔습니다.`); res.set({ 'content-type': 'application/json' }).send(JSON.stringify({success:true}));});
나머지 API들은 간단하게 작성합니다.
학교 식단 및 통학 버스 알림 봇을 만들다가 기본 구조를 갖는 소스코드를 올리는 것도 좋을 거 같아서 기존 프로젝트에서 불필요 소스코드를 제거하고 올린 거라 좀 어색한 부분이 있네요. 비슷한 프로젝트를 진행하실 분들은 다른 master branch를 참조하세요.
출처 : https://cheese10yun.github.io/kakao-bot-node/