@@ -48,33 +48,9 @@ const handleEvent = async (event) => {
4848
4949 // เช็คข้อมูล
5050 if ( event . type !== 'message' || event . message . type !== 'text' ) return null ;
51- // พิมหาบอทที่ไม่ใช่ command
52- else if ( event . type === 'message' || ! event . message . text . startsWith ( prefix ) ) {
53- let msg ;
54- let usermsg = [ "test" , "tot" ]
55- let replymsg = [ "ต้องการใช้งานบอทหรอครับ?" , "หากต้องการใช้งานบอทโปรดพิม !help ครับ" , "มีอะไรให้ช่วยไหมครับ >_<" ]
56-
57- for ( let i = 0 ; i < usermsg . length ; i ++ ) {
58- if ( ! event . message . text . includes ( usermsg [ i ] ) ) {
59- check = false ;
60- }
61- }
62-
63- for ( let i = 0 ; i < usermsg . length ; i ++ ) {
64- if ( event . message . text . includes ( usermsg [ i ] ) ) {
65- msg = replymsg [ Math . floor ( Math . random ( ) * replymsg . length ) ] ;
66- check = true ;
67- }
68- }
69-
70- if ( check == false ) {
71- return null ;
72- }
73-
74- return client . replyMessage ( event . replyToken , msg ) ;
75- }
51+
7652 // เริ่มทำงานในโต้ตอบ
77- else if ( event . type === 'message' || event . message . text . startsWith ( prefix ) ) {
53+ else if ( event . message . text . startsWith ( prefix ) ) {
7854
7955 // คำสั่งเรียกใช้งาน
8056 const args = event . message . text . trim ( ) . split ( / + / g) ;
@@ -105,89 +81,178 @@ const handleEvent = async (event) => {
10581 }
10682 }
10783
108- console . log ( sheet ) ;
10984 // Message Box สินค้าทั้งหมด
110- let msg1 = {
85+ let msg1 =
86+ {
11187 "type" : "flex" ,
11288 "altText" : "this is a flex message" ,
11389 "contents" : {
114- "type" : "bubble" ,
115- "styles" : {
116- "footer" : {
117- "separator" : true
90+ "type" : "carousel" ,
91+ "contents" : [ {
92+ "type" : "bubble" ,
93+ "styles" : {
94+ "footer" : {
95+ "separator" : true
96+ }
97+ } ,
98+ "hero" : {
99+ "type" : "image" ,
100+ "url" : "https://www.somjitpanich.com/wp-content/uploads/2020/06/8996001355923.jpg" ,
101+ "size" : "full" ,
102+ "aspectRatio" : "1.51:1" ,
103+ "aspectMode" : "fit" ,
104+ "backgroundColor" : "#FFFFFF"
105+ } ,
106+ "body" : {
107+ "type" : "box" ,
108+ "layout" : "vertical" ,
109+ "spacing" : "md" ,
110+ "backgroundColor" : "#121212" ,
111+ "contents" : [
112+ { "type" : "text" , "text" : "รายการสินค้า" , "weight" : "bold" , "color" : "#ffdab9" , "size" : "sm" } ,
113+ { "type" : "text" , "text" : "สินค้าทั้งหมด" , "weight" : "bold" , "color" : "#ffffff" , "size" : "xxl" , "margin" : "md" } ,
114+ { "type" : "separator" , "margin" : "xxl" } ,
115+ { "type" : "box" , "layout" : "vertical" , "margin" : "xxl" , "spacing" : "sm" ,
116+ "contents" : [
117+ {
118+ "type" : "box" , "layout" : "horizontal" ,
119+ "contents" : [
120+ { "type" : "text" , "text" : "ชื่อสินค้า" , "size" : "lg" , "color" : "#ffffff" , "weight" : "bold" , "align" : "start" } ,
121+ { "type" : "text" , "text" : "สต๊อก" , "size" : "lg" , "color" : "#ffffff" , "weight" : "bold" , "align" : "center" } ,
122+ { "type" : "text" , "text" : "ราคา" , "size" : "lg" , "color" : "#ffffff" , "weight" : "bold" , "align" : "end" }
123+ ] ,
124+ } ,
125+ { "type" : "separator" , "margin" : "md" , "color" : "#121212" } ,
126+ {
127+ "type" : "box" , "layout" : "horizontal" ,
128+ "contents" : [
129+ { "type" : "text" , "text" : getRows . data . values [ 1 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
130+ { "type" : "text" , "text" : getRows . data . values [ 1 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
131+ { "type" : "text" , "text" : getRows . data . values [ 1 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
132+ ]
133+ } ,
134+ {
135+ "type" : "box" , "layout" : "horizontal" ,
136+ "contents" : [
137+ { "type" : "text" , "text" : getRows . data . values [ 2 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
138+ { "type" : "text" , "text" : getRows . data . values [ 2 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
139+ { "type" : "text" , "text" : getRows . data . values [ 2 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
140+ ] ,
141+ } ,
142+ {
143+ "type" : "box" , "layout" : "horizontal" ,
144+ "contents" : [
145+ { "type" : "text" , "text" : getRows . data . values [ 3 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
146+ { "type" : "text" , "text" : getRows . data . values [ 3 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
147+ { "type" : "text" , "text" : getRows . data . values [ 3 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
148+ ]
149+ } ,
150+ {
151+ "type" : "box" , "layout" : "horizontal" ,
152+ "contents" : [
153+ { "type" : "text" , "text" : getRows . data . values [ 4 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
154+ { "type" : "text" , "text" : getRows . data . values [ 4 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
155+ { "type" : "text" , "text" : getRows . data . values [ 4 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
156+ ]
157+ } ,
158+ {
159+ "type" : "box" , "layout" : "horizontal" ,
160+ "contents" : [
161+ { "type" : "text" , "text" : getRows . data . values [ 5 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
162+ { "type" : "text" , "text" : getRows . data . values [ 5 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
163+ { "type" : "text" , "text" : getRows . data . values [ 5 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
164+ ]
165+ }
166+ ]
167+ }
168+ ]
118169 }
119170 } ,
120- "hero" : {
121- "type" : "image" ,
122- "url" : "https://i.pinimg.com/564x/c8/55/ae/c855aea64c62ef90a746df8d1670b017.jpg" ,
123- "size" : "full" ,
124- "aspectRatio" : "1.51:1" ,
125- "aspectMode" : "fit" ,
126- "backgroundColor" : "#000000FF"
127- } ,
128- "body" : {
129- "type" : "box" ,
130- "layout" : "vertical" ,
131- "spacing" : "md" ,
132- "backgroundColor" : "#121212" ,
133- "contents" : [
134- { "type" : "text" , "text" : "รายการสินค้า" , "weight" : "bold" , "color" : "#ffdab9" , "size" : "sm" } ,
135- { "type" : "text" , "text" : "สินค้าทั้งหมด" , "weight" : "bold" , "color" : "#ffffff" , "size" : "xxl" , "margin" : "md" } ,
136- { "type" : "separator" , "margin" : "xxl" } ,
137- { "type" : "box" , "layout" : "vertical" , "margin" : "xxl" , "spacing" : "sm" ,
138- "contents" : [
139- {
140- "type" : "box" , "layout" : "horizontal" ,
141- "contents" : [
142- { "type" : "text" , "text" : "ชื่อสินค้า" , "size" : "lg" , "color" : "#ffffff" , "weight" : "bold" , "flex" : 0 } ,
143- { "type" : "text" , "text" : "สต๊อก" , "size" : "lg" , "color" : "#ffffff" , "weight" : "bold" , "align" : "end" } ,
144- ] ,
145- } ,
146- { "type" : "separator" , "margin" : "md" , "color" : "#121212" } ,
147- {
148- "type" : "box" , "layout" : "horizontal" ,
149- "contents" : [
150- { "type" : "text" , "text" : getRows . data . values [ 1 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "flex" : 0 } ,
151- { "type" : "text" , "text" : getRows . data . values [ 1 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
152- ]
153- } ,
154- {
155- "type" : "box" , "layout" : "horizontal" ,
156- "contents" : [
157- { "type" : "text" , "text" : getRows . data . values [ 2 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "flex" : 0 } ,
158- { "type" : "text" , "text" : getRows . data . values [ 2 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" } ,
159- ] ,
160- } ,
161- {
162- "type" : "box" , "layout" : "horizontal" ,
163- "contents" : [
164- { "type" : "text" , "text" : getRows . data . values [ 3 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "flex" : 0 } ,
165- { "type" : "text" , "text" : getRows . data . values [ 3 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
166- ]
167- }
168- ]
169- } ,
170- {
171- "type" : "box" ,
172- "layout" : "vertical" ,
173- "flex" : 0 ,
174- "spacing" : "sm" ,
175- "contents" : [
176- {
177- "type" : "button" ,
178- "action" : {
179- "type" : "uri" ,
180- "label" : "เพิ่มเติม" ,
181- "uri" : "https://docs.google.com/spreadsheets/d/1TFMBHX19EVQWgTZIruszDxIlXo5r1Oj4LYsQQTcutlM/"
182- } ,
183- "color" : "#ffdab9" ,
184- "height" : "md" ,
185- "style" : "secondary"
186- } ]
171+ // กล่องข้อความที่2
172+ {
173+ "type" : "bubble" ,
174+ "styles" : {
175+ "footer" : {
176+ "separator" : true
187177 }
188- ]
189- } ,
190- }
178+ } ,
179+ "hero" : {
180+ "type" : "image" ,
181+ "url" : "https://ocs-k8s-prod.s3.ap-southeast-1.amazonaws.com/product/302107.jpg" ,
182+ "size" : "full" ,
183+ "aspectRatio" : "1.51:1" ,
184+ "aspectMode" : "fit" ,
185+ "backgroundColor" : "#FFFFFF"
186+ } ,
187+ "body" : {
188+ "type" : "box" ,
189+ "layout" : "vertical" ,
190+ "spacing" : "md" ,
191+ "backgroundColor" : "#121212" ,
192+ "contents" : [
193+ { "type" : "text" , "text" : "รายการสินค้า" , "weight" : "bold" , "color" : "#ffdab9" , "size" : "sm" } ,
194+ { "type" : "text" , "text" : "หน้า 2" , "weight" : "bold" , "color" : "#ffffff" , "size" : "xxl" } ,
195+ { "type" : "separator" , "margin" : "xxl" } ,
196+ { "type" : "box" , "layout" : "vertical" , "margin" : "xxl" , "spacing" : "sm" ,
197+ "contents" : [
198+ //{"type": "separator", "margin": "md", "color": "#121212"},
199+ {
200+ "type" : "box" , "layout" : "horizontal" ,
201+ "contents" : [
202+ { "type" : "text" , "text" : getRows . data . values [ 6 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
203+ { "type" : "text" , "text" : getRows . data . values [ 6 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
204+ { "type" : "text" , "text" : getRows . data . values [ 6 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
205+ ]
206+ } ,
207+ {
208+ "type" : "box" , "layout" : "horizontal" ,
209+ "contents" : [
210+ { "type" : "text" , "text" : getRows . data . values [ 7 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
211+ { "type" : "text" , "text" : getRows . data . values [ 7 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
212+ { "type" : "text" , "text" : getRows . data . values [ 7 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
213+ ] ,
214+ } ,
215+ {
216+ "type" : "box" , "layout" : "horizontal" ,
217+ "contents" : [
218+ { "type" : "text" , "text" : getRows . data . values [ 8 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
219+ { "type" : "text" , "text" : getRows . data . values [ 8 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
220+ { "type" : "text" , "text" : getRows . data . values [ 8 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
221+ ]
222+ } ,
223+ {
224+ "type" : "box" , "layout" : "horizontal" ,
225+ "contents" : [
226+ { "type" : "text" , "text" : getRows . data . values [ 9 ] [ 0 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "start" } ,
227+ { "type" : "text" , "text" : getRows . data . values [ 9 ] [ 1 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "center" } ,
228+ { "type" : "text" , "text" : getRows . data . values [ 9 ] [ 2 ] , "size" : "sm" , "color" : "#ffffff" , "align" : "end" }
229+ ]
230+ }
231+ ]
232+ } ,
233+ {
234+ "type" : "box" ,
235+ "layout" : "vertical" ,
236+ "flex" : 0 ,
237+ "spacing" : "sm" ,
238+ "contents" : [
239+ {
240+ "type" : "button" ,
241+ "action" : {
242+ "type" : "uri" ,
243+ "label" : "เพิ่มเติม" ,
244+ "uri" : "https://docs.google.com/spreadsheets/d/1TFMBHX19EVQWgTZIruszDxIlXo5r1Oj4LYsQQTcutlM/"
245+ } ,
246+ "color" : "#ffdab9" ,
247+ "height" : "md" ,
248+ "style" : "secondary"
249+ } ]
250+ }
251+ ]
252+ }
253+ }
254+ ]
255+ } ,
191256 }
192257
193258 // Message Box สินค้าแต่ละชิ้น
@@ -332,6 +397,45 @@ const handleEvent = async (event) => {
332397
333398 // ส่งข้อมูลกลับไปยังฟังชั่นหลัก
334399 return client . replyMessage ( event . replyToken , replyLineMessage ) ;
400+
401+ // พิมหาบอทที่ไม่ใช่ command
402+ } else {
403+ let msg ;
404+ let usermsg = [ "มี" , "ใช่" ]
405+ let replymsgX = [ "ต้องการใช้งานบอทหรอครับ? (โปรดพิม ใช่ ถ้าต้องการใช้งานครับ)" , "มีอะไรให้ช่วยไหมครับ >_< (โปรดพิม มี ถ้าต้องการใช้งานครับ)" ]
406+ let replymsgY = [ "โปรดพิม !help ครับ" , "พิม !help ดูสิ!" , "พิม !help เพื่อดูคำสั่งครับ" ]
407+
408+ for ( let i = 0 ; i < usermsg . length ; i ++ ) {
409+ if ( ! event . message . text . includes ( usermsg [ i ] ) ) {
410+ check = false ;
411+ }
412+ }
413+
414+ for ( let i = 0 ; i < usermsg . length ; i ++ ) {
415+ if ( event . message . text . includes ( usermsg [ i ] ) ) {
416+ msg = { "type" : "text" , "text" : replymsgY [ Math . floor ( Math . random ( ) * replymsgY . length ) ] } ;
417+ check = true ;
418+ }
419+ }
420+
421+ if ( check == false ) {
422+ switch ( event . message . text ) {
423+ case "สีเหลือง" :
424+ msg = { "type" : "text" , "text" : "Yellow!" } ;
425+ break
426+ case "มะม่วง" :
427+ msg = { "type" : "text" , "text" : "Mango!" } ;
428+ break
429+ case "ห้ะ" :
430+ msg = { "type" : "text" , "text" : "ห้ะ!" } ;
431+ break
432+ default :
433+ msg = { "type" : "text" , "text" : replymsgX [ Math . floor ( Math . random ( ) * replymsgX . length ) ] } ;
434+ break
435+ }
436+ }
437+
438+ return client . replyMessage ( event . replyToken , msg ) ;
335439 }
336440}
337441const PORT = process . env . PORT || 3000 ;
0 commit comments