Showing
1 changed file
with
26 additions
and
59 deletions
1 | const express = require('express'); | 1 | const express = require('express'); |
2 | const app = express(); | 2 | const app = express(); |
3 | +const logger = require('morgan'); | ||
3 | const bodyParser = require('body-parser'); | 4 | const bodyParser = require('body-parser'); |
4 | 5 | ||
5 | -app.use(bodyParser.urlencoded({extended: false})); | 6 | +const apiRouter = express.Router(); |
6 | -app.use(bodyParse.json()); | ||
7 | 7 | ||
8 | -app.post('/api/sayHello', (req, res) => { | 8 | +app.use(logger('dev', {})); |
9 | - const responseBody = { //skill response | 9 | +app.use(bodyParser.json()); |
10 | - version: "2.0", //version 필수 | 10 | +app.use(bodyParser.urlencoded({ |
11 | - template: { // template 필수 | 11 | + extended: true |
12 | - outputs: [ | 12 | +})); |
13 | - { | ||
14 | - simpleText: { | ||
15 | - text: "hello I'm Ryan" | ||
16 | - } | ||
17 | - } | ||
18 | - ] | ||
19 | - } | ||
20 | - }; | ||
21 | - res.status(200).send(responseBody); | ||
22 | -}); | ||
23 | 13 | ||
24 | -app.post('/api/showHello', (req, res) => { | 14 | +app.use('/api', apiRouter); |
25 | - console.log(req.body); | ||
26 | - const responseBody = { | ||
27 | - version: "2.0", | ||
28 | - template: { | ||
29 | - outputs: [ | ||
30 | - { | ||
31 | - simpleImage: { | ||
32 | - imageUrl: "https://t1.daumcdn.net/friends/prod/category/M001_friends_ryan2.jpg", | ||
33 | - altText: "hello I'm Ryan" | ||
34 | - } | ||
35 | - } | ||
36 | - ] | ||
37 | - } | ||
38 | - }; | ||
39 | - res.status(200).send(responseBody); | ||
40 | -}); | ||
41 | 15 | ||
42 | -app.post('/message', (req, res) => { | 16 | +apiRouter.post('/sayHello', function(req, res) { |
43 | - const question = req.body.userRequest.utterance; | 17 | + const responseBody = { |
44 | - if (question === 'test') { | 18 | + version: "2.0", |
45 | - const responseBody = { | 19 | + template: { |
46 | - version: "2.0", | 20 | + outputs: [ |
47 | - template: { | 21 | + { |
48 | - outputs: [ | 22 | + simpleText: { |
49 | - { | 23 | + text: "MBTI 검사 챗봇입니다!" |
50 | - simpleText: { | 24 | + } |
51 | - text: "text..." | 25 | + } |
52 | - } | 26 | + ] |
53 | - } | ||
54 | - ], | ||
55 | - quickReplies: [ | ||
56 | - { | ||
57 | - label: 'go main', | ||
58 | - action: 'message', | ||
59 | - messageText: 'go main' | ||
60 | - } | ||
61 | - ] | ||
62 | - } | ||
63 | - }; | ||
64 | - res.status(200).send(responseBody); | ||
65 | } | 27 | } |
66 | -}) | 28 | + }; |
29 | + | ||
30 | + res.status(200).send(responseBody); | ||
31 | +}); | ||
67 | 32 | ||
68 | -var server = app.listen(3000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
33 | +app.listen((process.env.PORT || 3000), function() { | ||
34 | + console.log('Example skill server listening on port 3000!'); | ||
35 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment