Skip to content

Node API 설정

Yun edited this page Feb 17, 2017 · 1 revision

Node keyboard API

router.get('/keyboard', (req, res) => {
  const menu = {
      type: 'buttons',
      buttons: ["메뉴2", "메뉴2", "메뉴3"]
  };

  res.set({
      'content-type': 'application/json'
  }).send(JSON.stringify(menu));
});

Response

{
  "type": "buttons",
  "buttons": [
    "메뉴1",
    "메뉴2",
    "메뉴3"
  ]
}

Node Message API

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));
});

Response

{
  "message": {
    "text": '응답 메세지...'
  },
  "keyboard": {
    "type": "buttons",
    "buttons": [
      "메뉴1",
      "메뉴2",
      "메뉴3"
    ]
  }
}

Node friend API

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}));
});

Node chat_room API

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}));
});