1

I've tried to convert cUrl source to Google App Script.

I've successed at cUrl.

But fail to convert Google App Script source.

I think that there is Something Problem in Google App Script source, but I can't solve it.

Thank you.

  1. cUrl source
curl -X POST "https://api.channel.io/open/v3/user-chats/5f726xxxxxxxxxxx/messages?botName=helloworldbot" -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\": \"Hello World\" } ], \"plainText\": \"Hello World\" },"
  1. Google App Script

    function test3() {

 

  var discordUrl = "https://api.channel.io/open/v3/user-chats/5f72xxxxxxxx/messages?botName=helloworldbot";

 

  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('test', text, Browser.Buttons.YES_NO_CANCEL);

 

  Logger.log(response.getContentText());

}

Oh. Solved.

I can answer myself joyful.

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

It worked.

Thank you!

Msjc Laki
  • 11
  • 2

0 Answers0