JSFiddle - React, Tailwind, and code Playground

by hbjpn

JavaScript

// here's some helpfull documentation
// request.headers - an array of headers
// reauest.body - body in text form
// request.method - one of [GET, POST, PUT, etc]
// request.query - URL query parameters

request = {};
request.headers = {};
//request.body="{'incident:\'huga\'}";

// write your code here to modify request
request.headers['X-ChatWorkToken'] = '2604b79e0eb07cd7edd5193edf9ed4e5';
request.headers['Content-Type'] = "application/x-www-form-urlencoded";
//request.body = "body="+ (encodeURI(JSON.stringify(request.body,null,'  ')));
// Somewhat, request.body is 
var obj = {
    incident: {
        incident_updates : [{},{}]
    }
};
    //JSON.parse(request.body);
var body = "";
body += "[info]";

if( "incident" in obj ){
    var latest = obj.incident.incident_updates[0]; // latest update
    body += "[title] Incident 通知 : "+obj.incident.name+" ("+obj.incident.status+")[/title]\n";
    body += "更新日時 : "+latest.updated_at + "\n";
    body += "状態 : "+latest.status + "\n";
    body += latest.body

}else if("component_update" in obj){
    body += "[title]"+"Component 更新通知"+"[/title]";
}else{
    body += "[title]"+"不明な状態通知" +"[/title]\n";
}

body += "詳細は https://status.sengdrid.com/ を確認して下さい."
body += "[/info]";
var formattedString = JSON.stringify(obj,null,'\t');
request.body = "body="+body;

console.log(request);