functiononFormSubmit(event){processResponse(event.response);}functionprocessResponse(response){constpayload=buildDiscordMessage(response);constendpoint=getSecret("webhookEndpoint");constpostFunc=buildPostToDiscordFunc(endpoint);postFunc(payload);}functionbuildDiscordMessage(response){constform=FormApp.getActiveForm();constkind=buildFetchElementResponseFunc(123456780)(response);constproductId=buildFetchElementResponseFunc(123456781)(response);constcontent=buildFetchElementResponseFunc(123456782)(response);constembed={"description":`${form.getTitle()} に回答があります`,"fields":[{"name":"種別","value":kind,"inline":true,},{"name":"URL","value":buildBoothProductUrl(productId),"inline":true,},{"name":"内容","value":content,"inline":false,},],};switch(kind){case"要望":embed["color"]=0x609dff;break;case"不具合報告":embed["color"]=0xff7777;break;}return{"embeds":[embed],};}functionbuildBoothProductUrl(id){if(/^\d+$/.test(id)){return`https://booth.pm/ja/items/${id}`;}return"";}functionbuildPostToDiscordFunc(endpoint){returnfunction(payload){returnUrlFetchApp.fetch(endpoint,{"method":"POST","contentType":"application/json","payload":JSON.stringify(payload),},);};}// === GAS/Form functions ===
functionbuildFetchElementResponseFunc(elementId){returnfunction(response){for(letitemofresponse.getItemResponses()){if(item.getItem().getId()==elementId){returnitem.getResponse();}}thrownewError(`Form element whose id is ${elementId} not found`);}}functiongetSecret(key){returnPropertiesService.getScriptProperties().getProperty(key);}// === Debug functions ===
// Dumps form elements with their id
functiondumpFormElements(){constform=FormApp.getActiveForm();constitems=form.getItems().map(item=>`id: ${item.getId()}, title: ${item.getTitle()}`);console.info(items.join("\n"));}// Processes first response to test
functiontestSendFirstResponse(){constform=FormApp.getActiveForm();constresponses=form.getResponses();if(responses.length==0){console.warn("No response recorded")return;}processResponse(responses[0]);}