<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Devster Hiddenman on Medium]]></title>
        <description><![CDATA[Stories by Devster Hiddenman on Medium]]></description>
        <link>https://medium.com/@devster.hiddenman?source=rss-f80a492c73e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UWnI_p3AG9V1_8EG</url>
            <title>Stories by Devster Hiddenman on Medium</title>
            <link>https://medium.com/@devster.hiddenman?source=rss-f80a492c73e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:10:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devster.hiddenman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ตอนที่ 05 — รู้จัก Core Workflow Concepts แบบเพื่อนรีวิวให้ฟัง]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88-05-%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-core-workflow-concepts-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B8%A3%E0%B8%B5%E0%B8%A7%E0%B8%B4%E0%B8%A7%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B8%9F%E0%B8%B1%E0%B8%87-0511b81d859e?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/0511b81d859e</guid>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Tue, 03 Jun 2025 13:11:58 GMT</pubDate>
            <atom:updated>2025-06-03T13:12:45.583Z</atom:updated>
            <content:encoded><![CDATA[<h3>ตอนที่ 05 : รู้จัก Core Workflow Concepts แบบเพื่อนรีวิวให้ฟัง</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PALQPUiv-QRDzXQQyjgpfw.png" /></figure><p>พอเราเริ่มเล่น n8n ไปสักพัก จะเริ่มรู้สึกว่า “เอ๊ะ มันทำอะไรได้เยอะกว่าที่คิดแฮะ”<br> บทนี้จะพาไปรู้จักกับสิ่งที่เรียกว่า <strong>“แก่นของ Workflow”</strong> หรือสิ่งที่ทำให้งานเรา “อัตโนมัติ” แบบมีสเต็ป มีระเบียบ และไม่มั่ว (เหมือนเราเวลาเช้าวันจันทร์)</p><h3>🖼️ Workflow Canvas</h3><p>พื้นที่หลักที่เราจะได้ลาก เส้นต่อจุด วาง Node ทุกอย่างอยู่ในที่เรียกว่า <strong>Canvas</strong> (กระดานวาดแผน)</p><p>บนหน้านี้จะมีเมนูสำคัญ ๆ ที่ควรรู้:</p><ul><li><strong>ชื่อ &amp; Tags</strong> → ตั้งชื่อเวิร์กโฟลว์ และใส่แท็กให้จัดระเบียบง่าย</li><li><strong>Workflow Activation</strong> → เปิด/ปิด การทำงานของ Workflow</li><li><strong>Version History</strong> → อยากย้อนกลับเวอร์ชันก่อนหน้าได้มั้ย? ได้!</li><li><strong>Workflow Settings</strong> → ตั้งค่าการทำงานต่าง ๆ เช่น Retry, Timeout, Error Handling</li><li><strong>Nodes</strong> → ตัวกล่องเล็ก ๆ ที่ใช้ทำงานต่าง ๆ เช่น ดึงข้อมูล, ส่งไลน์, เชื่อม API ฯลฯ</li></ul><h3>📂 หน้า List รวม Workflow</h3><p>เวลามีหลายเวิร์กโฟลว์ เราสามารถดูรวมในหน้า List ได้เลย<br> มีข้อมูลสำคัญให้ดู:</p><ul><li>ชื่อเวิร์กโฟลว์ (Name)</li><li>แท็กที่กำหนดไว้ (Tags)</li><li>เจ้าของ (Owner)</li><li>วันที่แก้ไขล่าสุด (Last updated)</li></ul><h3>⚡ Trigger: จุดเริ่มต้นของทุก Workflow</h3><p>“ทุก Workflow ต้องเริ่มจาก Trigger”<br> Trigger คือสิ่งที่ “ปลุก Workflow” ให้ทำงาน เช่น</p><ul><li>มีคนส่งฟอร์ม</li><li>มีอีเมลเข้า</li><li>กำหนดให้ทำงานทุกเช้าวันจันทร์</li></ul><p><strong>Trigger Node</strong> จะไม่มีทางรับข้อมูลจากที่อื่น — มันคือจุดเริ่มต้น 100%<br> (เหมือนนาฬิกาปลุก ที่ปลุก workflow ทุกวันตอนตี 5 ☠️)</p><h3>🔗 Connecting Nodes: ต่อเส้นให้ระบบรู้จักกัน</h3><p>เวลาเราต่อ Node แต่ละตัวเข้าด้วยกัน มันก็คือการบอกว่า<br> <strong>“พอทำ Node A เสร็จ → ไปทำ Node B ต่อเลยนะ”</strong></p><p>→ คลิก Node แล้วลากเส้นไปต่อ<br> → หรือ Double click เข้าไปดูรายละเอียดของแต่ละ Node ได้</p><h3>🌿 Branching: แยกเส้นทางให้ทำหลายอย่างพร้อมกัน</h3><p>อยากให้ Workflow แตกออกเป็นหลายเส้นทาง? ทำได้ 2 วิธี:</p><ol><li>ใช้ Node ที่มีหลายทางออก เช่น IF, Switch</li><li>ลากเส้นออกจาก Node เดียวกันได้หลายเส้น</li></ol><p>เช่น<br> ถ้ามีคำสั่งซื้อใหม่ →<br> ✅ ส่งอีเมลหาทีม<br> ✅ สร้างเอกสารใน Google Drive<br> ✅ แจ้งทีมใน Slack</p><p>ทั้งหมดนี้ทำพร้อมกันได้เลย!</p><h3>🔁 Branch Outputs</h3><p>เวลามีหลาย Output → ระบบจะสร้าง “หลาย output item”<br> คือมันจะถือว่าทุกเส้นคือ Task แยกกัน<br> อยากให้ไปคนละทาง → ก็แยกเส้นซะ!</p><h3>💡สรุปสั้น ๆ (ไว้เมาท์กับเพื่อนได้)</h3><ul><li>Canvas = พื้นที่ทำงานหลักของเรา</li><li>Workflow เริ่มจาก Trigger เสมอ</li><li>ต่อ Node ให้ครบ ลากเส้นให้ถูก</li><li>แยก Branch ได้ถ้าต้องทำงานหลายอย่างพร้อมกัน</li><li>เปิด/ปิด workflow ได้เหมือนสวิตช์</li><li>n8n ทำให้เราไม่ต้องคลิกซ้ำ ๆ ให้เหนื่อยอีกต่อไป ✨</li></ul><blockquote><em>พื้นที่โฆษณาชวนเชื่อ* Seed Edition 🌱 — บทความนี้ อาจจะเน้นแค่เนื้อหาแบบข้อความเป็นหลัก แต่ก็มีความตั้งใจอยากจะใส่ตัวอย่างภาพประกอบให้เข้าใจมากขึ้นอีกภายหลัง โดยหวังว่าเผื่อมีคนหลงมาอ่านแล้วจะเป็นประโยชน์ แต่อาจจะรีบเขียนไปหน่อยเพราะไม่อยากปล่อยให้ไอเดียมันหลุดลอย 😅 หากผ่านมาอีกทีหวังว่าจะได้เห็นเป็น Harvest Edition 🌾 นะครับ</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0511b81d859e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[บทที่ 4: n8n จัดการข้อมูลยังไง? — ไหนเพื่อนเล่าสิ]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%9A%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88-4-n8n-%E0%B8%88%E0%B8%B1%E0%B8%94%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%A2%E0%B8%B1%E0%B8%87%E0%B9%84%E0%B8%87-%E0%B9%84%E0%B8%AB%E0%B8%99%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%A5%E0%B9%88%E0%B8%B2%E0%B8%AA%E0%B8%B4-1f0ec17dadb2?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f0ec17dadb2</guid>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Tue, 03 Jun 2025 04:00:50 GMT</pubDate>
            <atom:updated>2025-06-03T04:00:50.681Z</atom:updated>
            <content:encoded><![CDATA[<h3>บทที่ 4: n8n จัดการข้อมูลยังไง? — ไหนเพื่อนเล่าสิ</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYDsJrAxBnvg5XVcYG8PTw.png" /></figure><p>เวลาเราใช้ n8n สร้าง workflow ข้อมูลจะวิ่งจาก node หนึ่งไปยังอีก node หนึ่ง<br> แต่ข้อมูลที่ไหลอยู่นั้น “หน้าตา” เป็นยังไง? แล้วเราจะใช้งานมันยังไง?</p><p>บทนี้มาคุยเรื่องนี้กันแบบ นั่งจิบเบียร์แล้วเชียร์บอลกันเลยดีกว่า 😄</p><h3>🔹 JSON คืออะไร?</h3><p>JSON (อ่านว่า เจสัน) คือรูปแบบข้อมูลที่ n8n ใช้เป็นหลัก<br> มันคือข้อมูลที่อยู่ในรูปแบบ “ชื่อ — ค่า” เช่น:</p><pre>{<br>  &quot;name&quot;: &quot;Max&quot;,<br>  &quot;email&quot;: &quot;max@example.com&quot;<br>}</pre><p>ข้อมูลแบบนี้เรียกว่า <strong>1 item</strong> หรือ 1 ก้อนข้อมูล<br>เป็นหน่วยเล็กที่สุดที่ node จะรับและประมวลผล</p><h3>🔹 List คืออะไร?</h3><p>List คือชุดของ item หลายๆ อันรวมกัน<br>เช่น ถ้าเรามีข้อมูลลูกค้า 3 คน มันจะออกมาประมาณนี้:</p><pre>[<br>  { &quot;name&quot;: &quot;A&quot;, &quot;age&quot;: 30 },<br>  { &quot;name&quot;: &quot;B&quot;, &quot;age&quot;: 25 },<br>  { &quot;name&quot;: &quot;C&quot;, &quot;age&quot;: 20 }<br>]</pre><p>เราเรียกสิ่งนี้ว่า <strong>List of JSON</strong> หรือพูดง่ายๆ ว่า “ข้อมูลหลายแถว”<br>แต่ละ JSON ก็คือแถวหนึ่ง หรือ row หนึ่งในมุมมองของ n8n</p><h3>🔹 Node จัดการกับข้อมูลยังไง?</h3><p>ทุก node (ส่วนใหญ่) จะทำงาน <strong>ทีละ item</strong><br> เช่น ถ้าเราได้รับข้อมูลมา 5 item → node จะวนทำงาน 5 ครั้ง (ครั้งละ 1 item)</p><p><strong>หมายเหตุ:</strong> มีบาง node ที่ไม่ทำงานแบบนี้ เช่น Merge, Wait, หรือ IF บางกรณี</p><h3>🔹 เข้าถึงข้อมูลยังไง?</h3><p>เราสามารถดึงข้อมูลจาก item ปัจจุบันมาใช้งานได้โดยใช้ expression เช่น:</p><pre>{{$json.name}}</pre><p>ตัวอย่างเช่น ถ้าใน item มีข้อมูลแบบนี้:</p><pre>{ &quot;name&quot;: &quot;Bank&quot;, &quot;score&quot;: 90 }</pre><p>แล้วเราเขียน:</p><pre>Hello {{$json.name}}! Your score is {{$json.score}}.</pre><p>ผลลัพธ์ก็จะออกมาเป็น:</p><pre>Hello Bank! Your score is 90.</pre><h3>🔹 Expressions คืออะไร?</h3><p>Expressions คือคำสั่งแบบผสม ที่ให้เราใส่ตัวแปร ข้อความ และโค้ด JavaScript เล็กๆ ได้</p><p>ตัวอย่าง:</p><pre>{{ $json.score &gt; 80 ? &quot;Passed&quot; : &quot;Failed&quot; }}</pre><p>ในที่นี้ ถ้า score มากกว่า 80 จะแสดงคำว่า “Passed” ถ้าไม่ใช่จะแสดง “Failed”</p><p>Expressions ทำให้เรายืดหยุ่นมากในการตั้งค่าเงื่อนไขหรือปรับค่าที่จะแสดง</p><h3>🧠 สรุปสั้นๆ</h3><ul><li>n8n ใช้ JSON เป็นรูปแบบข้อมูลหลัก</li><li>1 JSON = 1 item = 1 ชุดข้อมูล</li><li>Node ส่วนใหญ่จะทำงานวนทีละ item</li><li>เข้าถึงข้อมูลด้วย {{$json.key}} เช่น {{$json.email}}</li><li>Expressions ช่วยให้รวมข้อความ + ตัวแปร + โค้ดได้ในที่เดียว</li></ul><blockquote><em>พื้นที่โฆษณาชวนเชื่อ* Seed Edition 🌱 — บทความนี้ อาจจะเน้นแค่เนื้อหาแบบข้อความเป็นหลัก แต่ก็มีความตั้งใจอยากจะใส่ตัวอย่างภาพประกอบให้เข้าใจมากขึ้นอีกภายหลัง โดยหวังว่าเผื่อมีคนหลงมาอ่านแล้วจะเป็นประโยชน์ แต่อาจจะรีบเขียนไปหน่อยเพราะไม่อยากปล่อยให้ไอเดียมันหลุดลอย 😅 หากผ่านมาอีกทีหวังว่าจะได้เห็นเป็น Harvest Edition 🌾 นะครับ</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f0ec17dadb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[บทที่ 3: n8n Node คืออะไร? แมนๆเพื่อนคุยกัน]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%9A%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88-3-n8n-node-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%81%E0%B8%A1%E0%B8%99%E0%B9%86%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B8%84%E0%B8%B8%E0%B8%A2%E0%B8%81%E0%B8%B1%E0%B8%99-882e38612780?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/882e38612780</guid>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Tue, 03 Jun 2025 03:23:05 GMT</pubDate>
            <atom:updated>2025-06-03T04:03:02.527Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4YvJEJZkZIAcz4WMKgQhg.png" /></figure><h3>🧩 Node คืออะไรใน n8n?</h3><p>ลองนึกภาพว่าเราอยากให้คอมมันทำงานแทนเราแบบอัตโนมัติ เช่น พอมีอีเมลเข้า ก็ให้มันเอาข้อมูลไปเก็บใน Google Sheet แล้วส่งแจ้งเตือนในไลน์<br> <strong>n8n</strong> ก็คือเครื่องมือที่ช่วยให้เราทำแบบนี้ได้ โดยไม่ต้องเขียนโค้ดยากๆ</p><p>แล้วตัวหลักที่เราจะใช้งานก็คือ <strong>“Node”</strong></p><h3>🧱 Node คืออะไร?</h3><p><strong>Node</strong> ก็เหมือน “กล่องคำสั่ง” หรือ “ตัวต่อเลโก้” แต่ละชิ้นมีหน้าที่ต่างกัน<br> เราจะเอา node เหล่านี้มาต่อกันเป็นลำดับขั้นตอนให้มันทำงานแบบอัตโนมัติ</p><h3>📦 Node มีกี่ประเภท?</h3><h3>แบ่งง่ายๆ เป็น 3 กลุ่ม:</h3><p><strong>1.Entry Point</strong> — จุดเริ่มของ workflow</p><p>ตัวอย่าง: ใช้ node ชื่อว่า <strong>“Cron”</strong> ตั้งเวลาให้ workflow ทำงานทุกวันตอน 9 โมง</p><p><strong>2.Function / Processing</strong> — โหนดกลางๆ ที่ช่วยจัดการข้อมูล</p><p>ตัวอย่าง: ใช้ node <strong>“Set”</strong> เพื่อจัดข้อมูลให้อยู่ในรูปแบบที่ต้องการ เช่น ตั้งชื่อ field ใหม่</p><p><strong>3.Exit Point</strong> — จุดจบ workflow</p><p>ตัวอย่าง: ใช้ node <strong>“Gmail”</strong> ส่งอีเมล หรือ <strong>“Google Sheets”</strong> เพิ่มข้อมูลลงตาราง</p><h3>🔧 Node มีหลายประเภทให้เลือก</h3><p><strong>Trigger</strong> → เริ่ม workflow อัตโนมัติ เช่น ใช้ node <strong>“Webhook”</strong> รับข้อมูลจากฟอร์มที่คนกรอก</p><p><strong>Action</strong> → ทำบางอย่างในแอป เช่น node <strong>“Notion”</strong> เพื่อเพิ่ม note ใหม่เข้าไปในฐานข้อมูล</p><p><strong>Data Transformation</strong> → แปลงหรือจัดข้อมูล เช่นใช้ node <strong>“Function”</strong> เขียนโค้ดเล็กๆ แก้ไขข้อมูลก่อนส่งออก</p><p><strong>Flow</strong> → ควบคุมทิศทาง เช่น If-Else เช่น node <strong>“IF”</strong> เช็คว่าอีเมลที่เข้ามามีคำว่า “ด่วน” มั้ย ถ้ามีก็ค่อยส่งไลน์</p><p><strong>File &amp; Advanced</strong> → พวกไฟล์หรือโค้ดเฉพาะทาง เช่น node <strong>“Read Binary File”</strong> สำหรับเปิดไฟล์แนบจากอีเมล</p><h3>👇 ใช้งานยังไง?</h3><p>แค่ลาก node มาวางในหน้า canvas แล้วต่อเส้นเชื่อมกัน เหมือนเล่น flow chart<br> เช่น:</p><pre>[Webhook] ─▶ [Function (แก้ข้อมูล)] ─▶ [Google Sheets (เก็บข้อมูล)]</pre><h3>📍 เวลาเรา “คลิก” ที่ Node จะทำอะไรได้บ้าง?</h3><p>▶️ <strong>Execute</strong> → ทดสอบว่า node ทำงานถูกมั้ย</p><p>⚙️ <strong>Open settings</strong> → เปิดหน้าตั้งค่า เช่น ใส่ค่า, เชื่อมบัญชี</p><p>✏️ <strong>Rename</strong> → ตั้งชื่อ node เช่น “ตรวจอีเมล” จะได้หาง่าย</p><p>⏸️ <strong>Deactivate</strong> → ปิดชั่วคราว เผื่ออยากข้าม node ไปก่อน</p><p>📋 <strong>Copy / Duplicate</strong> → ถ้าอยากใช้ node เดิมอีก</p><p>🗑️ <strong>Delete</strong> → ลบทิ้ง</p><h3>🔐 Credentials คืออะไร?</h3><p>ก็คือพวกข้อมูลบัญชีที่ต้องใช้เชื่อมกับบริการต่างๆ เช่น Google, Notion, Facebook ฯลฯ เราจะต้อง login ผ่าน node ที่ต้องใช้บริการนั้นๆ</p><blockquote><em>ตัวอย่าง: ถ้าใช้ node </em><strong><em>“Google Sheets”</em></strong><em> ก็ต้องมี credential สำหรับบัญชี Google ที่เข้าถึงสเปรดชีตได้</em></blockquote><h3>🧾 ดูข้อมูลยังไงหลังจากรัน node?</h3><ul><li><strong>Table View</strong> — เห็นเป็นตาราง เหมือน Excel</li><li><strong>JSON View</strong> — เห็นโค้ดดิบของข้อมูล เหมาะกับ dev</li><li><strong>Schema View</strong> — เห็นโครงสร้างว่ามี field อะไรบ้าง</li></ul><blockquote><em>เช่น หลังจากรัน webhook แล้ว เราอาจจะเห็นข้อมูลแบบนี้ใน JSON view:</em></blockquote><pre>{<br>  &quot;name&quot;: &quot;john doe&quot;,<br>  &quot;email&quot;: &quot;john.doe@example.com&quot;,<br>  &quot;message&quot;: &quot;ขอใบเสนอราคา&quot;<br>}</pre><h3>🧠 สรุปสั้นง่ายๆ</h3><p><strong>Node คืออะไร</strong><br> ▸ กล่องคำสั่งใน n8n ที่เราลากมาต่อกันให้มันทำงานแทนเรา</p><p><strong>ใช้ยังไง</strong><br> ▸ ลากมาวาง → ตั้งค่า → ต่อเส้น → กด Run</p><p><strong>มีกี่แบบ</strong><br> ▸ Trigger (เริ่มต้น)<br> ▸ Action (สั่งให้ทำงาน)<br> ▸ Function (แปลงข้อมูล)<br> ▸ IF (เลือกทางตามเงื่อนไข)</p><p><strong>ตัวอย่าง Flow</strong><br> ▸ [Webhook รับฟอร์ม] → [Function จัดรูปแบบข้อมูล] → [Gmail ส่งแจ้งเตือน]</p><p><strong>Credentials คืออะไร</strong><br> ▸ ข้อมูลบัญชี เช่น Gmail หรือ Google Sheet ที่ต้อง login เพื่อให้ node ใช้งานได้</p><p><strong>ดูผลยังไง</strong><br> ▸ ดูผลลัพธ์ได้ทั้งแบบ Table View, JSON View หรือ Schema View</p><blockquote><em>พื้นที่โฆษณาชวนเชื่อ* Seed Edition 🌱 — บทความนี้ อาจจะเน้นแค่เนื้อหาแบบข้อความเป็นหลัก แต่ก็มีความตั้งใจอยากจะใส่ตัวอย่างภาพประกอบให้เข้าใจมากขึ้นอีกภายหลัง โดยหวังว่าเผื่อมีคนหลงมาอ่านแล้วจะเป็นประโยชน์ แต่อาจจะรีบเขียนไปหน่อยเพราะไม่อยากปล่อยให้ไอเดียมันหลุดลอย 😅 หากผ่านมาอีกทีหวังว่าจะได้เห็นเป็น Harvest Edition 🌾 นะครับ</em></blockquote><p>หากยังไหวก็ไปกันต่ออออ <a href="https://medium.com/@devster.hiddenman/%E0%B8%9A%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88-4-n8n-%E0%B8%88%E0%B8%B1%E0%B8%94%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%A2%E0%B8%B1%E0%B8%87%E0%B9%84%E0%B8%87-%E0%B9%84%E0%B8%AB%E0%B8%99%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%A5%E0%B9%88%E0%B8%B2%E0%B8%AA%E0%B8%B4-1f0ec17dadb2">ถัดไป</a> 🚙 💨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=882e38612780" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[บทที่ 2: n8n API กับ Webhook คืออะไร แบบเพื่อนช่วยติว?]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%9A%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88-2-api-%E0%B8%81%E0%B8%B1%E0%B8%9A-webhook-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B8%8A%E0%B9%88%E0%B8%A7%E0%B8%A2%E0%B8%95%E0%B8%B4%E0%B8%A7-1496e2a835fe?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1496e2a835fe</guid>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Sun, 01 Jun 2025 04:23:44 GMT</pubDate>
            <atom:updated>2025-06-03T03:25:38.382Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kspT-RSfnM1uutkGMBotGA.png" /></figure><h3>🥢 API คืออะไร?</h3><p>ลองนึกภาพว่าเราไปกินข้าวในร้านอาหาร</p><ul><li>เราคือ “ผู้ใช้งานที่หิวข้าว”</li><li>ครัวคือ “ระบบหลังบ้าน”</li><li>ส่วน <strong>API ก็คือพนักงานเสิร์ฟ</strong> ที่เป็นตัวกลางระหว่างเรากับครัว</li></ul><p>เวลาเราจะสั่งอาหาร เราไม่ได้เดินเข้าไปในครัวเองใช่ไหม<br>เรายื่นเมนูให้พนักงาน → เขาก็จัดการต่อให้หมด <strong>API ก็ทำหน้าที่แบบนั้นเลย</strong></p><h3>🎮 API ใช้ทำอะไรบ้าง?</h3><p>คนส่วนใหญ่มักเข้าใจว่า API คือ “ขอข้อมูลจากระบบ” อย่างเดียว<br> แต่จริง ๆ แล้ว API ใช้ได้หลายแบบเลยนะ:</p><ul><li>✅ ขอข้อมูล (GET) → เช่น ขอรายชื่อลูกค้า</li><li>📝 ส่งข้อมูลใหม่ (POST) → เช่น เพิ่มผู้ใช้งานใหม่เข้าในระบบ</li><li>✏️ แก้ไขข้อมูล (PUT / PATCH) → เช่น เปลี่ยนอีเมลของลูกค้า</li><li>❌ ลบข้อมูล (DELETE) → เช่น ลบคำสั่งซื้อเก่าออก</li></ul><p><strong>📌 เราไม่ได้แค่ “เรียกดู” — แต่ยัง “สั่งให้ทำอะไรบางอย่าง” ได้ด้วย</strong></p><h3>🧾 เวลาระบบเรียก API มีอะไรบ้าง?</h3><p>เวลาส่ง request ไปที่ API จะมี 4 ส่วนหลัก ๆ:</p><ol><li><strong>URL</strong> — บอกว่าจะไปติดต่อใคร (เว็บไหน, endpoint อะไร)</li><li><strong>Method</strong> — บอกว่าเราจะ “ขอข้อมูล”, “เพิ่ม”, “แก้”, หรือ “ลบ”</li><li><strong>Header</strong> — รายละเอียดอื่น ๆ เช่น ภาษา, ประเภทข้อมูล</li><li><strong>Body</strong> — ใส่ข้อมูลที่อยากส่งไป เช่น ฟอร์มสมัครสมาชิก</li></ol><p>และบางครั้งก็ต้องมี <strong>Authorization</strong> เช่น token หรือ API key ด้วย<br> กันไม่ให้ใครแอบเข้ามาเรียกมั่ว ๆ</p><h3>📦 แล้ว API ตอบกลับมายังไง?</h3><p>เวลา API ตอบกลับ เราจะได้ “Response” ซึ่งมี:</p><ul><li><strong>Status code</strong><br> 200 OK = ผ่านฉลุย<br> 404 Not Found = ไม่เจอจ้า<br> 500 Internal Server Error = ฝั่งนั้นงอแง</li><li><strong>Header</strong> — ข้อมูลเพิ่มเติม เช่น ไฟล์ชนิดอะไร, ขนาดเท่าไหร่</li><li><strong>Body</strong> — ข้อมูลจริง เช่น รายชื่อสินค้าใน JSON</li></ul><h3>🔔 แล้ว Webhook คืออะไร?</h3><p>API = เราไปเรียกเขา<br> <strong>Webhook = เขาเรียกเรากลับ เมื่อมีบางอย่างเกิดขึ้น</strong></p><p>ลองนึกภาพว่าเราเปิดร้านรับจองห้องประชุมออนไลน์<br> มีระบบจองของบริษัทลูกค้า A<br> → ถ้าลูกค้า A มีคนจองห้องใหม่ ระบบเขาก็ยิง Webhook มาหาเราว่า</p><blockquote><em>“มีคนจองใหม่แล้วนะ! ห้อง 401 เวลา 10:00”</em></blockquote><p>เราไม่ต้องไปนั่งกดรีเฟรชระบบเขาทุก 5 วิ<br> แค่เปิดรอไว้ → ถ้ามีอะไรเกิดขึ้น เขาจะ “ส่งเสียงกริ่ง” มาบอกเราเอง</p><h3>📌 ตัวอย่าง Webhook ที่เจอในชีวิตจริง</h3><ul><li>ระบบ e-learning ส่ง webhook หาทุกครั้งที่มีคนเรียนจบคอร์ส → เราออกใบ certificate ให้อัตโนมัติ</li><li>ระบบแชตแจ้งผ่าน webhook ถ้ามีคนส่งข้อความเข้ามา → เราเก็บข้อความไว้ตอบทีหลัง</li><li>มีคน submit แบบฟอร์ม → ระบบยิง webhook มาแจ้งเราให้บันทึกข้อมูลลง Google Sheet</li></ul><h3>🧠 สรุปเลยสั้นๆ</h3><p><strong>API คืออะไร?</strong><br> คือการที่ “เราต้องเป็นฝ่ายไปขอข้อมูล” หรือสั่งให้ระบบทำอะไรบางอย่าง เช่น ขอรายชื่อลูกค้า เพิ่มคำสั่งซื้อ แก้ไขข้อมูล ฯลฯ เหมือนกับเวลาเราไปร้านอาหาร แล้วเราต้องเป็นคนสั่งก่อนถึงจะได้อาหาร</p><p><strong>Webhook คืออะไร?</strong><br>Webhook จะต่างออกไป เพราะมันคือการที่ “ระบบเขาเป็นฝ่ายแจ้งเราก่อน” เมื่อมีอะไรเกิดขึ้น เช่น มีคนกรอกฟอร์ม มีการชำระเงิน หรือมีอีเวนต์อะไรบางอย่าง<br>เหมือนกับมี “กริ่งแจ้งเตือน” เวลาอาหารเสร็จ แล้วร้านบอกเราว่า “เฮ้ พร้อมแล้วนะ!”</p><p><strong>สรุปเลยแบบตัวอย่างที่สั้นกว่า ๆ:</strong></p><ul><li>API = เราเป็นฝ่ายขอ → ใช้เมื่อเราต้องการข้อมูลหรือสั่งให้ระบบทำอะไร</li><li>Webhook = เขาเป็นฝ่ายส่งมา → ใช้เมื่ออยากให้ระบบแจ้งเราทันทีที่มีอะไรเกิดขึ้น</li></ul><p>หากยังไม่เบื่อก็ <a href="https://medium.com/@devster.hiddenman/%E0%B8%9A%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88-3-n8n-node-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%81%E0%B8%A1%E0%B8%99%E0%B9%86%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B8%84%E0%B8%B8%E0%B8%A2%E0%B8%81%E0%B8%B1%E0%B8%99-882e38612780">ไปกันต่อ</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1496e2a835fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[บทที่ 1: Automation แบบเพื่อนเล่าให้ฟัง]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%9A%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88-1-automation-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%A5%E0%B9%88%E0%B8%B2%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B8%9F%E0%B8%B1%E0%B8%87-132380c38a2a?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/132380c38a2a</guid>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Sat, 31 May 2025 04:00:39 GMT</pubDate>
            <atom:updated>2025-06-03T03:27:30.320Z</atom:updated>
            <content:encoded><![CDATA[<h3>บทที่ 1: n8n Automation แบบเพื่อนเล่าให้ฟัง</h3><blockquote>Automation Definition<br> A predictable set of predetermined actions that transfers data from one point to another</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*szkiG0QD7cgJAyFExnfmNw.png" /></figure><h3>🧠 ทำไมต้อง Automation?</h3><p>เคยไหม…</p><p>📆 ทุกวันศุกร์ = วันรวมรายงาน<br>🧮 ก็อปยอดรายงานจาก A → B → C → รวมสูตร → เช็กยอดให้ถูก</p><p>⌛ ผ่านไป 2 ชั่วโมง:<br> “เสร็จแล้วเว้ย… แต่เหมือนเดิมทุกอาทิตย์เลยหงะ” 😵‍💫<br> (พูดปลอบใจจากคนผู้ใช้ความแมนนวล ตลอดเวลาฮ่า ๆ)</p><p>เมื่องานมันวนลูปแบบนี้…<br> ถึงเวลาแล้วสินะที่จะต้องอัพระดับความเท่ห์ ลองเปิดใจให้ <strong>Automation (ระบบอัตโนมัติ)</strong> มาช่วย ชีวิตนี้จะต้องเปลี่ยนไป?</p><p>🧹 ให้คอมฯมาช่วย จัดการงานซ้ำซาก<br> 🧠 แล้วเราก็จะได้เอาเวลามาคิดอะไรใหม่ ๆ<br> 📱 หรือจะแอบไถ TikTok ดูคลิปน้องแมวเต้น…ก็ไม่รู้สึกผิด เพราะงานมีคนทำให้แล้ว วู้ฮู้ววว! 🤣</p><p>ก่อนจะใช้งานมาเริ่มปูพื้นฐานรู้จัก Automation แบบเท่ห์ๆ คูลๆ กันก่อนดีกว่า</p><h3>🤖<strong> Automation คืออะไร?</strong></h3><p>คิดง่าย ๆ คือ “สั่งให้ระบบทำงานแทนเราแบบอัตโนมัติ”</p><p><strong>นิยามเท่ห์ ๆ:</strong></p><p>การกระทำที่เป็นลำดับแน่นอน (predictable) เพื่อย้ายหรือจัดการข้อมูลจากจุด A ไปจุด B</p><p><strong>ตัวอย่างง่าย ๆ:</strong></p><ul><li>มีอีเมลเข้า → ดึงไฟล์แนบ → เซฟลง Google Drive → แจ้งทีมใน Slack<br> 💬 “ไฟล์มาแล้วจ้าาาา 📩 อย่างเฟี้ยว”</li></ul><h3><strong>🔑 Core Concepts (หัวใจของ Automation)</strong></h3><p><strong>1. Trigger (ตัวกระตุ้น)</strong></p><p>คือจุดเริ่มต้นของการทำงาน<br> เช่น:</p><ul><li>มีคนส่งฟอร์ม (เช่น Google Forms)</li><li>ตั้งเวลาไว้ (Scheduled เช่น ทุก 9 โมงเช้า)</li><li>คลิกปุ่มเอง (Manual)</li></ul><p><strong>2. Filtering (คัดกรอง)</strong></p><p>เช่น ข้อมูลที่มามีคำว่า “ด่วน” ไหม?<br> ถ้าใช่ → ไปแจ้งหัวหน้า<br> ถ้าไม่ใช่ → ไปเก็บไว้เฉย ๆ</p><p><strong>3. Actions (การกระทำ)</strong></p><p>ระบบจะทำอะไรต่อ เช่น ส่งเมล, เซฟไฟล์, แปะใน Excel, ยิงแจ้งเตือน ฯลฯ</p><h3><strong>🧩 Workflow คืออะไร?</strong></h3><p>คือ “สายพาน” ที่พา Trigger → ไปคัดกรอง → แปลงข้อมูล → ทำ Action ต่าง ๆ</p><p><strong>ตัวอย่าง:</strong></p><p>แบบฟอร์มลูกค้า → ตรวจว่าอีเมลถูกไหม → เพิ่มเข้า Google Sheet → ส่ง Welcome Email</p><p>✅<strong> Automation Best Practices</strong></p><p><strong>Mapping คือพระเอก</strong></p><p>ก่อนทำ automation ต้อง “แมพ” ให้ดีว่าข้อมูลจากตรงไหน → ต้องไปไหน<br> เช่น:</p><ul><li>ช่องชื่อ → จะไปลง Google Sheet ช่องไหน</li><li>หมายเลขโทรศัพท์ → จะส่งเข้า LINE แบบไหน</li></ul><p><strong>คิดให้ชัด = ลดความงง ลดความพัง!</strong></p><h3><strong>สรุปสั้น ๆ</strong></h3><ul><li>Automation = ให้ระบบช่วยทำงานแทนเรา</li><li>เริ่มจาก Trigger → ผ่าน Filter → แล้วทำ Action</li><li>คิด Mapping ให้ดี = Automation จะเนียนเหมือนเวทมนตร์ 🧙‍♂️</li></ul><p>หากยังไม่เบื่อกันไปตามต่อ<a href="https://medium.com/@devster.hiddenman/%E0%B8%9A%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88-2-api-%E0%B8%81%E0%B8%B1%E0%B8%9A-webhook-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%99%E0%B8%8A%E0%B9%88%E0%B8%A7%E0%B8%A2%E0%B8%95%E0%B8%B4%E0%B8%A7-1496e2a835fe">บทที่ 2</a> ได้นะ 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=132380c38a2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ลองใช้ LINE Messaging API SDK for Python สร้างบอทใช้ร่วมกับ EX10 Chat Center]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%A5%E0%B8%AD%E0%B8%87%E0%B9%83%E0%B8%8A%E0%B9%89-line-messaging-api-sdk-for-python-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%9A%E0%B8%AD%E0%B8%97%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%A3%E0%B9%88%E0%B8%A7%E0%B8%A1%E0%B8%81%E0%B8%B1%E0%B8%9A-ex10-chat-center-912c20257bcc?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/912c20257bcc</guid>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Mon, 11 Mar 2024 04:32:30 GMT</pubDate>
            <atom:updated>2024-03-11T04:32:30.132Z</atom:updated>
            <content:encoded><![CDATA[<p>มาลองทำบอทง่ายๆอีกแล้วจ้า ซึ่งยังจะเป็นการเชื่อมต่อ LINE Bot เข้ากับการใช้งาน EX10 Chat Center เหมือนเคย แต่รอบนี้จะเป็นตัวอย่างการใช้ <a href="https://github.com/line/line-bot-sdk-python">line-bot-sdk-python</a> ครับ เผื่อเป็นประโยชน์เลยลองทำตัวอย่างมาให้ดู ไม่เกริ่นให้เสียเวลา ลองไปดูตามด้านล่างได้เลยจ้า 😉</p><p>ผมใช้ Flask ที่เป็นเฟรมเวิร์กในการสร้างและรันเซิร์ฟเวอร์ (จริงๆก็ลอกจากหน้า github มาเลยครับ) นอกจากนี้ยังใช้ไลบรารี line-bot-sdk เพื่อให้สามารถส่งข้อความกลับไปยังไลน์ได้ ดังนั้นคุณต้องติดตั้งไลบรารีเหล่านี้โดยใช้คำสั่ง pip install ก่อนที่จะรันโปรแกรม:</p><ol><li>Flask: เฟรมเวิร์ก Python สำหรับการสร้างเว็บแอปพลิเคชัน</li></ol><pre>pip install flask</pre><p>2. line-bot-sdk: ไลบรารีที่ใช้ในการส่งข้อความกลับไปยังไลน์</p><pre>pip install line-bot-sdk</pre><p>3. dotenv: ไลบรารีที่ใช้ในการโหลดข้อมูลจากไฟล์ .env</p><pre>pip install python-dotenv</pre><pre>from flask import Flask, request, abort<br>from linebot import LineBotApi, WebhookHandler<br>from linebot.exceptions import InvalidSignatureError<br>from linebot.models import (<br>    MessageEvent,<br>    TextMessage,<br>    TextSendMessage,<br>    StickerMessage,<br>    StickerSendMessage,<br>)<br><br>import os<br>from dotenv import load_dotenv<br><br># โหลดไฟล์ .env เพื่อเรียกใช้ข้อมูลจาก Environment Variables<br>load_dotenv()<br><br>app = Flask(__name__)<br><br># กำหนดค่า Channel Access Token และ Channel Secret ของเรา<br>CHANNEL_ACCESS_TOKEN = os.getenv(&quot;CHANNEL_ACCESS_TOKEN&quot;)<br>CHANNEL_SECRET = os.getenv(&quot;CHANNEL_SECRET&quot;)<br><br># สร้าง LineBotApi และ WebhookHandler<br>line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN)<br>handler = WebhookHandler(CHANNEL_SECRET)<br><br>@app.route(&quot;/&quot;, methods=[&quot;GET&quot;])<br>def init():<br>    return &quot;LINE Chatbot Python!&quot;<br><br>@app.route(&quot;/webhook&quot;, methods=[&quot;POST&quot;])<br>def webhook():<br>    # รับข้อมูลจาก Webhook<br>    signature = request.headers[&quot;X-Line-Signature&quot;]<br>    body = request.get_data(as_text=True)<br>    app.logger.info(&quot;Request body: &quot; + body)<br><br>    try:<br>        # ตรวจสอบลายเซ็นเจอร์ของข้อมูล<br>        handler.handle(body, signature)<br>    except InvalidSignatureError:<br>        # กรณีไม่สามารถตรวจสอบลายเซ็นเจอร์ได้ จะส่งโค้ด 400 กลับไป<br>        abort(400)<br><br>    return &quot;OK&quot;, 200<br><br># ฟังก์ชันสำหรับการตอบกลับข้อความ<br>def switch_case(argument):<br>    if argument == &quot;สีเหลือง&quot;:<br>        return &quot;เยลโล่ว 💛&quot;<br>    elif argument == &quot;มะม่วง&quot;:<br>        return &quot;แมงโก้ 🥭&quot;<br>    elif argument == &quot;มีด&quot;:<br>        return &quot;อีโต้ 🗡️&quot;<br>    elif argument == &quot;ไฟแช๊ค&quot;:<br>        return &quot;ซิปโป้ 🔥&quot;<br>    else:<br>        return &quot;😅 ขอโทษทีฉันไม่เข้าใจนะ&quot;<br><br># ฟังก์ชันสำหรับการจัดการกับข้อความ<br>@handler.add(MessageEvent, message=TextMessage)<br>def handle_message(event):<br>    try:<br>        # ดึงข้อความจากอีเวนท์<br>        text = event.message.text<br>        reply_text = switch_case(text)<br>        # ส่งข้อความตอบกลับ<br>        line_bot_api.reply_message(event.reply_token, TextSendMessage(text=reply_text))<br>    except Exception as e:<br>        print(f&quot;Error handling text message: {e}&quot;)<br><br># ฟังก์ชันสำหรับการจัดการกับสติกเกอร์<br>@handler.add(MessageEvent, message=StickerMessage)<br>def handle_sticker_message(event):<br>    try:<br>        # ดึงข้อมูลของสติกเกอร์<br>        sticker_id = event.message.sticker_id<br>        package_id = event.message.package_id<br>        # ส่งสติกเกอร์ตอบกลับ<br>        line_bot_api.reply_message(<br>            event.reply_token,<br>            StickerSendMessage(package_id=package_id, sticker_id=sticker_id),<br>        )<br><br>    except Exception as e:<br>        print(f&quot;Error handling sticker message: {e}&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    # รันเซิร์ฟเวอร์ Flask บน localhost พร้อมเปิดใช้งานโหมด Debug<br>    app.run(debug=True)CHANNEL_ACCESS_TOKEN={YOUR_LINE_CHANNEL_ACCESS_TOKEN}<br>CHANNEL_SECRET={YOUR_LINE_CHANNEL_SECRET}</pre><p>ไฟล์ .env</p><pre>CHANNEL_ACCESS_TOKEN={YOUR_LINE_CHANNEL_ACCESS_TOKEN}<br>CHANNEL_SECRET={YOUR_LINE_CHANNEL_SECRET}</pre><p>โค้ดนี้มีสองไฟล์ครับ main.py (ทำทุกอย่างเลยจ้าา) กับ .env (เก็บข้อมูล CHANNEL_ACCESS_TOKE และ CHANNEL_SECRET) ใช้ Flask เพื่อสร้างเซิร์ฟเวอร์และรับคำขอจากไลน์ผ่าน Webhook จากนั้นจึงตอบกลับข้อความหรือสติกเกอร์ที่ถูกส่งเข้ามา</p><p>โดยการใช้งาน Channel Access Token และ Channel Secret ที่ได้รับจากแพลตฟอร์มไลน์ในการติดต่อกับไลน์ API ซึ่งช่วยในการส่งและรับข้อความ</p><p>และการตรวจสอบลายเซ็นเจอร์เพื่อป้องกันการโจมตี CSRF ด้วย InvalidSignatureError ของไลน์บอท API ในการตอบกลับ ซึ่งอันนี้ EX10 Chat Center จะทำการสร้างและแนบมาให้ใน header ครับ<br>signature = request.headers[“X-Line-Signature”]</p><p>นอกจากนี้ยังมีตัวอย่างง่ายๆ อีกนิดหน่อยสำหรับฟังก์ชันสำหรับการจัดการกับข้อความและสติกเกอร์ที่ถูกส่งเข้ามาด้วย ซึ่งสามารถตอบกลับด้วยข้อความหรือสติกเกอร์ที่แสดงข้อความ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*EH2bxnI3m5CZw_PmeUhX5w.png" /><figcaption>รูปแบบการทำงานของโค้ดชุดแรก ให้ LINE เป็นคนตอบ</figcaption></figure><p>รูปแบบการทำงานก็จะเป็นตามภาพบนเลยครับ เรามั่นใจได้ว่าข้อความเราส่งไปหายูสเซอร์และ แต่ความเศร้าคือ Chat Center จะไม่ได้รับข้อความมาแสดงบน Platform แชทก็เลยจะหนักซ้ายแบบนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRzfBcpvdW2UoA3yM-F3Gg.png" /><figcaption>บอททำการตอบไปแล้ว แต่ Chat Center ไม่ได้รับข้อมูลมาแสดง</figcaption></figure><p>เพื่อให้ Chat ไม่หนักซ้ายเราจะมีการปรับโค้ดนิดหน่อยโดยที่จะมีการ return ค่าที่อยากให้ตอบกลับไปยัง Chat Center แทนซึ่งโค้ดที่ทำงานก็หน้าเปลี่ยนหน้าตาเป็นประมาณนี้</p><pre>from flask import Flask, request, abort, jsonify<br>from linebot import LineBotApi, WebhookHandler<br>from linebot.exceptions import InvalidSignatureError<br><br># from linebot.models import (<br>#     MessageEvent,<br>#     TextMessage,<br>#     TextSendMessage,<br>#     StickerMessage,<br>#     StickerSendMessage,<br># )<br><br>import os<br>from dotenv import load_dotenv<br><br># NOTE Load environment variables from .env file<br>load_dotenv()<br><br>app = Flask(__name__)<br><br># NOTE Replace these with your Channel Access Token and Channel Secret<br>CHANNEL_ACCESS_TOKEN = os.getenv(&quot;CHANNEL_ACCESS_TOKEN&quot;)<br>CHANNEL_SECRET = os.getenv(&quot;CHANNEL_SECRET&quot;)<br><br>line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN)<br>handler = WebhookHandler(CHANNEL_SECRET)<br><br><br>@app.route(&quot;/&quot;, methods=[&quot;GET&quot;])<br>def init():<br>    return &quot;LINE Chatbot Python!&quot;<br><br><br>@app.route(&quot;/webhook&quot;, methods=[&quot;POST&quot;])<br>def webhook():<br>    signature = request.headers[&quot;X-Line-Signature&quot;]<br>    body = request.get_data(as_text=True)<br>    app.logger.info(&quot;Request body: &quot; + body)<br><br>    try:<br>        handler.handle(body, signature)<br>    except InvalidSignatureError:<br>        abort(400)<br><br>    # Parse the request body to determine the message type<br>    payload = request.json<br>    events = payload.get(&quot;events&quot;, [])<br><br>    # Process each event<br>    responses = []<br>    for event in events:<br>        message_type = event.get(&quot;message&quot;, {}).get(&quot;type&quot;)<br>        if message_type == &quot;text&quot;:<br>            response = handle_text_message(event)<br>            responses.append(response)<br>        elif message_type == &quot;sticker&quot;:<br>            response = handle_sticker_message(event)<br>            responses.append(response)<br>        else:<br>            responses.append({&quot;messages&quot;: [{&quot;type&quot;: &quot;text&quot;, &quot;text&quot;: message_type}]})<br><br>    # Return the response(s) as JSON<br>    return jsonify(responses or []), 200<br><br><br>def switch_case(argument):<br>    if argument == &quot;สีเหลือง&quot;:<br>        return &quot;เยลโล่ว&quot;<br>    elif argument == &quot;มะม่วง&quot;:<br>        return &quot;แมงโก้&quot;<br>    elif argument == &quot;มีด&quot;:<br>        return &quot;อีโต้ 🗡️&quot;<br>    elif argument == &quot;ไฟแช๊ค&quot;:<br>        return &quot;ซิปโป้&quot;<br>    else:<br>        return &quot;ขอโทษทีฉันไม่เข้าใจนะ&quot;<br><br><br>def handle_text_message(event):<br>    try:<br>        # Retrieve text content<br>        text = event[&quot;message&quot;][&quot;text&quot;]<br>        reply_text = switch_case(text)<br>        response = {&quot;messages&quot;: [{&quot;type&quot;: &quot;text&quot;, &quot;text&quot;: reply_text}]}<br>        return response<br>    except Exception as e:<br>        print(f&quot;Error handling text message: {e}&quot;)<br>        return {}<br><br><br>def handle_sticker_message(event):<br>    try:<br>        # Get sticker information<br>        sticker_id = event[&quot;message&quot;][&quot;stickerId&quot;]<br>        package_id = event[&quot;message&quot;][&quot;packageId&quot;]<br>        response = {<br>            &quot;messages&quot;: [<br>                {&quot;type&quot;: &quot;sticker&quot;, &quot;stickerId&quot;: sticker_id, &quot;packageId&quot;: package_id}<br>            ]<br>        }<br>        return response<br>    except Exception as e:<br>        print(f&quot;Error handling sticker message: {e}&quot;)<br>        return {}<br><br><br>if __name__ == &quot;__main__&quot;:<br>    app.run(debug=True)</pre><p>จะเห็นได้ว่าเวอรชันนี้จะปรับเปลี่ยนตรง แทนที่จะต้องใช้</p><pre>line_bot_api.reply_message(event.reply_token, TextSendMessage(text=reply_text))</pre><p>เพื่อทำการส่งข้อความออกไป โค้ดได้ทำการ return ข้อมูลกลับไปยัง Chat Center แทนแล้วให้ Chat Center เป็นคนนำข้อความไปตอบให้ ซึ่งไม่ต้องกังวลเรื่องเสียโควต้า เพราะระบบจำทำการนำค่า replyToken ที่ได้มาใช้ในการยิง reply ให้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*0ya2nDWP28K9yPqrQk7uRQ.png" /><figcaption>รูปแบบการทำงานที่ใช้ Chat Center เป็นคนตอบให้</figcaption></figure><p>และผลลัพธ์ที่ได้ก็จะออกมาหน้าตาประมาณนี้ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S8leoQf5l7cFP7U4n0Uxow.png" /><figcaption>ข้อความถูกส่งไปยัง User และแสดงบน Chat Center</figcaption></figure><p>เย้ในที่สุดก็ได้อย่างที่ใจต้องการแล้ว ขออภัยที่โพสนี้รีบๆ ข้อความอาจจะดูมึน ลวกๆไปบ้างกับการอธิบาย สารภาพเลยว่าผมเขียน Python ไม่เป็นครับ แต่พยายามแปลงจาก Node ที่เคยทำมาเป็นตัวอย่างให้ ต้องขอบคุณลูกพี่ ChatGPT ถ้าไม่มีพี่แกผมคงงมอีกนาน</p><p>หวังว่าตัวอย่างพอจะเป็นไกด์ในการใช้งานได้นะครับ แต่ถ้ามีข้อแนะนำ ติชมก็ซัดมาได้เลย ด่าได้แต่อย่าแรงมากนะฮะ 😅 แล้วเจอกัน ถ้าอยากได้ภาษาอื่นซัพพอร์ตรีเควสมาได้เลย ผมจะพยายามจัดให้ ฮ่าๆ ถือว่าได้เรียนไปในตัวด้วยครับ ขอบคุณคร๊าบบบ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=912c20257bcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[มาใช้งาน LINE Bot ร่วมกับ EX10 Chat Center กันเถอะ]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%A1%E0%B8%B2%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-line-bot-%E0%B8%A3%E0%B9%88%E0%B8%A7%E0%B8%A1%E0%B8%81%E0%B8%B1%E0%B8%9A-ex10-chat-center-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B9%80%E0%B8%96%E0%B8%AD%E0%B8%B0-fd0d7f4a8cbb?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd0d7f4a8cbb</guid>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Sat, 13 Jan 2024 15:22:28 GMT</pubDate>
            <atom:updated>2024-01-14T01:49:01.962Z</atom:updated>
            <content:encoded><![CDATA[<p>จากที่เห็นใน <a href="https://www.facebook.com/groups/747270396284201">EX10 Develper Community</a> มีคนถามเข้ามาว่าจะใช้ Bot เดิมที่เคยทำไว้ร่วมกับ Chat Center อย่างไรดี ก็เลยจะลองทำตัวอย่างง่ายๆ มาแนะนำเผื่อจะเป็นประโยชน์สำหรับคนที่อยากลองใช้งานดูครับ</p><p>เนื้อหาบทความนี้จะสรุปรวดรัดประกอบด้วยหัวข้อดังต่อไปนี้</p><ol><li>แนะนำกับแสดงตัวอย่างการทำบอทต่อกับไลน์ (ง่ายมากจริ๊งๆ)</li><li>ปรับการตอบตามเงื่อนไขข้อความที่เราต้องการ</li><li>ใช้งาน EX10 Chat Center โดยทำการเชื่อมต่อบอทเก่าที่เราเคยทำ</li><li>นั่งจิบชา หรือว่าน้ำเก็กฮวยมีฟอง แล้วผมขอฝากที่เหลือด้วยนะครับ</li></ol><p><strong>ขั้นตอนที่ 1</strong> เริ่มต้นการทำบอทกับไลน์ที่ผมบอกว่าง่ายมาก เพราะผมไม่ได้ทำเองครับ ฮ่าๆ อยากให้ลองศึกษากรณีที่เป็นมือใหม่เช่นผม ก็ต้องลอกกกคนทำเป็นเลยฮะ</p><p>ถ้าใครยังไม่เคยก็ลองไปอ่านบทความนี้ได้เลยครับ <a href="https://medium.com/linedevth/line-bot-101-447e427d62c7">LINE Bot 101 — จับมือทำบอท</a></p><p>อ่านอย่างเดียวไม่พอใจต้องนิ่งแล้ววิ่งไปเอาโค้ดมาใช้ฟรีอีกฮ่าๆ ตามมาที่ลิ้งคนี้กันเลยฮะ <a href="https://github.com/kamnan43/line-bot-nodejs-starter">line-bot-nodejs-starter</a></p><p>ถ้าทำการรันโค้ดกับเชื่อมต่อบอทสำเร็จคิดว่าทุกคนพอลองทักข้อความเข้าไปจะได้ผลลัพธ์ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*pf9_Q0c3HZydia_hVCLAwg.png" /><figcaption>ทดสอบการทักข้อความไปหาไลน์ และบอททำการตอบกลับอย่างง่าย</figcaption></figure><p>เบื้องต้นบอทจะทำการตอบข้อความที่เราทักไปกลับมา กรณีเป็น message ประเภทอื่นจะตอบ Got Sticker ,… Image กลับมาอย่างง่าย<br>หากไม่ได้ผลลัพธ์ตามนี้อาจจะต้องให้ลองกลับไปอ่านบทความอีกที ตรวจสอบ Webhook ที่ LINE Develper Console ดู เห็นไหมว่าง่ายยจริงๆ</p><p><strong>ขั้นตอนที่ 2</strong> เดี๋ยวเรามาลองปรับข้อความตอบกลับเราเล่นดูให้เป็นไปตามเงื่อนไขที่เราอยากแสดงผล</p><pre>const replyText = (token, texts) =&gt; {<br>  const replyMessages = texts.map((text) =&gt; {<br>    switch (true) {<br>      case text.includes(&#39;อังกฤษ&#39;):<br>        return { type: &#39;text&#39;, text: &#39;พูดได้สิ สบายมาก&#39; };<br>      case text.includes(&#39;สีเหลือง&#39;):<br>        return { type: &#39;text&#39;, text: &#39;เยลโล่วว&#39; };<br>      case text.includes(&#39;มะม่วง&#39;):<br>        return { type: &#39;text&#39;, text: &#39;แมงโก้&#39; };<br>      case text.includes(&#39;มีด&#39;):<br>        return { type: &#39;text&#39;, text: &#39;อีโต้&#39; };<br>      case text.includes(&#39;ไฟแช๊ค&#39;):<br>        return { type: &#39;text&#39;, text: &#39;ซิปโป้&#39; };<br>      case text.includes(&#39;ชุดชั้นใน&#39;):<br>        return { type: &#39;text&#39;, text: &#39;วาโก้&#39; };<br>      case text.includes(&#39;เฉี๊ยบ&#39;):<br>      case text.includes(&#39;แจ๋ว&#39;):<br>      case text.includes(&#39;โดดเด่น&#39;):<br>        return { type: &#39;text&#39;, text: &#39;แต๊งกิ้วววว&#39; };<br>      default:<br>        return { type: &#39;text&#39;, text };<br>    }<br>  });<br><br>  return client.replyMessage(token, replyMessages);<br>};</pre><p>มาปรับให้บอทเราเล่นมุขง่ายๆดู โดยการใส่เงื่อนไขใน ฟังกชัน replyText ดูนะครับซึ่งถ้าสำเร็จผลลัพธ์ของเราก็จะได้เป็นแบบนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*3hlWdG5QUuPYNInBRUsl8g.png" /><figcaption>แสดงการตอบโต้ของบอทอย่างโบ๊ะบ๊ะตามเงื่อนไขที่เราต้องการ</figcaption></figure><p>คิดว่าคราวนี้เพื่อนๆพอจะเห็นแนวทางและ ผมจะพาเข้าสู่ฟินาเล่~ สำหรับการใช้งานร่วมกับ EX10 Chat Center</p><p><strong>ขั้นตอนที่ 3</strong> เชื่อมต่อการใช้งาน Chat Center สำหรับคนที่เคยสร้างแล้วให้เข้าไปเซ็ตดังนี้</p><p>เข้าไปยัง <a href="https://chat.ex10.tech/channel/1657014348">https://chat.ex10.tech/</a></p><p>เลือกโปรเจ็คที่เราต้องการ -&gt; คลิกเมนู -&gt; การจัดการ -&gt; เลือกบอทที่เราต้องการตั้งค่า</p><p>ทำการคลิกที่คำว่า <strong>ตั้งเว็บฮุค </strong>เพื่อเชื่อมต่อไลน์บอทกับ EX10 Chat Center</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWQIdhk60DRNvAFZbhE_vQ.png" /><figcaption>เชื่อมต่อไลน์บอทกับ EX10 Chat Center</figcaption></figure><p>คราวนี้เราจะไปที่แท็บส่วนเสริมกันจะพบว่ามีหลายๆตัวให้เลือกที่ บอท</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQHogJVVsFd7KzESIJKnNQ.png" /><figcaption>เลือกใช้งานส่วนเสริมที่การตั้งค่า</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rse_Wb1swPdaclIg1Epc5g.png" /><figcaption>กดเชื่อมต่อแล้วทำการส่งยืนยันเพื่อใช้งาน</figcaption></figure><p>จากขั้นตอนด้านบนจะถือว่าเราทำการเชื่อมต่อการทำงานกับ EX10 Chat Center สำเร็จแล้ว แต่เพื่อให้ข้อความส่งไปหาบอทที่เราสร้างไว้อาจจะต้องมีการปรับโค้ดอีกนิดหน่อยตามนี้ครับ</p><ul><li>ใน replyText ให้ทำการ คืนค่า replyMessage มาเลยแทนที่จะส่งไปหาไลน์</li></ul><pre>// simple reply function<br>const replyText = (token, texts) =&gt; {<br>  const replyMessages = texts.map((text) =&gt; {<br>    switch (true) {<br>      case text.includes(&#39;อังกฤษ&#39;):<br>        return { type: &#39;text&#39;, text: &#39;พูดได้สิ สบายมาก&#39; };<br>      case text.includes(&#39;สีเหลือง&#39;):<br>        return { type: &#39;text&#39;, text: &#39;เยลโล่วว&#39; };<br>      case text.includes(&#39;มะม่วง&#39;):<br>        return { type: &#39;text&#39;, text: &#39;แมงโก้&#39; };<br>      case text.includes(&#39;มีด&#39;):<br>        return { type: &#39;text&#39;, text: &#39;อีโต้&#39; };<br>      case text.includes(&#39;ไฟแช๊ค&#39;):<br>        return { type: &#39;text&#39;, text: &#39;ซิปโป้&#39; };<br>      case text.includes(&#39;ชุดชั้นใน&#39;):<br>        return { type: &#39;text&#39;, text: &#39;วาโก้&#39; };<br>      case text.includes(&#39;เฉี๊ยบ&#39;):<br>      case text.includes(&#39;แจ๋ว&#39;):<br>      case text.includes(&#39;โดดเด่น&#39;):<br>        return { type: &#39;text&#39;, text: &#39;แต๊งกิ้วววว&#39; };<br>      default:<br>        return { type: &#39;text&#39;, text };<br>    }<br>  });<br>  // client.replyMessage(token, replyMessages);<br>  return replyMessages;<br>};</pre><ul><li>ถัดมาให้ทำการคืนข้อความที่ได้ให้กับ EX10 ดังนี้</li></ul><pre>// handle events separately<br>  Promise.all(<br>    req.body.events.map((event) =&gt; {<br>      // NOTE return result for EX10<br>      const result = handleEvent(event);<br>      const resp = {<br>        messages: result,<br>      };<br>      return res.status(200).json(resp);<br>    })<br>  )<br>    .then(() =&gt; res.end())<br>    .catch((err) =&gt; {<br>      console.error(err);<br>      res.status(500).end();<br>    });</pre><p>คราวนี้ถ้าทุกอย่างถูกต้องลองมาเล่นกันดูเราก็จะได้ผลลัพธ์แบบนี้ มดสามตัวต้องเดินมา แอ่น แอน แอ๊นนนนน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PAEq6HFs75pNHCnMCHs1Qw.png" /><figcaption>บอทก็ยังโบ๊ะบ๊ะกับเราต่อบน EX10</figcaption></figure><p>จะเห็นว่าบอทที่เราทำก็ยังใช้งานได้ต่อ จุ๊ๆ อย่าบอกใครไป ถ้าสังเกตที่ฟังก์ชัน replyText จะเห็นว่าเราจะต้องใช้ token (replyToken) ส่งไปมาเพื่อใช้ในการตอบไม่ให้เสียโควต้า</p><p>แต่อันนี้ผมแอบไปแง้มประตูฟังได้ยินมาว่าระบบ EX10 จะทำการจัดการเรื่องนี้ให้เราด้วย เพียงแค่บอทเราตอบกลับ ได้ข้อความมาถามปุ๊บตอบปั๊บ</p><p>ระบบก็จะทำการเอา replyToken ในรอบที่ได้รับข้อความมาใช้งานแบบ reply ตอบกลับหาผู้ใช้ทำให้ไม่ต้องเสียโควต้าการส่งข้อความด้วยนะครับ มันช่าง เอเลแก้นนนนน อะไรเช่นนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2vWEGxpbxlp7H8zk.jpg" /></figure><p>ก่อนจบบทความขอแอบแถมท้ายด้วยการลองทำ flex message ส่งให้ดูปิดท้ายแบบ เอเลแก้นเลยฮะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qs9NW1cNVyQQniM6SZqBwQ.png" /><figcaption>แสดงผลการส่ง flex message บน EX10</figcaption></figure><p>สรุปกันอีกสักรอบว่า ที่เราทำการปรับโค้ดจากขั้นตอนการตอบไปยัง LINE OA <em>(1,2)</em> เองแล้วเปลี่ยนมาให้ EX10 Chat Center <em>(3)</em> ช่วยตอบแทนมีจุดไหนบ้างที่ทำการปรับไป</p><ul><li>จุดแรกคือ จากที่เคย ใช้ <strong>client.replyMessage(token, replyMessages)</strong> ทำการตอบข้อความ ก็ปรับมาเป็น คืนแค่รูปแบบข้อความที่เราต้องการตอบกลับไปยัง handleEvent ฟังกชันแบบนี้แทน <strong>return replyMessages</strong></li><li>จุดที่สองคือ จากที่ เส้น POST /webhook จะทำการ <strong>return handleEvent(event) </strong>ออกไปเลยเราก็มีการปรับให้ทำการรับข้อความที่ส่งมาจากฟังกชัน replyText แล้วทำการส่งเป็น status พร้อมกับข้อมูล json ออกไปแทนแบบนี้<br><strong>const result = handleEvent(event);<br> const resp = {<br> messages: result,<br> };<br> return res.status(200).json(resp)</strong></li></ul><p>หากมีข้อสงสัย แนะนำติชมยังไงเม้นแนะนำกันได้เลยนะครับ จบแล้วไปดื่มน้ำเก็กฮวยกันนนเถอะ ซู้ดดดดดด</p><p><a href="https://github.com/devster19/line-bot-with-ex10">ดาวน์โหลด Source code ตัวอย่าง</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd0d7f4a8cbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[พื้นฐาน Vuejs [เขียนไม่ซ้ำจำไม่ได้]]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B8%8B%E0%B9%89%E0%B8%B3%E0%B8%88%E0%B8%B3%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%84%E0%B8%94%E0%B9%89-vuejs-%E0%B8%9E%E0%B8%B7%E0%B9%89%E0%B8%99%E0%B8%90%E0%B8%B2%E0%B8%99-65ff7d10f33d?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/65ff7d10f33d</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Sat, 29 Jul 2023 17:00:39 GMT</pubDate>
            <atom:updated>2023-08-07T02:56:54.525Z</atom:updated>
            <content:encoded><![CDATA[<p>เพราะจำไม่ค่อยได้ เจอปัญหาเวลาไม่ได้เขียนนานๆแล้วก็ลืมเลยต้องจดเอาไว้อ่านเองซะหน่อยแล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*6ja8OkXcqGkD_nWUjDSeZw.gif" /></figure><h3>1. Vue Instance</h3><p>อินสแตนซ์ที่ใช้สร้างและควบคุมแอปพลิเคชัน Vue และเชื่อมต่อคุณสมบัติและโมเดลของ Vue กับส่วนของ HTML</p><pre>// Creating a Vue instance<br>var vm = new Vue({<br>  el: &#39;#app&#39;, // Bind to element with ID &#39;app&#39;<br>  data: {<br>    message: &#39;Hello, Vue.js!&#39;,<br>  },<br>});</pre><h3>2. Data Binding</h3><p>(การผูกข้อมูล) เชื่อมโยงและประมวลผลค่าของข้อมูลใน Vue instance กับส่วนของ HTML ให้แสดงผลแบบอัตโนมัติ</p><pre>&lt;!-- Interpolation --&gt;<br>&lt;p&gt;{{ message }}&lt;/p&gt;<br><br>&lt;!-- Binding HTML attributes --&gt;<br>&lt;img v-bind:src=&quot;imageUrl&quot; alt=&quot;Image&quot;&gt;<br><br>&lt;!-- Two-way data binding --&gt;<br>&lt;input v-model=&quot;inputValue&quot; type=&quot;text&quot;&gt;</pre><h3>3. Directives</h3><p>คำสั่งพิเศษใน HTML ที่ใช้ในการผูกข้อมูล (Data Binding) และควบคุมพฤติกรรมของ Element ในแอปพลิเคชัน Vue</p><pre>&lt;!-- Conditional Rendering --&gt;<br>&lt;p v-if=&quot;isVisible&quot;&gt;Visible&lt;/p&gt;<br>&lt;p v-else&gt;Hidden&lt;/p&gt;<br><br>&lt;!-- Looping with v-for --&gt;<br>&lt;li v-for=&quot;item in items&quot; :key=&quot;item.id&quot;&gt;{{ item.name }}&lt;/li&gt;<br><br>&lt;!-- Event Handling --&gt;<br>&lt;button v-on:click=&quot;doSomething&quot;&gt;Click Me&lt;/button&gt;<br><br>&lt;!-- Shorthand for Event Handling --&gt;<br>&lt;button @click=&quot;doSomething&quot;&gt;Click Me&lt;/button&gt;</pre><h3>4. Computed Properties</h3><p>(คุณสมบัติที่คำนวณ): เป็นคุณสมบัติใน Vue.js ที่ช่วยในการคำนวณและเก็บค่าผลลัพธ์เป็นค่าคงที่เมื่อค่าข้อมูลใน Vue instance เปลี่ยนแปลง</p><pre>&lt;!-- Example: Computed Property for Calculating Area --&gt;<br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;p&gt;Radius: {{ radius }}&lt;/p&gt;<br>    &lt;p&gt;Area: {{ area }}&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  data() {<br>    return {<br>      radius: 5,<br>    };<br>  },<br>  computed: {<br>    area() {<br>      return Math.PI * this.radius * this.radius;<br>    },<br>  },<br>};<br>&lt;/script&gt;</pre><h3>5. Watchers</h3><p>(ตัวดูแล): เป็นตัวเฝ้าสังเกตค่าของตัวแปรหรือคุณสมบัติใน Vue instance และทำการประมวลผลเมื่อมีการเปลี่ยนแปลงค่า</p><pre>&lt;!-- Example: Watcher for Asynchronous Search --&gt;<br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;input v-model=&quot;searchQuery&quot; type=&quot;text&quot; /&gt;<br>    &lt;p&gt;Search Result: {{ searchResult }}&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  data() {<br>    return {<br>      searchQuery: &#39;&#39;,<br>      searchResult: &#39;&#39;,<br>    };<br>  },<br>  watch: {<br>    searchQuery(newQuery, oldQuery) {<br>      // Simulate an API call delay<br>      setTimeout(() =&gt; {<br>        this.searchResult = &#39;Results for: &#39; + newQuery;<br>      }, 500);<br>    },<br>  },<br>};<br>&lt;/script&gt;</pre><p><em>งงตลอดว่าจะใช้ watch หรือ compute ดี นะ</em></p><p><strong><em>ควรใช้ Computed Properties เมื่อ:</em></strong></p><p><em>ต้องการคำนวณและดึงข้อมูลจากข้อมูลที่มีอยู่ใน Vue instance เพื่อคำนวณค่าใหม่</em></p><p><em>ต้องการรับค่าคงที่ที่ถูกคำนวณขึ้นมาจากข้อมูลหลายๆ ตัวแปร</em></p><p><em>ต้องการทำความสะดวกในการควบคุมสถานะและระบุเงื่อนไขสำหรับการแสดงผล HTML ใน Template</em></p><p><strong><em>ควรใช้ Watchers เมื่อ:</em></strong></p><p><em>ต้องการตรวจสอบการเปลี่ยนแปลงของตัวแปรหรือคุณสมบัติใน Vue instance เพื่อทำงานหรือกระทำเพิ่มเติมเมื่อมีการเปลี่ยนแปลงค่า</em></p><p><em>ต้องการจับควบคุมและประมวลผลค่าที่เปลี่ยนแปลงโดยสำหรับกรณีที่ไม่ควรคำนวณค่าใหม่ทุกครั้ง</em></p><h3>6. Components</h3><p>คือส่วนประกอบของโค้ดที่เป็นส่วนย่อยของแอปพลิเคชัน ซึ่งช่วยในการสร้างหน้าตาและพฤติกรรมที่นำไปใช้ซ้ำได้ในหลายส่วนของแอปพลิเคชัน</p><p><strong>Props</strong> เป็นวิธีในการส่งข้อมูลจากคอมโพเนนต์หนึ่งไปยังคอมโพเนนต์อื่น</p><p><strong>Event</strong> เป็นวิธีในการส่งข้อมูลจากคอมโพเนนต์ลูกกลับไปยังคอมโพเนนต์แม่ หรือกับคอมโพเนนต์อื่นที่สนใจ เมื่อเกิดเหตุการณ์บางอย่างที่คอมโพเนนต์ลูกต้องการแจ้งให้คอมโพเนนต์แม่ทราบ</p><p>ตย. โค้ดของแม่ เรียก parent น่าจะดีกว่า ฮ่าๆ!!</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;my-component<br>      title=&quot;Component Title&quot;<br>      content=&quot;Component Content&quot;<br>      @custom-event=&quot;handleCustomEvent&quot;<br>    /&gt;<br>    &lt;p&gt;{{ message }}&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>import MyComponent from &#39;./MyComponent.vue&#39;;<br><br>export default {<br>  components: {<br>    MyComponent,<br>  },<br>  data() {<br>    return {<br>      message: &#39;&#39;,<br>    };<br>  },<br>  methods: {<br>    handleCustomEvent(dataFromChild) {<br>      this.message = dataFromChild;<br>    },<br>  },<br>};<br>&lt;/script&gt;</pre><p>ตย. โค้ดของลูก!!</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h2&gt;{{ title }}&lt;/h2&gt;<br>    &lt;p&gt;{{ content }}&lt;/p&gt;<br>    &lt;button @click=&quot;notifyParent&quot;&gt;Notify Parent&lt;/button&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  props: [&#39;title&#39;, &#39;content&#39;],<br>  methods: {<br>    notifyParent() {<br>      this.$emit(&#39;custom-event&#39;, &#39;Custom event data from the child component&#39;);<br>    },<br>  },<br>};<br>&lt;/script&gt;</pre><h3>7. Lifecycle Hooks</h3><p>เป็นเหตุการณ์ที่เกิดขึ้นในระหว่างการสร้าง แก้ไข และทำลายคอมโพเนนต์และตัวแปรใน Vue instance</p><pre>var vm = new Vue({<br>  beforeCreate: function () {<br>    // Called before the instance is created<br>  },<br>  created: function () {<br>    // Called after the instance is created<br>  },<br>  beforeMount: function () {<br>    // Called before the instance is mounted to the DOM<br>  },<br>  mounted: function () {<br>    // Called after the instance is mounted to the DOM<br>  },<br>  // Other lifecycle hooks: beforeUpdate, updated, beforeDestroy, destroyed<br>});</pre><h3>8. Vue Router</h3><p>ใช้ในการจัดการเส้นทาง (Routing) หรือการนำทางระหว่างหน้าเว็บในแอปพลิเคชัน</p><pre>// Assuming Vue Router is installed and imported<br>const routes = [<br>  { path: &#39;/&#39;, component: Home },<br>  { path: &#39;/about&#39;, component: About },<br>];<br><br>const router = new VueRouter({<br>  routes,<br>});<br><br>var vm = new Vue({<br>  router,<br>});</pre><h3>9. Vuex (State Management)</h3><p>เป็นไลบรารีสำหรับการจัดการสถานะ (State Management) ในแอปพลิเคชัน Vue.js ซึ่งช่วยให้คุณบริหารจัดการข้อมูลและส่งค่าระหว่างคอมโพเนนต์</p><p>Vuex มีส่วนประกอบหลัก ๆ ดังนี้:</p><ol><li><strong>State</strong> คือข้อมูลที่เก็บค่าในแอปพลิเคชัน ซึ่งสามารถเรียกใช้ได้ในทุกๆ คอมโพเนนต์ของแอปพลิเคชัน</li><li><strong>Mutations</strong> เป็นเมทอดที่ใช้ในการเปลี่ยนแปลงค่าใน State โดยเฉพาะเมื่อต้องการทำการเปลี่ยนแปลง State ให้ตรงกับกฎเกณฑ์ที่กำหนด</li><li><strong>Actions</strong> เมทอดที่ใช้ในการทำงานแบบส่วนหนึ่งและสามารถทำงานที่ไม่ใช่การเปลี่ยนแปลง State ได้ เช่น เรียก API, การคำนวณ ฯลฯ</li><li><strong>Getters</strong> เป็นคอมพิวเตอร์ฟังก์ชันที่ช่วยในการคำนวณหรือนำ State มาใช้งานในรูปแบบที่คุณต้องการ เพื่อนำไปใช้ในการแสดงผลหรือการคำนวณเพิ่มเติม</li></ol><pre>// Assuming Vuex is installed and imported<br>const store = new Vuex.Store({<br>  state: {<br>    count: 0,<br>  },<br>  mutations: {<br>    increment(state) {<br>      state.count++;<br>    },<br>  },<br>  actions: {<br>    incrementAsync({ commit }) {<br>      setTimeout(() =&gt; commit(&#39;increment&#39;), 1000);<br>    },<br>  },<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65ff7d10f33d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ก้าวแรกไม่เป็นไร ก้าวต่อไป หัดเขียน Nestjs + Mongo]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%81%E0%B9%89%E0%B8%B2%E0%B8%A7%E0%B9%81%E0%B8%A3%E0%B8%81%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B9%84%E0%B8%A3-%E0%B8%81%E0%B9%89%E0%B8%B2%E0%B8%A7%E0%B8%95%E0%B9%88%E0%B8%AD%E0%B9%84%E0%B8%9B-%E0%B8%AB%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99-nestjs-mongo-c6410ea2cd85?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6410ea2cd85</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Fri, 22 May 2020 17:15:36 GMT</pubDate>
            <atom:updated>2020-05-22T17:20:47.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>ก้าวแรกไม่เป็นไร ก้าวต่อไป หัดเขียน Nestjs + MongoDB</h3><blockquote>หลังจากครั้งที่แล้วเราลองเขียน ระบบจัดการน้ำเก็กฮวยขึ้นมา <a href="https://medium.com/@devster.hiddenman/%E0%B8%81%E0%B9%89%E0%B8%B2%E0%B8%A7%E0%B9%81%E0%B8%A3%E0%B8%81%E0%B8%AA%E0%B8%B9%E0%B9%88%E0%B8%AA%E0%B8%B1%E0%B8%87%E0%B9%80%E0%B8%A7%E0%B8%B5%E0%B8%A2%E0%B8%99-%E0%B8%AB%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99-nestjs-%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%9B%E0%B8%90%E0%B8%A1%E0%B8%9A%E0%B8%97-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-api-3bbe9ae44642">บทก่อนหน้านี้ </a>คราวนี้เราจะลองทำการต่อกับ MongoDB ดู ถ้าพร้อมแล้วก็มามึนไปด้วยกันต่อเลยฮะ</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*owYUc43c_ZWnFRwVGVSVOg.jpeg" /></figure><p>อ่านจาก Document Nestjs ซัพพอร์ตการเชื่อมต่อกับ MongoDB ได้สองแบบคือใช้งาน Mongoose หรือ TypeORM ส่วนในบทความนี้จะลองต่อโดยเลือกใช้ Mongoose</p><p><strong>ติดตั้ง Mongoose #</strong></p><pre>$ npm install --save @nestjs/mongoose mongoose<br>$ npm install --save-dev @types/mongoose</pre><p><strong>อิมพอร์ต MongooseModule ไปยัง AppModule #</strong></p><p>เพื่อไม่ให้เป็นการเสียเวลาในการ Set up Database ก็เลยไปใช้ Cloud Service ฟรี ของ MongoDB Atlas ซึ่ง Free tier สามารถใช้งานเดต้าได้ถึง 512 MB</p><p>สำหรับขั้นตอนการ Set up ก็ไม่ซับซ้อนนะครับ ทางเว็บทำการอธิบายด้วยภาพไว้ละเอียดดีเลย กดดูได้จากลิ้งคนี้ <a href="https://docs.atlas.mongodb.com/getting-started/">Get Started with Atlas</a> ซึ่งถ้าสร้างเดต้าเบส เสร็จแล้วเราก็จะได้ Connection String เพื่อเอามาใช้งานดังรูป ข้อดีอีกอย่างก็คือสามารถเซ็ต IP Whitelist ที่เมนู Security/Network Access ได้นะครับจะได้ปลอดภัยยิ่งขึ้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AlQgmZNkM9FfvbuYrwd8lQ.png" /></figure><p><strong>อัพเดทไฟล์ app.module.ts #</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5efbae3110a67041c33d3da3233519af/href">https://medium.com/media/5efbae3110a67041c33d3da3233519af/href</a></iframe><p><strong>สร้าง Schema #</strong></p><p>Schema<strong> </strong>จะเป็นตัวกำหนดว่าจะมีข้อมูลอะไรบ้างที่จะเก็บไปยัง Database</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f5309405bdd17d8641c86c367156035/href">https://medium.com/media/0f5309405bdd17d8641c86c367156035/href</a></iframe><p><strong>อัพเดทไฟล์ beers.module.ts #</strong></p><p>เพื่อที่จะทำการเรียกใช้โมเดล Beer ผ่านการ @InjectModel ในไฟล์ beers.service.ts ได้เราก็ต้องย้อนกลับมาอัพเดทไฟล์ที่ beers.module.ts ก่อนโดยทำการ Import MongooseModule เข้าไป</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef8caa70a52dcd8e7ca414e7f1fdfdd9/href">https://medium.com/media/ef8caa70a52dcd8e7ca414e7f1fdfdd9/href</a></iframe><p><strong>อัพเดทไฟล์ beers.service.ts #</strong></p><p>อันนี้ก็จะเริ่มเยอะนิดนึงเพราะว่าเราจะทำการ save ข้อมูลจริงๆไปยัง Cloud Database Service ละซึ่งหลักๆที่เปลี่ยนแปลงไปก็คือมีการ</p><ul><li>@InjectModel ที่ Constructor</li><li>เรียกใช้ Moongoose API เพื่อเป็นตัวกลางเชื่อมตัวไปยัง Database</li><li>มีปรับ try…catch ง่ายๆไว้ในกรณีที่หาข้อมูลไม่เจอแต่จริงๆแล้วรู้สึกว่าการ Handle Error ของ Nestjs ถ้าจะทำให้ถูกกระบวนท่าน่าจะต้องไปดูเรื่อง <a href="https://docs.nestjs.com/exception-filters">Exception Filters</a> เพิ่ม น่าสนใจดีนะครับ</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69c9c0564aa6fde7f83dacb3fe1f1670/href">https://medium.com/media/69c9c0564aa6fde7f83dacb3fe1f1670/href</a></iframe><p>เหมือนเคยกราบบบบบ ขออภัยถ้าอธิบายไม่ดี ยิ่งเขียนเหมือนยิ่งลวก แต่แอบหวังว่าจะพอมีประโยชน์ให้ลองเป็นไกด์เบื้องต้น ลองไปทำเวอร์ชั่น เดอะเบสของท่านออกมาได้</p><p>โค้ดทั้งหมดไปดูได้ที่นี่เลย <a href="https://github.com/devster19/nestjs-beer-bckn.git">https://github.com/devster19/nestjs-beer-bckn.git</a></p><p>อันนี้เป็นตัวอย่างจาก official document ของ Nestjs <a href="https://docs.nestjs.com/techniques/mongodb">https://docs.nestjs.com/techniques/mongodb</a></p><p>และ document ของ mongoose <a href="https://mongoosejs.com/">https://mongoosejs.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6410ea2cd85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ก้าวแรกสู่สังเวียน หัดเขียน Nestjs ภาคปฐมบท สร้าง API]]></title>
            <link>https://medium.com/@devster.hiddenman/%E0%B8%81%E0%B9%89%E0%B8%B2%E0%B8%A7%E0%B9%81%E0%B8%A3%E0%B8%81%E0%B8%AA%E0%B8%B9%E0%B9%88%E0%B8%AA%E0%B8%B1%E0%B8%87%E0%B9%80%E0%B8%A7%E0%B8%B5%E0%B8%A2%E0%B8%99-%E0%B8%AB%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99-nestjs-%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%9B%E0%B8%90%E0%B8%A1%E0%B8%9A%E0%B8%97-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-api-3bbe9ae44642?source=rss-f80a492c73e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bbe9ae44642</guid>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Devster Hiddenman]]></dc:creator>
            <pubDate>Mon, 18 May 2020 05:46:26 GMT</pubDate>
            <atom:updated>2020-05-22T17:17:12.036Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>ประมาณ 2 ปีที่แล้วที่ได้มีโอกาสไปงาน Angular Meet up แล้วก็ได้เห็นผู้เชี่ยวชาญหลายๆท่านมาให้ความรู้ และก็แนะนำ Nestjs ให้ได้รู้จักนับแต่นั้นมาก็ได้แต่ทดไว้ในใจว่า เฮ้ย !!สักวันเราจะต้องไปลองหน่อยละ เวลาก็ผ่านไปไวยังไม่ได้เริ่มสักทีโดยส่วนตัวแล้วอาจจะไม่ค่อยได้เขียน Angular บ่อยเท่าไหร่ แต่แค่รู้สึกว่า อยากหัดเขียนไว้บ้าง เผื่ออนาคตจะต้องมีประโยชน์แน่นอน 🚀</blockquote><p>สำหรับบทความนี้จะเป็นการทดลองเขียนการ เพิ่ม ลบ แก้ไข และเรียกดูข้อมูลน้ำเก็กฮวย 🍺 โดยพาร์ทนี้จะยังไม่ได้ทำการเชื่อมต่อกับ Database นะครับถ้างั้นมาลองมึนไปด้วยกันเลย 🤪</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*CfxlOjjSOFRtsJni8nO--Q.jpeg" /></figure><p><strong>เริ่มต้นด้วยการ ติดตั้ง Nest CLI เพื่อเอาไว้ใช้ในการสร้างโปรเจ็ค #</strong></p><pre>npm install -g @nestjs/cli</pre><p><strong>สร้างโปรเจ็ค #</strong></p><pre>nest new beer-bcknd-app</pre><p><strong>หลังจากนั้นก็เข้าไปในโฟลเดอร์ที่เราทำการสร้าง แล้วรันโปรเจ็คขึ้นมา #</strong></p><pre>cd beer-bcknd-app<br>npm run start:dev</pre><p>แอ่น แอน แอ๊นนน 🐜 🐜 🐜…พอเปิดบราวเซอร์ขึ้นมาแล้วเข้าผ่าน <a href="http://localhost:3000/">http://localhost:3000/</a> ก็จะได้ผลลัพธ์ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-H-09OL2wHfj015y28ZhTw.png" /><figcaption>รัน localhost:3000</figcaption></figure><p><strong>เริ่มต้นสร้าง Module beers #</strong></p><pre>nest g module beers</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7fe604be24231ca1877866b9c3e4ef9/href">https://medium.com/media/b7fe604be24231ca1877866b9c3e4ef9/href</a></iframe><p><strong>สร้าง Controller สำหรับจัดการ Endpoint #</strong></p><pre>nest g controller beers</pre><p><strong>สร้าง Request payloads </strong><a href="https://docs.nestjs.com/controllers#request-payloads"><strong>#</strong></a></p><p>ปกติเรา Post ข้อมูลด้วย @Body() ตัวอย่าง เช่น @Body(‘name’) name: string แต่เราจะมาสร้างเจ้าส่ิงที่เรียกว่า DTO (Data Transfer Object) ซึ่งจะเป็นตัวกำหนดว่าหน้าตาข้อมูลที่เราจะส่งไปมีอะไรบ้าง จากตย. เป็นการสร้างไว้สำหรับ Post ข้อมูลน้ำเก็กฮวย 🍺</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc902c6b36341e73ddaea59797851591/href">https://medium.com/media/fc902c6b36341e73ddaea59797851591/href</a></iframe><p>แทนโค้ด ใน file beers.controller.ts ด้วยโค้ดด้านล่างนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1518b8b5a031e02c6b294023f6cbd8ed/href">https://medium.com/media/1518b8b5a031e02c6b294023f6cbd8ed/href</a></iframe><p><strong>สรุป Endpoint นิดนึงละกัน #</strong></p><blockquote><a href="http://localhost:3000/beers">http://localhost:3000/beer</a>s — GET (โชว์ลิสต์ของน้ำเก็กฮวยทั้งหมด)</blockquote><blockquote><a href="http://localhost:3000/beers">http://localhost:3000/beers</a>/{id} — GET (โชว์ลิสต์ของน้ำเก็กฮวยจากไอดี)</blockquote><blockquote><a href="http://localhost:3000/beers/create">http://localhost:3000/beers/</a>create — POST (เพิ่มน้ำเก็กฮวยเข้าสู่ระบบ)</blockquote><blockquote><a href="http://localhost:3000/beers/create">http://localhost:3000/beers/</a>{id} — PUT (อัพเดทข้อมูลน้ำเก็กฮวย)</blockquote><blockquote><a href="http://localhost:3000/beers/create">http://localhost:3000/beers/</a>{id} — DELETE (ลบข้อมูลน้ำเก็กฮวยออกจากระบบ)</blockquote><p>โค้ดด้านบนอาจจะรวบรัดนิดนึงโดยทำการสร้าง service กับ interface ไว้แล้ว ไงลองดูต่อนะครับ</p><p><strong>สร้าง Service สำหรับจัดการ ข้อมูลเพื่อไว้ให้ Controller เรียกใช้งาน #</strong></p><pre>nest g service beers</pre><p><strong>ทำการสร้าง interface สำหรับใช้เช็ค type ของข้อมูล #</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12452928a29fc77f8f8e913786cc5720/href">https://medium.com/media/12452928a29fc77f8f8e913786cc5720/href</a></iframe><p>สุดท้ายก็แทนโค้ด service ด้วยโค้ดด้านล่างดูนะครับ ฮาร์ดโค้ดตัวข้อมูลน้ำเก็กฮวยมาลองเล่นดูก่อนนะครับ</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebffafdddf25117f9f8081859a9f671d/href">https://medium.com/media/ebffafdddf25117f9f8081859a9f671d/href</a></iframe><p>ไงลองเล่นดูนะครับ ส่วน source code ทั้งหมดไปดูได้ที่นี่เลย <a href="https://github.com/devster19/nestjs-beer-bckn.git"><em>https://github.com/devster19/nestjs-beer-bckn.git</em></a></p><p>จริงๆก็ลองเข้าไปแกะดูจาก document ในหน้าหลักของ Nestjs ดูก็ได้เขาเขียนอธิบายไว้ดีเลย</p><p><a href="https://docs.nestjs.com/">Documentation | NestJS - A progressive Node.js framework</a></p><p>ปล. หวังว่าถ้ามีใครหลงเข้ามาอ่านก็ขอให้ทำตามได้ด้วยเถิด หากมีคำแนะนำใดๆก็บอกได้นะครับ เพิ่งหัดเขียนดู อยากให้มันกระชับสั้นๆ แต่รู้สึกว่ายากจังแหะ 😓</p><p><a href="https://medium.com/@devster.hiddenman/%E0%B8%81%E0%B9%89%E0%B8%B2%E0%B8%A7%E0%B9%81%E0%B8%A3%E0%B8%81%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B9%84%E0%B8%A3-%E0%B8%81%E0%B9%89%E0%B8%B2%E0%B8%A7%E0%B8%95%E0%B9%88%E0%B8%AD%E0%B9%84%E0%B8%9B-%E0%B8%AB%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99-nestjs-mongo-c6410ea2cd85">มีภาคต่อแล้วนะ กดตรงนี้ได้เลยจ้า </a>😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bbe9ae44642" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>