Last active
August 29, 2015 14:19
-
-
Save KazuCocoa/26a5f3ee8b9bb19aafb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @param authToken [String] HipChat token you are created. | |
* @param roomId [String] Room id you would like to send notification. | |
* @param message [String] Message string | |
*/ | |
function hipchat(authToken, roomId, message) { | |
var url = 'https://api.hipchat.com/v2/room/' + roomId + '/notification?auth_token=' + authToken; | |
var payload = | |
{ | |
color : 'green', | |
message : message, | |
notify : true, | |
message_format : 'text' | |
}; | |
var params = | |
{ | |
method : 'post', | |
contentType : 'application/json; charset=utf-8', | |
payload : JSON.stringify(payload) | |
}; | |
var res = UrlFetchApp.fetch(url, params); | |
} | |
/* | |
* @param formId [String] Form ID you would like to access. | |
*/ | |
function submittedMessage(formId) { | |
var existingForm = FormApp.openById(formId); | |
var responses = existingForm.getResponses(); | |
var result = 'Submitted:'; | |
var latestResponse = responses[responses.length - 1]; | |
result = result + Utilities.formatDate(latestResponse.getTimestamp(), 'Asia/Tokyo', 'yyyy年MM月dd日(EEE) HH:mm:ss'); | |
var itemResponses = latestResponse.getItemResponses(); | |
for (var i = 0; i < itemResponses.length; i++) { | |
var itemResponse = itemResponses[i]; | |
result = result + '\n' + itemResponse.getItem().getTitle() + itemResponse.getResponse(); | |
} | |
return result | |
} | |
function messageToHipchat() { | |
hipchat(authToken, roomId, submittedMessage(formId)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment