<?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 Snoop Duck on Medium]]></title>
        <description><![CDATA[Stories by Snoop Duck on Medium]]></description>
        <link>https://medium.com/@aofiee?source=rss-d12e6af6df6d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qrRng9Luwe2h7vnfNjE2wg.png</url>
            <title>Stories by Snoop Duck on Medium</title>
            <link>https://medium.com/@aofiee?source=rss-d12e6af6df6d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 03:32:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aofiee/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[AngularDart]]></title>
            <link>https://medium.com/@aofiee/angulardart-3ab7d01da1d1?source=rss-d12e6af6df6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ab7d01da1d1</guid>
            <category><![CDATA[angulardart]]></category>
            <category><![CDATA[dartlang]]></category>
            <dc:creator><![CDATA[Snoop Duck]]></dc:creator>
            <pubDate>Tue, 01 May 2018 16:24:57 GMT</pubDate>
            <atom:updated>2018-05-01T16:27:04.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*5YXnf75clefL63B-WVN8Bg.png" /><figcaption><a href="https://angulardart.org/">https://angulardart.org</a></figcaption></figure><p>เมื่อเป้าหมาย คือเขียน ภาษาเดียว เปรี๊ยวได้ทุก Platform เลยต้องมาค้นคว้าหาวิธีเริ่มเขียนตั้งแต่ AngularDart ด้วยภาษา Dart</p><p>หลังจากลง Dart กันในเครื่องเรียบร้อยแล้ว การที่เราจะใช้ Visual Studio Code ในการ Develop Dart Lang แทน IntelliJ IDEA’s ต้องลง Extension Dart Code กันก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQccuH_XXCy50rIg2A_EXg.png" /><figcaption>Dart Code</figcaption></figure><p>หากเราใช้ VS Code ที่ลืมไม่ได้เลยต้องลง <a href="https://github.com/dart-lang/stagehand">StageHand</a> ด้วยครับ เพื่อใช้ในการ Generate Project File ตั้งต้นในการ Develop ภาษา Dart ผ่านทาง Command line</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_DjGycrgR11c2xhg4M-u0w.jpeg" /><figcaption><a href="https://github.com/dart-lang/stagehand">https://github.com/dart-lang/stagehand</a></figcaption></figure><p>หลังจากลง StageHand เรียบร้อยแล้ว ก็ใช้ Terminal ไปสร้าง Folder ที่ Path ที่เราต้องการได้เลย ในที่นี้ผมตั้งชื่อว่า web-demo/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H46RTM3z8NkCkpFpkms5CA.png" /></figure><p>หลังจากนั้นเราพิมพ์คำสั่ง stagehand ที่ terminal เพื่อดูว่ามันทำอะไรได้บ้าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6F7XMX9KDM2-b4PSSRALFQ.png" /></figure><p>จะพบว่ามีทั้ง console-full ที่เอาไว้เขียน dart แบบ command-line และ server-shelf ที่ไว้เขียน ฝั่ง server แบบง่ายๆ หรือแบบ web-angular ที่เราจะใช้งานกันตอนนี้</p><p>หลังจากนั้นให้เรา command คำสั่ง stagehand web-angular เพื่อสร้าง project แรกของเราด้วย angulardart กัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HO0wakea0ahGQneN0hnXUQ.png" /></figure><p>ใน Folder web-demo/ ของเราจะได้ไฟล์ตามภาพนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAjLsYOg9k4fHgM5OuMs6Q.png" /></figure><p>หลังจากนั้นเราต้อง install package ที่ต้องใช้งานกันก่อน ด้วยตัวจัดการ package manager ของ dart ที่ชื่อว่า pub ด้วยคำสั่ง pub get จากนั้นก็รอ…..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qNd-TI8-mmmnBZGlG-f_OQ.png" /></figure><p>เราเริ่มต้นด้วยการ ลบ ลบ ลบ ลบไฟล์ที่ตัวอย่างที่ได้มาออกให้หมดเลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVUvI0awnA2AdY_EfjtNtg.png" /></figure><p>หลังจากนั้นให้เราสร้างไฟล์ชื่อ</p><p>app_component.dart , app_component.html, app_component.css เก็บไว้ที่ lib/</p><p>Sample:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5c2335df7a232425f3233d3076817d3/href">https://medium.com/media/b5c2335df7a232425f3233d3076817d3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae33439e7d85cde0f4ee737c8c3c24e9/href">https://medium.com/media/ae33439e7d85cde0f4ee737c8c3c24e9/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9748ff18ee873a4295a8d87eb810ddfe/href">https://medium.com/media/9748ff18ee873a4295a8d87eb810ddfe/href</a></iframe><p>เมื่อสั่ง pub serve ที่ terminal แล้ว หากไม่มีอะไร error เมื่อเข้าไปที่ browser localhost ที่ port 8080 จะได้ภาพดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GcKrlw0cSGIS9gKmxZfoaw.png" /></figure><p>หลังจากนั้นเราจะสร้าง class ชื่อ Bnk48 เก็บไว้ใน folder lib/src/bnk48.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34aad33dd725ed1e022b6ca01793b867/href">https://medium.com/media/34aad33dd725ed1e022b6ca01793b867/href</a></iframe><p>โดยมีการเก็บข้อมูลชื่อ และรูปภาพของน้องๆวง BNK48 กัน</p><p>หลังจากนั้นก็หาข้อมูลใน google เพื่อทำ mock data ของน้องๆว่ามีใครบ้าง หน้าตายังไง น่ารักไหม เก็บไว้ที่ lib/src/mockBnk.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24241009663640bcb2ef174e75461072/href">https://medium.com/media/24241009663640bcb2ef174e75461072/href</a></iframe><p>หลังจากนั้นเราเพิ่ม บรรทัดนี้ เพื่อ loop แสดงผลจากตัวแปร bnkNames</p><pre>&lt;ul class=&quot;bnkNames&quot;&gt;</pre><pre>&lt;li *ngFor=&quot;let bnkName of bnkNames&quot;&gt;</pre><pre>&lt;span class=&quot;badge&quot;&gt;{{bnkName.id}}&lt;/span&gt; {{bnkName.name}}</pre><pre>&lt;/li&gt;</pre><pre>&lt;/ul&gt;</pre><p>ที่ file app_component.html ใต้บรรทัด</p><pre>&lt;h2&gt;My BNK48&lt;/h2&gt;</pre><p>เมื่อ Refresh Browser จะได้ผลตามภาพ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hm7ekfphXlCINUiI6Hf-XA.png" /></figure><p>หลังจากนั้นมาต่อที่ Action เมื่อเราทำการกด Click ที่ชื่อของ member BNK48 กันก่อน จะให้แสดง ชื่อนามสกุล และรูปภาพของน้องๆเขาด้วยนะ</p><p>เริ่มจากการสร้าง component กันก่อนเลย เก็บไว้ใน lib/src/bnkdetailcomponent/</p><p>ชื่อว่า bnk_detail_component.dart, bnk_detail_component.html และ bnk_detail_component.css ขรั่บ….</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/549294edbd1dc05374e2ca24f68dd2dd/href">https://medium.com/media/549294edbd1dc05374e2ca24f68dd2dd/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4082d771a6a15aa6101c4bf667d88d0/href">https://medium.com/media/b4082d771a6a15aa6101c4bf667d88d0/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/467d62abdb43d5629180045f670a3090/href">https://medium.com/media/467d62abdb43d5629180045f670a3090/href</a></iframe><p>และไป import ‘package:web_demo/src/bnkdetailcomponent/bnk_detail_component.dart’;</p><p>ใน app_component.dart เพื่อดึง layout detail มาแสดงเมื่อทำการกดปุ่ม โดยเรียก directives Bnk48DetailComponent เข้ามา</p><pre>directives: const [CORE_DIRECTIVES,Bnk48DetailComponent],</pre><pre>Bnk48 selectedBnk;</pre><pre>void onSelectPerson(Bnk48 person){</pre><pre>selectedBnk = person;</pre><pre>}</pre><p>เมื่อกด Refresh จะแสดงผลตามนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3MKMb0WGhtmb6bnsZYFDkA.png" /></figure><p>ที่เหลือก็แค่แสดงรูปถ่ายของน้องๆกันแล้ว</p><p>เรามาสร้าง component การแสดงภาพด้วยการสร้างไฟล์ไว้ที่ lib/bnkphotocomponent/bnk_photo_component.css</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ded905a135d46481cf63c3779c33c11/href">https://medium.com/media/1ded905a135d46481cf63c3779c33c11/href</a></iframe><p>lib/bnkphotocomponent/bnk_photo_component.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06bd828bab08df95b0804f06681ba7e8/href">https://medium.com/media/06bd828bab08df95b0804f06681ba7e8/href</a></iframe><p>lib/bnkphotocomponent/bnk_photo_component.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d718366d78c606cf6c0d2ad5585c579/href">https://medium.com/media/8d718366d78c606cf6c0d2ad5585c579/href</a></iframe><p>หลังจากนั้นเราไปเพิ่ม tag สำหรับเรียกใช้ component photo เราในไฟล์ bnk_detail_component.html</p><pre>&lt;bnk48-photo [bnk48]=&quot;bnk48&quot;&gt;&lt;/bnk48-photo&gt;</pre><p>และไป import ‘../bnkphotocomponent/bnk_photo_component.dart’;</p><p>เข้ามาที่ bnk_detail_component.dart เพื่อดึง component photo น้องเฌอมาแสดง</p><p>พร้อมแก้ไข directives เพื่อเพิ่ม component Bnk48PhotoComponent ลงไป</p><pre>directives: const [CORE_DIRECTIVES,Bnk48PhotoComponent, formDirectives],</pre><p>เมื่อทำการ Refresh แล้วจะได้ผลแบบนี้เป็นอันจบการทดลองศึกษา AngularDart ในวันแรงงานวันนี้ฮะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*40ujRGFY94lNbp1ZWYihRw.png" /></figure><p>เราสามารถลอง build เป็นไฟล์ html และ js ได้ด้วยคำสั่ง</p><pre>$ pub build</pre><p>ตัวอย่าง Source Code ทั้งหมดอยู่ที่นี่</p><p><a href="https://github.com/aofiee/angulardart-demo-bnk48">aofiee/angulardart-demo-bnk48</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ab7d01da1d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Dart ?]]></title>
            <link>https://medium.com/@aofiee/why-dart-80886bf10922?source=rss-d12e6af6df6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/80886bf10922</guid>
            <category><![CDATA[dartlang]]></category>
            <dc:creator><![CDATA[Snoop Duck]]></dc:creator>
            <pubDate>Tue, 01 May 2018 09:30:28 GMT</pubDate>
            <atom:updated>2018-05-01T09:30:28.820Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3g5RCJhqKNwqYPGxtTmtg.png" /><figcaption>Dart Lang</figcaption></figure><p>เนื่องจากภาวะขาดแคลน resource ทางด้าน programming ที่เจอกันบ่อยๆ และ cost ที่ไปหนักอยู่บนทางด้าน mobile app เสียส่วนมาก เนื่องจากทีมเขียน native อย่างน้อยต้องใช้ dev ถึง 2 คน ,Frontend 1, API 1, Backend 1, Devops 1 อะไรก็ว่าไป ในการเริ่มต้น 1 project</p><p>ในทีมก็มีทั้ง Vuejs, laravel, golang, swift, java, javascript framework ภาษาตีกันมั่วไปหมด</p><p>เลยมีการตกลงคุยกันในทีม ว่านอกจากความถนัดของแต่ละคนแล้ว ทีมควรได้ภาษากลางอีกภาษา 1 ที่ไว้ทำ crossplatform กันได้ ย้ายตำแหน่งความถนัดกันได้</p><p>งั้นมาเลือกที่ performence จะมี react native สูสีกับ flutter</p><p>แล้ว flutter มันคือ? บ่องตง ไม่รู้จักเลยว่ามันคือไร เขาบอกว่ามัน compile เป็น native code และไม่ใช้ Javascript bridge เลย veryๆ fast</p><p>และมี widgets ทั้ง Material Design (for Android) และ Cupertino (for iOS) ให้ใช้งาน</p><p>ฟังดูดีๆ</p><p>แล้วจะเริ่มยังไง?</p><p>ไอ้ flutter เนี่ย ใช้ภาษา Dart</p><p>Dart เหี้ยไรอีก!!!?</p><p>Search หา Community ก่อนเลย ใน Facebook มีอยู่ ร้อยกว่าคน น้อยสัสรัสเซีย!!</p><p>ทำไมข้อมูลน้อยจังวะ!!</p><p>google แพร้พ หาก่อนว่า “Worst Programming Languages to Learn in 2018”</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0tL55LSgMj5p23_TIsIwOQ.png" /></figure><p>นั่นไง Dart มาอันดับ 1 ภาษาที่ไม่น่าศึกษามากที่สุดในปีนี้เลย</p><p>เพราะ</p><p>- Community แย่</p><p>- Job Market เลยน้อยตามมา ไม่มีการจ้างงาน</p><ul><li>Growth and Trends ยอดแย่อันดับ 3</li></ul><p><a href="https://www.codementor.io/blog/worst-languages-to-learn-3phycr98zk">https://www.codementor.io/blog/worst-languages-to-learn-3phycr98zk</a></p><p>ไม่แปลกเลย กูยังจะเพิ่งรู้จัก Dart วันนี้แหล่ะ การตลาด google -_-’</p><p>แต่หลังจาก google ปล่อย flutter ออกมา แนวโน้มคนพูดถึง Dart มากขึ้นนะ</p><p>Community ใน Discord ก็มีฝรั่งช่วยตอบอย่างไว ก็โอเคล่ะน่า</p><p>สรุปหลังจากเลือก Technology มาเสริมทีมกันแล้ว เลยเลือก codebase ที่ภาษา Dart</p><p>ใช้ Frontend ด้วย AngularDart และใช้ Aqueduct ทำ Resful API ไปจบที่ Flutter ในการทำ Mobile Crossplatform Native ช่วงแรกๆ Library อาจจะยังมีให้เลือกใช้ไม่มากนัก แต่เท่าที่ลองใช้งานใน Project เล็กๆตัวนึงพบว่าใช้งานได้ดี Leraning Curve ทั้ง Dart, AngularDart ,Aqueduct , Flutter</p><p>ใช้เวลารวมๆกันไม่เกิน อาทิตย์นึง ก็พอจะนำไปใช้พัฒนาโปรเจคได้แล้ว</p><p><em>ตัวอย่าง code ที่เขียนระหว่างศึกษาตัวภาษา dart</em></p><p>Dart</p><p><a href="https://github.com/aofiee/dart-basic">https://github.com/aofiee/dart-basic</a></p><p>FrontEnd AngularDart</p><p><a href="https://github.com/aofiee/angulardart-demo-bnk48">https://github.com/aofiee/angulardart-demo-bnk48</a></p><p>Native Mobile App Cross Platform Flutter</p><p><a href="https://github.com/aofiee/flutter-login-demo">https://github.com/aofiee/flutter-login-demo</a></p><p>Restful API aqueduct.io</p><p><em>ยังไม่ได้ทำตัวอย่าง</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80886bf10922" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[หนทางสู่ Tester]]></title>
            <link>https://medium.com/@aofiee/%E0%B8%AB%E0%B8%99%E0%B8%97%E0%B8%B2%E0%B8%87%E0%B8%AA%E0%B8%B9%E0%B9%88-tester-69eb566ac880?source=rss-d12e6af6df6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/69eb566ac880</guid>
            <category><![CDATA[robot-framework]]></category>
            <dc:creator><![CDATA[Snoop Duck]]></dc:creator>
            <pubDate>Mon, 05 Mar 2018 05:28:08 GMT</pubDate>
            <atom:updated>2018-03-05T09:44:41.526Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>แรกๆในทีมเริ่มจากนัดกันเขียน TDD ใน Project ของตัวเองไปแล้วเรียบร้อย หลังจากนั้นก็เริ่มการศึกษา Robot Framework เพื่อเข้าสู่ skill tester ตามมาอีกขั้น เพื่อนำมาปรับใช้กันในทีมต่อไปในวันหน้า</blockquote><p>เริ่มเลยด้วยการลง Brew แล้วไปลง Python ก่อน หลังจากนั้นค่อยลง Robot ด้วย cmd</p><pre>$pip install robotframework</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4EZijE_Kv02M_QgK0tv5w.png" /></figure><p>หลังจากนั้นเราเข้าไปที่ web</p><p><a href="http://robotframework.org/#libraries">Robot Framework</a></p><p>เพื่อเลือกสรรค์ Library ที่ต้องการใช้งานเป็นอันดับแรกเลย ในที่นี้ผมจะเริ่มหัดกับ website ก่อน เลยเลือก SeleniumLibrary</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*flj3beELDua_Xty00S_TaA.png" /></figure><pre>$pip install --upgrade robotframework-seleniumlibrary</pre><p>หลังจากนั้นก็ลง webdriver ใน เครื่อง</p><p>โชคดีที่ใช้ Chrome เป็น Webbrowser พอดี ใช้ Brew หา chromedriver เจอ พร้อมติดตั้ง แต่หา firefoxdriver ไม่เจอ เห็นเขาไปใช้ Marionette อะไรกันเนี่ยแหล่ะ</p><blockquote>ลงเสร็จก็ไปนั่งบื้ออ่าน Document สักแพร้พ… ไม่เคยใช้งาน ฮาๆๆๆ</blockquote><p>ก่อนอื่นก็หาเวปที่จะใช้สำหรับทดสอบกันก่อน เลยเอา code ที่เขียน Go เล่นใน Github ที่ใช้ทดสอบเชื่อม Omise ไว้ มาทดสอบซะเลย โดยทำเป็น Docker ไว้เรียบร้อยแล้ว ต้องขอบคุณ <a href="https://snappytux.com/">snappytux</a> DevOps ที่ Office ที่คอยทำให้เรื่อยๆ</p><p><a href="https://github.com/aofiee/Omise-Go-Example">aofiee/Omise-Go-Example</a></p><blockquote>หาตัวช่วยเพิ่มแพร้พ ด้วยการลง VSCODE Plugin Robot Framework</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TyfiX6Xfsfha5CdhSX3hrA.png" /><figcaption>keith.robotframework</figcaption></figure><p>ทีนี้ก็ลอง build docker จาก git ที่ clone มา</p><pre>docker-compose build<br>docker-compose up -d</pre><blockquote>หลังจากนั้นมาลองเขียน Robot Framework แรกของเรากันเถอะ</blockquote><p>โดยโครงสร้างของ Robot Framework จะประกอบไปด้วย</p><pre>*** Settings ***<br>ส่วนของ Library<br>Library Libraryname</pre><pre>*** Variables ***<br>${LOGIN URL}      http://localhost<br>${BROWSER}        Chrome<br><br>*** Test Cases ***<br>เทส case ต่างๆที่เขียน</pre><pre>*** Keywords ***<br>keyword ต่างๆที่ใช้งาน ดูได้ในนี้<br><a href="http://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Keywords">http://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Keywords</a></pre><p>หลังจากนั้น ทดสอบเขียน File Test สำหรับ Robot เราดังนี้ ตั้งชื่อว่า login_test.robot</p><pre>*** Settings ***</pre><pre>Documentation     Simple example using SeleniumLibrary.</pre><pre>Library           SeleniumLibrary</pre><pre>*** Variables ***</pre><pre>${LOGIN URL}      http://skulltree.com/</pre><pre>${BROWSER}        Chrome</pre><pre>*** Keywords ***</pre><pre>Open Browser To Demo Login Page</pre><pre>Open Browser    ${LOGIN URL}    ${BROWSER}</pre><pre>Title Should Be    Home</pre><pre>Input Username</pre><pre>[Arguments]    ${username}</pre><pre>Input Text    username    ${username}</pre><pre>Input Password</pre><pre>[Arguments]    ${password}</pre><pre>Input Text    password    ${password}</pre><pre>Submit To Login</pre><pre>Click Button    login-submit</pre><pre>Dashboard Should Be Open</pre><pre>Title Should Be    Dashboard</pre><pre>*** Test Cases ***</pre><pre>Authentication Login</pre><pre>Open Browser To Demo Login Page</pre><pre>Input Username    admin</pre><pre>Input Password    password</pre><pre>Submit To Login</pre><pre>Dashboard Should Be Open</pre><pre>[Teardown]    Close Browser</pre><p>เมื่อทดลอง Run ผ่าน cmd จะพบว่า Error เพราะตอนแรกผมไม่ได้ตั้งชื่อ Test Case ลอง run ใหม่</p><blockquote>ไม่รู้นี่หว่าว่าต้องตั้ง ฮาๆๆๆ</blockquote><pre>robot login_test.robot</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bgxB551xTZdaFlmAOE1iLQ.png" /><figcaption>result</figcaption></figure><p>แค่นี้เองหรอ ผ่านแล้วโว้ะ Acceptance Testing ได้ผลลัพธ์มา 3 file มี output.xml, log.html, report.html</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Lpv9-3w7tlMyoy-1rWjQg.png" /><figcaption>log.html</figcaption></figure><p>อีกตัวอย่างหนึ่ง ก็จะเป็นการทดสอบการค้นหาข้อมูลจากเวป Github แบบ Automate ดู ด้วย script robot ดังนี้</p><pre>*** Settings ***</pre><pre>Documentation     This is some basic info about the test</pre><pre>Library           SeleniumLibrary</pre><pre>*** Variables ***</pre><pre>*** Test Cases ***</pre><pre>User Must sign in to check out</pre><pre>[Documentation]     This is some basic info about the test</pre><pre>[Tags]  Github</pre><pre>Open Browser    https://github.com/   Chrome</pre><pre>Wait Until Page Contains    Built for developers</pre><pre>Input Text  name=q  Swift4-CoreML</pre><pre>Press Key    name=q    \\13</pre><pre>Wait Until Page Contains    aofiee/Swift4-CoreML</pre><pre>Click Link    xpath=//a[@href=&quot;/aofiee/Swift4-CoreML&quot;]</pre><pre>Wait Until Page Contains    Khomkrid Lerdprasert</pre><pre>#Sleep   5s</pre><pre>#Close Browser</pre><pre>*** Keyword ***</pre><p>หลังจากนั้นเซฟชื่อ github.robot แล้ว run cmd</p><pre>$ robot -d results github.robot</pre><p>ผลลัพธ์ถือเป็นที่น่าพอใจ</p><p>ว่าแล้วก็ลองเอาไปใช้จริงเลย น่าจะสะดวกกับชีวิตน้องๆในทีมมากขึ้น</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69eb566ac880" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ลองเล่น Machine Learning coreML บน iOS]]></title>
            <link>https://medium.com/@aofiee/%E0%B8%A5%E0%B8%AD%E0%B8%87%E0%B9%80%E0%B8%A5%E0%B9%88%E0%B8%99-machine-learning-coreml-%E0%B8%9A%E0%B8%99-ios-daaa038cafbe?source=rss-d12e6af6df6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/daaa038cafbe</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[coreml]]></category>
            <dc:creator><![CDATA[Snoop Duck]]></dc:creator>
            <pubDate>Sun, 04 Mar 2018 12:43:35 GMT</pubDate>
            <atom:updated>2018-03-04T14:47:55.371Z</atom:updated>
            <content:encoded><![CDATA[<p>วันนี้ว่าวอีก แล้ว หลังจากนั่งกล่อมลูกหลับเลยมีเวลามาลองเล่นอะไรใหม่ๆ ตามที่ตั้งเป้าไว้ในปี 2018 นี้ ว่าจะหัดอะไรใหม่ๆ เดือนละอย่าง สิ้นปีก็จะทำเป็นเพิ่มขึ้นเป็น 12 อย่าง</p><p>วันนี้จะมาลองเล่น Machine Learning coreML บน iOS สักหน่อย</p><p>คลำๆไปนะ</p><p>ก่อนอื่นก็ New Project ก่อนเลย ผมเลือกเป็น Single View เพราะกะแค่ลองแพ้พๆ จบ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VAlC91qUPTFrIEZdlyVVkw.png" /><figcaption>new project from xcode</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6eyfaDw5vsZBNFsDQf28Q.png" /><figcaption>Project Name MLExample</figcaption></figure><p>หลังจากนั้นวาด View ใน Storyboard ก่อนเลย มี UIImageView และ UILabel ตามภาพ โดย UILabel ตั้งชื่อว่า resultLabel ละกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLynEGLDfat_S8hYSHQA1g.png" /><figcaption>Create Layout</figcaption></figure><p>หลังจากนั้นก็หารูปตัวอย่างสักรูปมาทดสอบ ผมเลือก Avril-Lavigne น้องสาวของ Adam Lavigne วง Maroon 5 นั่นเอง ในที่นี้ผมจะตั้งชื่อใน xcode ว่า</p><pre>@IBOutlet weak var imageView: UIImageView!</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LoCMyQzMDyXxN2QHgGySSQ.jpeg" /><figcaption>Avril-Lavigne.jpg</figcaption></figure><p>หลังจากนั้นเราจะย้ายไปทำงานใน ViewController.swift โดยจะ import library มาสองตัวคือ</p><pre>import CoreML</pre><pre>import Vision</pre><p>หลังจากนั้นก็ไปหา model ของ machine learning ที่จะใช้รวมกับ iOS app ของเรา</p><p>โดยจะใช้ Vision ในการวิเคราะห์ภาพของเรา</p><p>Model ที่มีคนทำไว้แล้วผมไปเลือกมาจากที่นี่อ่ะ</p><p><a href="https://coreml.store/">CoreML.Store</a></p><p>โดยเลือกใช้ตัว Model GenderNet จาก <a href="https://coreml.store/gendernet">https://coreml.store/gendernet</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*9vPwy2lzvC1HpG_T9VOkXQ.png" /><figcaption>GenderNet</figcaption></figure><p>หลังจาก Download มาแล้วจะได้ File GenderNet.mlmodel ให้เราลากเข้า Project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ticFdIqTxiX7GIZOua6UHg.png" /><figcaption>GenderNet.mlmodel</figcaption></figure><p>หลังจากนั้นเราก็เขียน ประกาศตัวแปรข้างนอกนู่นก่อนเลย เป็น</p><pre>let model = GenderNet()</pre><p>หลังจากนั้นก็ใช้ VNCoreMLModel Load model เข้ามาก่อน</p><pre>let modelGender = try! VNCoreMLModel(for: model.model)</pre><p>หลังจากนั้นจึงสร้าง VNImageRequestHandler ในที่นี้เราจะใช้ UIImageView เลยต้องแปลงเป็น CGImage ก่อน</p><p><a href="https://developer.apple.com/documentation/vision/vnimagerequesthandler">VNImageRequestHandler - Vision | Apple Developer Documentation</a></p><p>let handlerGender = VNImageRequestHandler(cgImage: (imageView.image?.cgImage)!, options: [:])</p><p>แล้ว options มันให้ใส่ค่าเหี้ยอะไรอ่ะเนี่ย!! WTF! ไม่ใส่แม่งเลย ถถถถถ</p><p>หลังจากนั้นก็เตรียมสร้าง VNCoreMLRequest ส่งไปที่ resultFunc ที่เราเกรียมไว้</p><pre>let requestGender = VNCoreMLRequest(model: modelGender, completionHandler: resultFunc)</pre><p>โดย Code ทั้งหมดก็จะออกมาแบบนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOpsKp-oskcy2NPQElc2VA.png" /></figure><pre>//</pre><pre>//  ViewController.swift</pre><pre>//  MLExample</pre><pre>//</pre><pre>//  Created by SkullTree on 4/3/2561 BE.</pre><pre>//  Copyright © 2561 SkullTree. All rights reserved.</pre><pre>//</pre><pre>import UIKit</pre><pre>import CoreML</pre><pre>import Vision</pre><pre>class ViewController: UIViewController {</pre><pre>@IBOutlet weak var resultLabel: UILabel!</pre><pre>@IBOutlet weak var imageView: UIImageView!</pre><pre>let model = GenderNet()</pre><pre>override func viewDidLoad() {</pre><pre>super.viewDidLoad()</pre><pre>let modelGender = try! VNCoreMLModel(for: model.model)</pre><pre>let handlerGender = VNImageRequestHandler(cgImage: (imageView.image?.cgImage)!, options: [:])</pre><pre>let requestGender = VNCoreMLRequest(model: modelGender, completionHandler: resultFunc)</pre><pre>try! handlerGender.perform([requestGender])</pre><pre>}</pre><pre>func resultFunc(request: VNRequest, errpr: Error?) {</pre><pre>guard let results = request.results as? [VNClassificationObservation] else {</pre><pre>fatalError(&quot;no result&quot;)</pre><pre>}</pre><pre>var bestPrediction = &quot;&quot;</pre><pre>var bestConfidence: VNConfidence = 0</pre><pre>for classification in results {</pre><pre>if(classification.confidence &gt;  bestConfidence) {</pre><pre>bestConfidence = classification.confidence</pre><pre>bestPrediction = classification.identifier</pre><pre>}</pre><pre>}</pre><pre>print(&quot;\(bestPrediction) \(bestConfidence)&quot;)</pre><pre>self.resultLabel.text = bestPrediction</pre><pre>}</pre><pre>override func didReceiveMemoryWarning() {</pre><pre>super.didReceiveMemoryWarning()</pre><pre>// Dispose of any resources that can be recreated.</pre><pre>}</pre><pre>}</pre><p>อันนี้ code ที่ลองเอามาใช้กับกล้องดู โดยจะคำนวน ว่าเพศอะไรจากรูปที่ถ่าย และช่วงอายุเท่าไหร่</p><p>แค่นี้ก่อน ลูกร้องแล้ว</p><p><a href="https://github.com/aofiee/Swift4-CoreML">aofiee/Swift4-CoreML</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*dpNqKx278KWCO6Igd3TplA.png" /><figcaption>Result</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daaa038cafbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เล่น Go Lang วันว่าง ใช้ Download หนังสือการ์ตูน]]></title>
            <link>https://medium.com/@aofiee/%E0%B9%80%E0%B8%A5%E0%B9%88%E0%B8%99-go-lang-%E0%B8%A7%E0%B8%B1%E0%B8%99%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%87-%E0%B9%83%E0%B8%8A%E0%B9%89-download-%E0%B8%AB%E0%B8%99%E0%B8%B1%E0%B8%87%E0%B8%AA%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%8C%E0%B8%95%E0%B8%B9%E0%B8%99-606b9ac3049f?source=rss-d12e6af6df6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/606b9ac3049f</guid>
            <category><![CDATA[go-language]]></category>
            <dc:creator><![CDATA[Snoop Duck]]></dc:creator>
            <pubDate>Sun, 04 Mar 2018 11:48:45 GMT</pubDate>
            <atom:updated>2018-03-04T11:48:45.230Z</atom:updated>
            <content:encoded><![CDATA[<p>เพิ่งจะลองเล่น Go Lang เป็นจริงเป็นจังได้ไม่กี่วัน ประกอบกับวันว่างเสาร์อาทิตย์ นั่งอ่าน โดจินตาม website อยู่ มีความขี้เกียจรอ load เลยเขียน script ง่ายๆ ใช้ ดูด รูปภาพใน url ปลายทาง แล้วเซฟรูปใน tag img src ของ html ที่ response กลับมา</p><p>เว็ปปลายทางที่เราจะโหลดมาเล่น ก็คือเวปนี้ จริงๆมันแค่ script ไว้ดึงรูปจาก website มาไว้ที่ Directory ปลายทางนั่นแหล่ะ จะเขียน PHP เขียน Perl ก็ได้ แต่แค่อยากลอง ภาษา Go เพราะเพิ่งหัดก็แค่นั้นเอง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*rjid26sx8FFKDv4qkm-UUg@2x.jpeg" /></figure><p><a href="http://www.kingsmanga.net/">KingsManga การ์ตูน อ่านการ์ตูน อ่านการ์ตูนออนไลน์ Doujin โดจินแปลไทย ThaiManga</a></p><p>เขียน code ใน file main.go ตามนี</p><pre>package main</pre><pre>import (</pre><pre>&quot;fmt&quot;</pre><pre>&quot;io&quot;</pre><pre>&quot;io/ioutil&quot;</pre><pre>&quot;net/http&quot;</pre><pre>&quot;net/url&quot;</pre><pre>&quot;os&quot;</pre><pre>&quot;path&quot;</pre><pre>&quot;regexp&quot;</pre><pre>&quot;strings&quot;</pre><pre>&quot;github.com/dustin/go-humanize&quot;</pre><pre>&quot;github.com/labstack/gommon/log&quot;</pre><pre>)</pre><pre>var argDownloaderURL string</pre><pre>var argSavePath string</pre><pre>//ImagesStruct structure</pre><pre>type ImagesStruct struct {</pre><pre>imageURL  string</pre><pre>imageName string</pre><pre>}</pre><pre>func main() {</pre><pre>args := os.Args</pre><pre>argumentReciever(args)</pre><pre>}</pre><pre>func argumentReciever(args []string) {</pre><pre>argDownloaderURL = &quot;&quot;</pre><pre>argSavePath = &quot;&quot;</pre><pre>help := `</pre><pre>Images Downloder from URL</pre><pre>Usage:</pre><pre>go run main.go [arguments]</pre><pre>or go build</pre><pre>./main [arguments]</pre><pre>-u  URL of content</pre><pre>-f  path to save</pre><pre>`</pre><pre>fmt.Println(help)</pre><pre>for index, arg := range args {</pre><pre>if arg == &quot;-u&quot; {</pre><pre>argDownloaderURL = args[index+1]</pre><pre>if !isValidURL(argDownloaderURL) {</pre><pre>log.Error(&quot;URL is invalid&quot;)</pre><pre>os.Exit(1)</pre><pre>}</pre><pre>}</pre><pre>if arg == &quot;-f&quot; {</pre><pre>argSavePath = args[index+1]</pre><pre>}</pre><pre>}</pre><pre>if argDownloaderURL != &quot;&quot; &amp;&amp; argSavePath != &quot;&quot; {</pre><pre>if _, err := os.Stat(argSavePath); err != nil {</pre><pre>extractImagesFromURL(argDownloaderURL, argSavePath)</pre><pre>} else {</pre><pre>log.Error(&quot;Found folder&quot;)</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>func extractImagesFromURL(URL string, dirName string) {</pre><pre>os.Mkdir(dirName, 0777)</pre><pre>result := getURLContent(URL)</pre><pre>imgTags := getImagesURL(result)</pre><pre>for _, item := range imgTags {</pre><pre>dirSavePath := dirName + &quot;/&quot; + item.imageName</pre><pre>goDownload(dirSavePath, item.imageURL)</pre><pre>}</pre><pre>}</pre><pre>func goDownload(filename string, URL string) {</pre><pre>err := DownloadFile(filename, URL)</pre><pre>if err != nil {</pre><pre>log.Error(err)</pre><pre>}</pre><pre>}</pre><pre>func getURLContent(URL string) (convertToString string) {</pre><pre>res, err := http.Get(URL)</pre><pre>if err != nil {</pre><pre>fmt.Println(&quot;Error: &quot;, err)</pre><pre>os.Exit(1)</pre><pre>}</pre><pre>contents, err := ioutil.ReadAll(res.Body)</pre><pre>convertToString = string(contents)</pre><pre>return</pre><pre>}</pre><pre>func getImagesURL(html string) []ImagesStruct {</pre><pre>var imgRex = regexp.MustCompile(`&lt;img[^&gt;]+\bsrc=[&quot;&#39;]([^&quot;&#39;]+)[&quot;&#39;]`)</pre><pre>imgTags := imgRex.FindAllStringSubmatch(html, -1)</pre><pre>output := make([]ImagesStruct, len(imgTags))</pre><pre>for index := range output {</pre><pre>output[index].imageURL = imgTags[index][1]</pre><pre>output[index].imageName = path.Base(output[index].imageURL)</pre><pre>}</pre><pre>return output</pre><pre>}</pre><pre>//WriteCounter struct</pre><pre>type WriteCounter struct {</pre><pre>Total uint64</pre><pre>}</pre><pre>func (wc *WriteCounter) Write(p []byte) (int, error) {</pre><pre>n := len(p)</pre><pre>wc.Total += uint64(n)</pre><pre>wc.PrintProgress()</pre><pre>return n, nil</pre><pre>}</pre><pre>//PrintProgress func</pre><pre>func (wc WriteCounter) PrintProgress() {</pre><pre>fmt.Printf(&quot;\r%s&quot;, strings.Repeat(&quot; &quot;, 35))</pre><pre>fmt.Printf(&quot;\rDownloading... %s complete&quot;, humanize.Bytes(wc.Total))</pre><pre>}</pre><pre>//DownloadFile func</pre><pre>func DownloadFile(filepath string, url string) error {</pre><pre>out, err := os.Create(filepath + &quot;.tmp&quot;)</pre><pre>if err != nil {</pre><pre>return err</pre><pre>}</pre><pre>defer out.Close()</pre><pre>resp, err := http.Get(url)</pre><pre>if err != nil {</pre><pre>return err</pre><pre>}</pre><pre>defer resp.Body.Close()</pre><pre>counter := &amp;WriteCounter{}</pre><pre>_, err = io.Copy(out, io.TeeReader(resp.Body, counter))</pre><pre>if err != nil {</pre><pre>return err</pre><pre>}</pre><pre>fmt.Print(&quot;\n&quot;)</pre><pre>err = os.Rename(filepath+&quot;.tmp&quot;, filepath)</pre><pre>if err != nil {</pre><pre>return err</pre><pre>}</pre><pre>return nil</pre><pre>}</pre><pre>//isValidURL check</pre><pre>func isValidURL(toTest string) bool {</pre><pre>_, err := url.ParseRequestURI(toTest)</pre><pre>if err != nil {</pre><pre>return false</pre><pre>}</pre><pre>return true</pre><pre>}</pre><p>เมื่อ save file แล้วทดลอง run คำสั่ง</p><pre>$ go run main.go</pre><p>จะได้ผลลัพธ์ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IC_1b0kTUx_xGd-P9rLk_g.png" /><figcaption>$ go run main.go</figcaption></figure><p>ในทีนี้เราจะลองโหลด จากเรื่อง</p><p><a href="http://www.kingsmanga.net/gal-gohan-16/">Gal Gohan 16</a></p><p>เมื่อลอง run command ตามข้างล่าง จะได้ผลตามนี้</p><pre>go run main.go -u http://www.kingsmanga.net/gal-gohan-16/ -f gal_gohan_16</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K3-ROHt0u7scvvCAzv9OWw.png" /><figcaption>result</figcaption></figure><p>จาก code ข้างต้นยังไม่ได้เขียนให้รองรับ <strong>img src</strong> ที่เป็น <strong>Relative Path </strong>เนื่องจากเวปตัวอย่าง เป็น <strong>Absolute Path </strong>อยู่แล้ว</p><p>code อยู่นี่</p><p><a href="https://github.com/aofiee/bigGaboo">https://github.com/aofiee/bigGaboo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=606b9ac3049f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Line Message API]]></title>
            <link>https://medium.com/@aofiee/line-message-api-f10f6f13b95e?source=rss-d12e6af6df6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f10f6f13b95e</guid>
            <dc:creator><![CDATA[Snoop Duck]]></dc:creator>
            <pubDate>Sat, 22 Oct 2016 10:48:12 GMT</pubDate>
            <atom:updated>2016-10-22T10:55:57.873Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wv7GMWbYPuD-JOHIdr-ZkA.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQ3wl7_OzyDw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQ3wl7_OzyDw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQ3wl7_OzyDw%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b0126226a7667623fd142b9814b8d82/href">https://medium.com/media/2b0126226a7667623fd142b9814b8d82/href</a></iframe><p>ไปสมัคร Line Developer ก่อนเลย</p><p><a href="https://business.line.me/">LINE Business Center</a></p><p>หลังจากสมัครแล้ว เราก็มาเริ่มเขียน BOT ง่ายๆกัน</p><p>โดยเริ่มแรก ไปทำการ Regis IP address เพื่อทำ White List ใน Line Developer ก่อนเลย หลังจากนั้นเราก็มาเริ่มเขียน PHP กัน ขอไม่ capture รูป ขี้เกียจนะ</p><p>$post = file_get_contents(‘php://input’);<br>$urlReply = ‘<a href="https://api.line.me/v2/bot/message/reply%27">https://api.line.me/v2/bot/message/reply&#39;</a>;<br>$token = ‘อันนี้ของใครของมัน’;</p><p>เสร็จแล้วก็มาเขียน Function ไว้สำหรับ post data ไปยัง Line Message API กัน</p><p>function postMessage($token,$packet,$urlReply){<br> $dataEncode = json_encode($packet);<br> $headersOption = array(‘Content-Type: application/json’,’Authorization: Bearer ‘.$token);<br> $ch = curl_init($urlReply);<br> curl_setopt($ch,CURLOPT_CUSTOMREQUEST,’POST’);<br> curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);<br> curl_setopt($ch,CURLOPT_POSTFIELDS,$dataEncode);<br> curl_setopt($ch,CURLOPT_HTTPHEADER,$headersOption);<br> curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);<br> $result = curl_exec($ch);<br> curl_close($ch);<br>}</p><p>หลังจากนั้นก็มาเขียนส่วนที่รอรับข้อความจาก ผู้ใช้งานในระหว่างที่พิมพ์คุยกับ BOT กันครับ โครงสร้างของ JSON ที่ผู้ใช้งานพิมพ์ส่งไปยัง Line จะเป็นประมาณนี้</p><p>{“events”:[{“type”:”message”,”replyToken”:”ไม่บอก”,”source”:{“userId”:”ไม่บอก”,”type”:”user”},”timestamp”:1477132643802,”message”:{“type”:”text”,”id”:”5094630491076&quot;,”text”:”ว่าไงท่าน”}}]}</p><p>ดังนั้นเราก็ต้องแปลง JSON แล้วทำการตรวจว่ามันเป็น event ประเภทอะไร มี type เป็นอะไร location, text, sticker, video, audio หรือ image เราจะได้แยกการทำงานให้ BOT เราถูกว่าจะให้ Response อะไรกลับไปบ้าง</p><p>$res = json_decode($post, true);<br>if(isset($res[‘events’]) &amp;&amp; !is_null($res[‘events’])){<br> foreach($res[‘events’] as $item){<br> if($item[‘type’] == ‘message’){<br> switch($item[‘message’][‘type’]){<br> case ‘text’:</p><p>break;<br>case ‘image’:</p><p>break;<br> case ‘video’:<br> <br> break;<br> case ‘audio’:<br> <br> break;<br> case ‘location’:</p><p>break;<br> case ‘sticker’:<br><br> break;</p><p>}</p><p>เรามาลองส่ง sticker กลับไปหาผู้ใช้งานกัน</p><p>ดู sticker list ได้ที่นี่ <a href="https://devdocs.line.me/en/files/sticker_list.pdf">https://devdocs.line.me/en/files/sticker_list.pdf</a></p><p>ลองเขียน function สร้าง json จาก array เพื่อส่ง sticker กลับดูแบบง่ายๆ</p><p>function getSticker($replyToken){<br> $sticker = array(<br> ‘type’ =&gt; ‘sticker’,<br> ‘packageId’ =&gt; ‘4’,<br> ‘stickerId’ =&gt; ‘300’<br> );<br> $packet = array(<br> ‘replyToken’ =&gt; $replyToken,<br> ‘messages’ =&gt; array($sticker),<br> );<br> return $packet;<br>}</p><p>แล้วก็ลองนำไปเรียกใช้งานดูเช่น</p><p>$packet = getSticker($item[‘replyToken’]);<br> postMessage($token,$packet,$urlReply);</p><p>เอกสาร API ก็ค่อนข้างครบ สรุปลองเล่นดูแล้ว ประยุตก์ใช้ได้อีกหลายเลย เช่นกด share location จาก user แล้วส่งมายัง server เพื่อค้นหาสนามฟุตบอลที่อยู่ใกล้ๆ แล้วลิสออกมาบน Line ในรูปแบบ Carousel นำไปทำ action อื่นๆได้อีก สรุปว่าดีเอาไปเลยสิบกระโหลก</p><p>ในอนาคตจะเสียเงินค่าบริการหรือเปล่า อันนี้ไม่รู้นะ อ่านภาษาอังกฤษไม่ออกด้วย</p><p>ใครอยากเล่นต่อก็ไปอ่านเอกสาร api ได้ที่นี่<a href="https://devdocs.line.me/en/?shell#messaging-api">https://devdocs.line.me/en/?shell#messaging-api</a></p><p>สามารถแอดมาลองเล่นได้ที่นี่เลย @xkc6901a</p><p>หรือ ​scan qr ตามเน้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*Ox2rxW6VDM3hVgVjY3w77g.png" /></figure><p>วิธีเล่นก็ลองพิมพ์ว่า /help ดูครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f10f6f13b95e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[notify-bot.line.me ใช้ Line รับ Order งาน]]></title>
            <link>https://medium.com/@aofiee/notify-bot-line-me-%E0%B9%83%E0%B8%8A%E0%B9%89-line-%E0%B8%A3%E0%B8%B1%E0%B8%9A-order-%E0%B8%87%E0%B8%B2%E0%B8%99-afe56f898fc?source=rss-d12e6af6df6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe56f898fc</guid>
            <dc:creator><![CDATA[Snoop Duck]]></dc:creator>
            <pubDate>Thu, 20 Oct 2016 03:19:44 GMT</pubDate>
            <atom:updated>2016-10-20T03:19:44.441Z</atom:updated>
            <content:encoded><![CDATA[<p>ไป Add Friend มันก่อนเลย ที่นี่</p><p><a href="https://notify-bot.line.me/en/">https://notify-bot.line.me/en/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FVMps4EZIUbB_XY3x7y9dg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*902EPQXbRT4XffJme3F1qw.png" /></figure><p>แล้วก็ login ไป generate token ที่จะใช้งาน จะใช้ notify กับ group หรือ ส่วนตัวก็ได้โดยช่องแรกอ่ะ เป็นชื่อเรียก token ของเรา เวลามี auto response message กลับไปหา ผมตั้งชื่อว่า Aofiee และให้ส่ง message แบบ 1-on-1 เพื่อทดสอบหลังจากนั้นจะส่งไปยัง group ก็ได้ (แต่ต้องทำการสร้าง token ใหม่และกำหนด group )แค่ทำการ invite line notify account เข้า group ที่เราต้องการให้มี auto message</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wFZIdUZqwBlyvaoLvuPfmg.png" /></figure><p>หลังจาก กด generate token มาจะได้ dialog ตามรูป เอากระดาษจดไว้นะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l4WZ2XDg9-ff1G4gkF9c6g.png" /></figure><p>หลังจากนั้นเปิด terminal ขึ้นมาทดสวบพิมพ์คำสั่งแว่</p><p>curl -X POST -H ‘Authorization: Bearer Toeken’ -F “message=สวัสดีวันพระ แฮร่” <a href="https://notify-api.line.me/api/notify">https://notify-api.line.me/api/notify</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRjjVGaMhr79j4lBtaRtpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*hQX28K5DowTnCyxc_-pmQQ.png" /></figure><p>ที้นี้ก็ลองเขียน PHP แบบง่อยๆไปเรียกเลย</p><pre>define(&#39;LINE_API&#39;,&quot;https://notify-api.line.me/api/notify&quot;);<br>define(&#39;LINE_TOKEN&#39;,&#39;ไม่บอก&#39;);<br><br>function notify_message($message){<br><br>    $queryData = array(&#39;message&#39; =&gt; $message);<br>    $queryData = http_build_query($queryData,&#39;&#39;,&#39;&amp;&#39;);<br>    $headerOptions = array(<br>        &#39;http&#39;=&gt;array(<br>            &#39;method&#39;=&gt;&#39;POST&#39;,<br>            &#39;header&#39;=&gt; &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;<br>            		  .&quot;Authorization: Bearer &quot;.LINE_TOKEN.&quot;\r\n&quot;<br>                      .&quot;Content-Length: &quot;.strlen($queryData).&quot;\r\n&quot;,<br>            &#39;content&#39; =&gt; $queryData<br>        )<br>    );<br>    $context = stream_context_create($headerOptions);<br>    $result = file_get_contents(LINE_API,FALSE,$context);<br>    $res = json_decode($result);<br>	return $res;<br>}<br>$res = notify_message(&#39;hello&#39;);<br>var_dump($res);</pre><p>ถ้าได้ response 200 ก๊ะโอ</p><pre>object(stdClass)#1 (2) {<br>  [&quot;status&quot;]=&gt;<br>  int(200)<br>  [&quot;message&quot;]=&gt;<br>  string(2) &quot;ok&quot;<br>}</pre><p>หลังจากนั้นจะเอาไปเชื่อม service อะไรก็แล้วแต่เลย</p><p>ของผมเองเอาไปประยุกต์ใช้เวลามี User จองสนามเข้ามาจะมีการแจ้งเตือนเข้าใน Line group ของ ทีม Marketting อีกช่องทางหนึ่งนอกเหนือจาก notification ในระบบ backend และ email ต่างๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*-sv0VopJdFPGMCEQu4Xu1A.png" /></figure><p>สมัคร medium ไว้นานโคตร ไม่เคยใช้ เห็นน้องในออฟฟิศใช้ ก็เอาบ้างยอมกันที่ไหนล่ะ ^_^</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe56f898fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>