티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
    console.log("req.body: " + req.body); // debug 
 
    let actions = req.body.queryResult.action; // action name get
 
    // REF: https://dialogflow.com/docs/fulfillment#sample_response_from_the_service
    // Response body
    function jsonResponse(text) {
 
        let json = {
            "fulfillmentText""This is a text response",
            "fulfillmentMessages": [
  ],
            "source""example.com",
            "payload": {
                "google": {
                    "expectUserResponse"true,
                    "richResponse": {
                        "items": [
                            {
                                "simpleResponse": {
                                    "textToSpeech": text
                                }
          }
        ]
                    }
                }
            }
        };
        return json
    }
 
    //Switch
    //It is use action name. 
    let insertText = ''// text make.
    switch (actions) {
        case "input.welcome":
            console.log("input.welcome");
            insertText = "Welcome action";
            
            // 1. insert text in jsonResponse() 
            // 2. it return json field.
            // 3. use it.
            res.send(jsonResponse(insertText)); // json send 
            break;
        default:
            console.log("ETC: default");
            insertText = "another default action";
            res.send(jsonResponse(insertText)); // json send 
            break;
    }
 
 
cs


프로그래머러 들은 이상한 사람들이 많아서 api가 아닌 json raw로 보내야 할때가 있다.

다음과 같이 코드를 쓰면 return이 가능하다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함