app script doPost รับข้อมูลจาก diaglogflow

 function doPost(e) {

try {
const body = JSON.parse(e.postData.contents);
const queryResult = body.queryResult;
const outputContexts = queryResult.outputContexts;

let productEntity = '';

// ค้นหา context ที่มีชื่อลงท้ายด้วย 'getprice-followup'
const getPriceContext = outputContexts.find(context => context.name.endsWith('getprice-followup'));

if (getPriceContext && getPriceContext.parameters) {
productEntity = getPriceContext.parameters.product_entity;
}

// สร้าง response object
const response = {
fulfillmentText: `คุณเลือกผลิตภัณฑ์: ${productEntity}`
};

// ส่งค่ากลับเป็น JSON
return ContentService.createTextOutput(JSON.stringify(response))
.setMimeType(ContentService.MimeType.JSON);

} catch (error) {
// จัดการข้อผิดพลาด
console.error('Error in doPost:', error);
return ContentService.createTextOutput(JSON.stringify({ fulfillmentText: "ขออภัย เกิดข้อผิดพลาดบางอย่าง" }))
.setMimeType(ContentService.MimeType.JSON);
}
}

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

google app script เชื่อมต่อกับ diaglogflow