function doPost(e) {
var hook = JSON.parse(e.postData.contents);
var hooktype = hook.webhook_type;
var data = hook.entity_data;
var dog = data.animal_name;
var last = data.o_last;
var pic = data.image;
var breed = data.breed_name;
var type = data.type;
var sheet = SpreadsheetApp.getActiveSheet();
var url = "DISCORD_URL";
var params = {
"method": "post",
"headers": {
"Content-Type": "application/json",
},
"payload": JSON.stringify({
"username": dog,
"content": "I'm going home!",
"embeds": [{
"title": "Reservation Type",
"description": type,
"fields": [
{
"name": dog,
"value": last,
"inline": true
},
{
"name": "Breed",
"value": breed,
"inline": true
}
],
"image": {
"url": pic
}
}]
})
};
if (hooktype === "check_out") {
sheet.appendRow([dog, last, breed, pic]);
UrlFetchApp.fetch(url, params);
}
return ContentService.createTextOutput(JSON.stringify({ "success": true }))
.setMimeType(ContentService.MimeType.JSON);
}
Changes:
- Added proper content-type header for JSON payload
- Fixed the breed field formatting (was missing "value" property)
- Added strict equality operator (===) for type checking
- Added error handling with proper response
- Added return statement to properly handle the webhook response
Use:
- Replace "DISCORD WEBHOOK URL WILL GO HERE" with your actual Discord webhook URL
- Deploy it as a Google Apps Script web app
- Make sure to set the proper deployment permissions
Check:
- Double check your URL is correct
- Ensure all the data fields are present in your incoming webhook payload
- Double check your Google Apps Script has the proper permissions set.
- Make sure your deployment settings allow external access