Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // Google Apps Script 
function doPost(e) {
  // スクリプトのプロパティから各tokenを取得
  var prop = PropertiesService.getScriptProperties().getProperties();
  var bot_name = "ゴゴ号"; // Botの名前
  var bot_icon = "https://drive.google.com/uc?export=view&id=xxxxx-xxxxxxxxxx"; // Botのアイコン

  // tokenが一致しなかったらエラー
  if (prop.VERIFY_TOKEN != e.parameter.token) {
    throw new Error("invalid token.");
  }

  /* 帰ってくる値はこんな感じ
  token=5oz5Ei0XJcGvZznPJUDnbctoken=5oz5Ei0XJcGvZznPJUDnbcyy
  team_id=T0001
  team_domain=example
  channel_id=C2147483705
  channel_name=test
  timestamp=1355517523.000005
  user_id=U2147483697
  user_name=Steve
  text=googlebot: What is the air-speed velocity of an unladen swallow?
  trigger_word=googlebot:
  */

  var app = SlackApp.create(prop.SLACK_ACCESS_TOKEN);

  // デフォルトのリアクション
  var message = "@" + e.parameter.user_name + " " + "あい"; 

  var text = e.parameter.text; // 発言を取得
  var channel = e.parameter.channel_id; // Channnelを取得

  // 記念日
  if(text.match(/記念/) || text.match(/きねん/) || text.match(/kinen/)){
    // スプレッドシートを指定
    var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxxxx/edit#gid=0');
    var sheet = ss.getSheets()[0]; // シートを指定(左から0、1、2...)
    var sheetdata = sheet.getSheetValues(1,1,1,1); // 取得するセルの範囲を指定(A1だけ取得)
    var message = "@" + e.parameter.user_name + " " + sheetdata[0][0]; // 取得するセルを指定(0から[行][列])
  }

  // ゴミの日
  if(text.match(/ゴミ/) || text.match(/ごみ/) || text.match(/gomi/)){
    var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxxxx/edit#gid=0');
    var sheet = ss.getSheets()[1];
    var sheetdata = sheet.getSheetValues(1,1,1,1); 
    var message = "@" + e.parameter.user_name + " " + sheetdata[0][0];
  }

  // ごはん
  if(text.match(/ごはん/) || text.match(/ゴハン/) || text.match(/gohan/)){
    var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxxxx/edit#gid=0');
    var sheet = ss.getSheets()[2];
    var sheetdata = sheet.getSheetValues(1,1,sheet.getLastRow(),1); // A1:A1000までを取得
    var num = sheetdata[0][1]; // counta関数で取得したデータの総数を取得
    var rand = Math.floor(Math.random()*num); // 0~総数でランダムな値を取得
    var message = "@" + e.parameter.user_name + " " + sheetdata[rand][0]; // A列の値をランダムに取得
  }

  // 天気予報
  if(text.match(/てんき/) || text.match(/テンキ/) || text.match(/tenki/) || text.match(/天気/)){
    var weather = UrlFetchApp.fetch("http://weather.livedoor.com/forecast/webservice/json/v1?city=1320300"); // 東京武蔵野市

    // エラーだったら処理を終了
    if(weather.getResponseCode() != 200){
      return false;
    }

    var json = JSON.parse(weather.getContentText());
    var today = json["forecasts"][0]["telop"]; // 今日の天気
    var tomorrow = json["forecasts"][1]["telop"]; // 明日の天気
    var message = "@" + e.parameter.user_name + " 今日は「" + today + "」。明日は「" + tomorrow + "」やで~";
  }

  // messageをSlackに投稿
  return app.postMessage(channel, message, {
    username: bot_name,
    icon_url: bot_icon
  });
}
              
            
!
999px

Console