김성욱

Update test_code

Showing 1 changed file with 15 additions and 48 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;
44 - if (question === 'test') {
45 const responseBody = { 17 const responseBody = {
46 version: "2.0", 18 version: "2.0",
47 template: { 19 template: {
48 outputs: [ 20 outputs: [
49 { 21 {
50 simpleText: { 22 simpleText: {
51 - text: "text..." 23 + text: "MBTI 검사 챗봇입니다!"
52 - }
53 } 24 }
54 - ],
55 - quickReplies: [
56 - {
57 - label: 'go main',
58 - action: 'message',
59 - messageText: 'go main'
60 } 25 }
61 ] 26 ]
62 } 27 }
63 }; 28 };
29 +
64 res.status(200).send(responseBody); 30 res.status(200).send(responseBody);
65 - } 31 +});
66 -})
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
......