LINEBOT-GoogleAppScript กำหนดสิทธิ์ follower ในการใช้งาน

ITTIRIT T.
3 min readSep 18, 2019

--

QR bot ตัวอย่าง

Repository : https://github.com/itchampclub/linebot-GAS-con

การทำ Linebot โดยใช้ google app script เป็น webhook และใช้ google sheet บันทึกข้อมูล

  1. สร้าง sheet

2.webhook โดยใช้ code จากไฟล์ webhook.gs ใน repository

config

อธิบายการทำงานคร่าวๆ

เมื่อ user follow bot >> case ‘follow’:

ฝั่ง user
ฝั่งผู้ดูแล

เมื่อ user ส่งข้อความหรือ event ใดๆ ขณะที่ยังไม่ได้รับการยืนยันจากผู้ดูแล

เมื่อผู้ดูแล confirm ให้ user สามารถใช้งานฟังก์ชั่นต่างๆได้

if(messageText.indexOf(“conf “)>-1){ << ตรวจสอบ text ที่มี conf เพื่อเข้าฟังก์ชั่นยืนยันให้ user ใช้งาน
var confId = messageText.split(‘ ‘,2)[1]; << เลือกตัดเฉพาะ userid ด้วยการ split จาก วรรค conf userid [จะได้ userid เพื่อนำไปค้นหาและยืนยันให้ใช้งาน]

ผลลัพธ์

if(confstatus == true){

//ส่วนที่ทำงานเฉพาะ user ที่ได้รับการยืนยันแล้ว สามารถปรับแก้ไขเพิ่มเติมได้ในส่วนนี้

if(messageText == “ทดสอบ”){
var mess = [{‘type’: ‘text’, ‘text’: ‘ข้อความทดสอบ ยืนยันแล้ว’}];
replyMsg(replyToken, mess, channelToken);
}
else{
var mess = [{‘type’: ‘text’, ‘text’: messageText}];
replyMsg(replyToken, mess, channelToken);
}

}

3.เมื่อแก้ไขโค๊ดเรียบร้อยแล้ว

Deploying a script as a web app

url ที่ได้คือ webhook

https://developers.line.biz/console/ << ตั้งค่า

หรือเข้าไปตั้งค่าที่ https://manager.line.biz/

--

--