Extra Form
PHP PHP 7.2
CMS XpressEngine

curl 요청에 성공했는데, 이걸 google app script 로 변환을 하지 못하고 있습니다.

 

curl -X POST "https://api.channel.io/open/v3/user-chats/5f726xxxxxxxxxxx/messages?botName=%EA%B0%9C%EB%B0%9C%ED%97%A4%EC%95%84%EB%A6%BC" -H "accept: application/json" -H "Content-Type: application/json" -H "x-access-key: 5f72xxxxxxxxxx" -H "x-access-secret: 342b0xxxx" -d " { \"chatKey\": \"userChat-5f7264x\", \"id\": \"5f729xxxxxxxxxxxxxxxxxxxxxxx\", \"channelId\": \"33086\", \"chatType\": \"userChat\", \"chatId\": \"5f7264xxxxxxxxxx\", \"personType\": \"manager\", \"personId\": \"68813\", \"requestId\": \"4dcb5dxxxxxxxxxx\", \"createdAt\": 1601xxxxxxxxxx, \"version\": 1, \"blocks\": [ { \"type\": \"text\", \"value\": \"ㅎㅎ\" } ], \"plainText\": \"ㅎㅎ\" },"

 

이건 성공

 

그런데,

 

function test3() {

 

  var discordUrl = "https://api.channel.io/open/v3/user-chats/5f72645400d9e834ea42/messages?botName=개발헤아림";

 

  var params = {

    'method': 'POST',

    headers: {

 

      'accept': 'application/json',

      'ContentType': 'application/json',

      'x-access-key': '5f72651xxxxxxxxxx',

      'x-access-secret': '342b0f6dfxxxxxxxxxx',

    },

 

    "chatKey": "userChat-5f72xxxxxxxxxx",

    "id": "5f729323xxxxxxxxxx",

    "channelId": "33086",

    "chatType": "userChat",

    "chatId": "5f72645xxxxxxxxxx",

    "personType": "manager",

    "personId": "68813",

    "requestId": "4dxxxxxxxxxx",

    "createdAt": 1601xxxxxxxxxx,

    "version": 1,

    "blocks": [{

      "type": "text",

      "value": "Hello World"

    }],

    "plainText": "Hello World"

  };

  var response = UrlFetchApp.fetch(discordUrl, params);

 

  var text = response.getContentText();

  Browser.msgBox('테스트', text, Browser.Buttons.YES_NO_CANCEL);

 

  Logger.log(response.getContentText());

}

 

 

요렇게 변환한건 에러가 납니다.

 

따로 에러코드가 뜨지 않고, 뭔가 POST 명령에 이상이 있는 듯 정상 값이 리턴되지 않습니다.

 

고수님들의 많은 가르침 부탁드립니다.

 

 

 

  • ?
    ㅎㅎ 성공했습니다. 자문자답합니다~!


    function test3(){
    var message = "Hello World!";
    var discordUrl = "https://api.channel.io/open/v3/user-chats/5f7264/messages?botName=%EA%B0%9C%EB%B0%9C%ED%97%A4%EC%95%84%EB%A6%BC";
    var payload1 = {
    "chatKey": "userChat-5f72645",
    "id": "5f72932",
    "channelId": "386",
    "chatType": "userChat",
    "chatId": "5f726434ea42",
    "personType": "manager",
    "personId": "683",
    "requestId": "4dcb55b1c",
    "createdAt": 160199,
    "version": 1,
    "blocks": [
    {
    "type": "text",
    "value": message,
    }
    ],
    "plainText": message,
    }


    var params = {
    'method': 'post',
    'contentType': 'application/json',
    'headers': {
    'x-access-key': '5f4bbf',
    'x-access-secret': '342b0698327',
    },
    'payload': JSON.stringify(payload1)
    }

    var response = UrlFetchApp.fetch(discordUrl, params);

    var text=response.getContentText();
    Browser.msgBox('테스트', text, Browser.Buttons.YES_NO_CANCEL);

    Logger.log(response.getContentText());
    }
  • profile
    GAS 속도 괜찮나요?? 예전에 webhook 구현할때 공짜라서 (사실 IO제한이 있긴하지만 넉넉한 편이라) GAS 사용해봤는데 응답속도가 좀 느린거 같더라구요... 어차피 디비처리 해주려면 한계가 있어서 LNMP 하나파서 연동해보니 GAS가 느린거더라구요
  • profile ?
    아직 데이터량이 작아서 속도를 체감할 단계에 있지는 않습니다~ 데이터가 많아지면 말씀하신 문제가 생길 수도 있겠네요!