Last active
October 13, 2022 13:11
-
-
Save neno-tech/7c40fa6cea405df9302d57113f5c4973 to your computer and use it in GitHub Desktop.
โค้ดสร้างไลน์แชตบอต Zoom 15 ก.ย. 64
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
var CHANNEL_ACCESS_TOKEN = 'xxx'; | |
var line_endpoint = 'https://api.line.me/v2/bot/message/reply'; | |
function doGet(request) { | |
return ContentService.createTextOutput(JSON.stringify({ | |
post: "ok" | |
})).setMimeType(ContentService.MimeType.JSON); | |
} | |
function doPost(e) { | |
var json = JSON.parse(e.postData.contents); | |
var reply_token = json.events[0].replyToken; | |
var message = json.events[0].message.text; | |
var result = {} | |
//------------------ | |
//------------------ | |
UrlFetchApp.fetch(line_endpoint, { | |
'headers': { | |
'Content-Type': 'application/json; charset=UTF-8', | |
'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, | |
}, | |
'method': 'post', | |
'payload': JSON.stringify({ | |
'replyToken': reply_token, | |
'messages': [result], | |
}), | |
}); | |
var replyJSON = ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON); | |
return replyJSON; | |
} |
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
++++++ลิ้งค์ทำสำเนาตัวอย่างข้อมูล Google Sheet++++++ | |
https://docs.google.com/spreadsheets/d/1VF5HOrEhbCU1c-2nC69oo1WFLm0Hr_DI2uQYoRGN-nk/copy | |
++++สติกเกอร์+++++ | |
result={ | |
type: "sticker", | |
packageId: 11537, | |
stickerId: 52002744 | |
} | |
++++รูปภาพ+++++ | |
result={ | |
type: "image", | |
originalContentUrl: "https://sv1.picz.in.th/images/2021/09/15/CjW7vn.png", | |
previewImageUrl: "https://sv1.picz.in.th/images/2021/09/15/CjW7vn.png" | |
} | |
++++quick reply+++++ | |
result={ | |
"type": "text", | |
"text": "กรุณาเลือกเมนู", | |
"quickReply": { | |
"items": [ | |
{ | |
"type": "action", | |
"action": { | |
"type": "uri", | |
"label": "เมนู1", | |
"uri": "https://developers.line.biz" | |
} | |
}, | |
{ | |
"type": "action", | |
"action": { | |
"type": "uri", | |
"label": "เมนู2", | |
"uri": "https://developers.line.biz" | |
} | |
} | |
] | |
} | |
} |
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
var CHANNEL_ACCESS_TOKEN = 'xxx'; //แก้1 | |
var line_endpoint = 'https://api.line.me/v2/bot/message/reply'; | |
function doGet(request) { | |
return ContentService.createTextOutput(JSON.stringify({ | |
post: "ok" | |
})).setMimeType(ContentService.MimeType.JSON); | |
} | |
var ws = SpreadsheetApp.openById('xxx') //แก้2 | |
var sheet = ws.getSheetByName("xxx"); //แก้3 | |
var data = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn()).getDisplayValues(); | |
//Logger.log(data) | |
var result = { | |
type: 'text', | |
text: 'ไม่พบข้อมูล' | |
} | |
function doPost(e) { | |
var json = JSON.parse(e.postData.contents); | |
var reply_token = json.events[0].replyToken; | |
var message = json.events[0].message.text; | |
for (var i = 0; i < data.length; i++) { | |
if (data[i][0] == message) { | |
i = i + 2; | |
var data1 = sheet.getRange(i, 1).getDisplayValue(); //รหัส | |
var data2 = sheet.getRange(i, 2).getDisplayValue(); //ชื่อ - นามสกุล | |
var data3 = sheet.getRange(i, 3).getDisplayValue(); //เบอร์โทร | |
var data4 = sheet.getRange(i, 4).getDisplayValue(); //อีเมล | |
var data5 = sheet.getRange(i, 5).getDisplayValue(); //ชื่อเล่น | |
var data6 = sheet.getRange(i, 6).getDisplayValue(); //วันเกิด | |
result = | |
//------------------------------- | |
//------------------------------- | |
result = { | |
'type': 'flex', | |
'altText': 'This is Flex Message', | |
'contents': result | |
} | |
break; | |
};//End if | |
};//End for | |
UrlFetchApp.fetch(line_endpoint, { | |
'headers': { | |
'Content-Type': 'application/json; charset=UTF-8', | |
'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, | |
}, | |
'method': 'post', | |
'payload': JSON.stringify({ | |
'replyToken': reply_token, | |
'messages': [result], | |
}), | |
}); | |
var replyJSON = ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON); | |
return replyJSON; | |
} |
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
var CHANNEL_ACCESS_TOKEN = ''; | |
var line_endpoint = 'https://api.line.me/v2/bot/message/reply'; | |
function doGet(request) { | |
return ContentService.createTextOutput(JSON.stringify({ | |
post: "ok" | |
})).setMimeType(ContentService.MimeType.JSON); | |
} | |
var ws = SpreadsheetApp.openById('xxx') //แก้2 | |
var sheet = ws.getSheetByName("ชีต1"); //แก้3 | |
var data = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn()).getDisplayValues(); | |
//Logger.log(data) | |
var result = { | |
type: 'text', | |
text: 'ไม่พบข้อมูล' | |
} | |
function doPost(e) { | |
var json = JSON.parse(e.postData.contents); | |
var reply_token = json.events[0].replyToken; | |
var message = json.events[0].message.text; | |
var msg = message.split(',') | |
if(msg[0]=='ค้นหา'){ | |
var msg1 = msg[1] | |
for (var i = 0; i < data.length; i++) { | |
if (data[i][0] == msg1) { | |
i = i + 2; | |
var data1 = sheet.getRange(i, 1).getDisplayValue(); //รหัส | |
var data2 = sheet.getRange(i, 2).getDisplayValue(); //ชื่อ - นามสกุล | |
var data3 = sheet.getRange(i, 3).getDisplayValue(); //เบอร์โทร | |
var data4 = sheet.getRange(i, 4).getDisplayValue(); //อีเมล | |
var data5 = sheet.getRange(i, 5).getDisplayValue(); //ชื่อเล่น | |
var data6 = sheet.getRange(i, 6).getDisplayValue(); //วันเกิด | |
result = | |
//------------------------------- | |
{ | |
"type": "bubble", | |
"body": { | |
"type": "box", | |
"layout": "vertical", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "ข้อมูลนักเรียน", | |
"weight": "bold", | |
"color": "#1DB446", | |
"size": "lg" | |
}, | |
{ | |
"type": "text", | |
"text": data2, | |
"weight": "bold", | |
"size": "xxl", | |
"margin": "md" | |
}, | |
{ | |
"type": "separator", | |
"margin": "xxl" | |
}, | |
{ | |
"type": "box", | |
"layout": "vertical", | |
"margin": "xxl", | |
"spacing": "sm", | |
"contents": [ | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "รหัสนักเรียน", | |
"size": "lg", | |
"color": "#555555", | |
"flex": 0 | |
}, | |
{ | |
"type": "text", | |
"text": data1, | |
"size": "lg", | |
"color": "#111111", | |
"align": "end" | |
} | |
] | |
}, | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "เบอร์โทร", | |
"size": "lg", | |
"color": "#555555", | |
"flex": 0 | |
}, | |
{ | |
"type": "text", | |
"text": data3, | |
"size": "lg", | |
"color": "#111111", | |
"align": "end" | |
} | |
] | |
}, | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "อีเมล", | |
"size": "lg", | |
"color": "#555555", | |
"flex": 0 | |
}, | |
{ | |
"type": "text", | |
"text": data4, | |
"size": "lg", | |
"color": "#111111", | |
"align": "end" | |
} | |
] | |
}, | |
{ | |
"type": "separator", | |
"margin": "xxl" | |
}, | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"margin": "xxl", | |
"contents": [] | |
}, | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"contents": [] | |
}, | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "ชื่อเล่น", | |
"size": "lg", | |
"color": "#555555" | |
}, | |
{ | |
"type": "text", | |
"text": data5, | |
"size": "lg", | |
"color": "#111111", | |
"align": "end" | |
} | |
] | |
}, | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "วันเกิด", | |
"size": "lg", | |
"color": "#555555" | |
}, | |
{ | |
"type": "text", | |
"text": data6, | |
"size": "lg", | |
"color": "#111111", | |
"align": "end" | |
} | |
] | |
} | |
] | |
}, | |
{ | |
"type": "separator", | |
"margin": "xxl" | |
}, | |
{ | |
"type": "box", | |
"layout": "horizontal", | |
"margin": "md", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "ครูที่ปรึกษา", | |
"size": "xs", | |
"color": "#aaaaaa", | |
"flex": 0 | |
}, | |
{ | |
"type": "text", | |
"text": "อภิวัฒน์ วงศ์กัณหา", | |
"color": "#aaaaaa", | |
"size": "xs", | |
"align": "end" | |
} | |
] | |
} | |
] | |
}, | |
"styles": { | |
"footer": { | |
"separator": true | |
} | |
} | |
} | |
//------------------------------- | |
result = { | |
'type': 'flex', | |
'altText': 'This is Flex Message', | |
'contents': result | |
} | |
break; | |
};//End if | |
};//End for | |
} | |
UrlFetchApp.fetch(line_endpoint, { | |
'headers': { | |
'Content-Type': 'application/json; charset=UTF-8', | |
'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, | |
}, | |
'method': 'post', | |
'payload': JSON.stringify({ | |
'replyToken': reply_token, | |
'messages': [result], | |
}), | |
}); | |
var replyJSON = ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON); | |
return replyJSON; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment