let template = require('./builder.js');
let kms = require('./kms.js');
let cw = require('./post.js');

exports.handler = (event, context, callback) => {

  console.log('Received event:', JSON.stringify(event, null, 2));

  // try {
  //   var config = require('./.env.json')
  //   for (var key in config) {
  //     process.env[key] = config[key]
  //   }
  // } catch (err) {
  //   // ignore
  // }

  // Encrypted Chatwork token
  const enc_cwtoken = process.env.CHATWORK_API_TOKEN;

  // Chatwork Room ID from queryString
  const room_id = event.pathParameters['room_id'];

  // Payload from GitHub
  const payload = event.requestParameters;

  // GitHub Event Name
  const eventName = event.headers['X-GitHub-Event'];

  Promise.all([
    kms.decrypt(enc_cwtoken),
    new Promise((resolve, reject)=>{
      if(room_id != ''){
        resolve(room_id);
      }else{
        reject("room_id is blank.");
      }
    }),
    template.build(eventName, payload)
  ]).then((payload)=>{
    return cw.message(
      payload[0], // Raw Chatwork token
      payload[1], // Chatwork Room ID
      payload[2]
    );
  }).then((text)=>{
    callback(null, {"text": text});
    context.succeed();
  }).catch((reason)=>{
    console.log(reason);
    console.log("Not post to chatwork.");
    context.fail();
  });

}

@@ -218,190 +218,8 @@
 );%0A%0A
-  // try %7B%0A  //   var config = require('./.env.json')%0A  //   for (var key in config) %7B%0A  //     process.env%5Bkey%5D = config%5Bkey%5D%0A  //   %7D%0A  // %7D catch (err) %7B%0A  //   // ignore%0A  // %7D%0A%0A
   //
@@ -915,16 +915,42 @@
 yload%5B2%5D
+  // Chatwork message body
 %0A    );%0A
@@ -973,44 +973,8 @@
 =%3E%7B%0A
-    callback(null, %7B%22text%22: text%7D);%0A
     

Simplify index.js