Skip to content

Instantly share code, notes, and snippets.

@KazuCocoa
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KazuCocoa/26a5f3ee8b9bb19aafb5 to your computer and use it in GitHub Desktop.
Save KazuCocoa/26a5f3ee8b9bb19aafb5 to your computer and use it in GitHub Desktop.
/*
* @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