なぜ作ったか
- CoffeeScriptに慣れたかった。
- Hubotにやってもらうことを増やしたかった。
利用させていただいたもの
使い方
PCサイトの情報を知りたいときは
hubot psi google.co.jp desktop
スマートフォンサイトの情報を知りたいときは
hubot psi google.co.jp mobile
ソースコード
psi.coffee
psi = require('psi')
module.exports = (robot) ->
message = (id, title, score, numberResources, numberHosts, totalRequestBytes
, numberStaticResources, htmlResponseBytes, cssResponseBytes, imageResponseBytes
, javascriptResponseBytes, otherResponseBytes, numberJsResources, numberCssResources)-> """
ʕ•ᴥ•ʔが教えるPageSpeed Insights!
domain: #{id}
name: #{title}
score: #{score}
numberResources: #{numberResources}
numberHosts: #{numberHosts}
totalRequestBytes: #{totalRequestBytes}
numberStaticResources: #{numberStaticResources}
htmlResponseBytes: #{htmlResponseBytes}
cssResponseBytes: #{cssResponseBytes}
imageResponseBytes: #{imageResponseBytes}
javascriptResponseBytes: #{javascriptResponseBytes}
otherResponseBytes: #{otherResponseBytes}
numberJsResources: #{numberJsResources}
numberCssResources: #{numberCssResources}
"""
robot.respond /psi (.*)/i, (msg) ->
matches = msg.match[1].split(' ')
url = matches[0]
if matches[1] == 'desktop' || matches[1] == 'mobile'
strategy = matches[1]
else
strategy = 'desktop'
locale = 'ja_JP'
psi(url,
nokey: 'true'
strategy: strategy
locale: locale).then (data) ->
msg.send message(data.id, data.title, data.ruleGroups.SPEED.score, data.pageStats.numberResources, data.pageStats.numberHosts, data.pageStats.totalRequestBytes
, data.pageStats.numberStaticResources, data.pageStats.htmlResponseBytes, data.pageStats.cssResponseBytes, data.pageStats.imageResponseBytes
, data.pageStats.javascriptResponseBytes, data.pageStats.otherResponseBytes, data.pageStats.numberJsResources, data.pageStats.numberCssResources)
return