ART's Random Thoughts
BlogAbout
Blog
About
NongHed
2020.09.20 · 4-min read ·  · Tags: economics, finance, data, project

NongHed is a chatbot who could provide you with up-to-date economic and financial data for Thailand. See NongHed's homepage here.

น้องเห็ด (NongHed) เป็นแชทบอทน่ารัก ๆ ที่จะมาช่วยคุณค้นหาข้อมูลเศรษฐกิจและการเงินของประเทศไทย ลองดูหน้าเว็บเพจของน้องเห็ดได้เลย

Backgroundความเดิม

When I started my job at the Bank of Thailand, one of the first things I noticed is how data-oriented the organization is. Questions like, "What was last month's export growth?" or "What was the current account last year?" consistently pop up.

While most people could recall these numbers off the top of their head (or at least have some rough numbers), newcomers often find it hard to recall these numbers and would have to flip through their giant folders to look up the numbers. The same goes for "infrequently asked numbers" that even veterans sometimes find troublesome.

ตอนเริ่มงานที่แบงก์ชาติใหม่ ๆ สิ่งแรก ๆ ที่สังเกตได้คือในการประชุมต่าง ๆ พี่ ๆ ทุกคนเน้นข้อมูลมากกก ได้เจอคำถามต่าง ๆ เช่น ส่งออกเดือนที่แล้วโตเท่าไหร่ หรือ current account ปีที่แล้วเท่าไหร่ อยู่ตลอดเวลา

คนส่วนใหญ่ที่ทำงานมาซักพักนึงดูเหมือนจะมีญาณหยั่งรู้เลขเหล่านี้ได้ (และ update ได้เรื่อย ๆ อีกแน่ะ) หรืออย่างน้อยก็รู้เลขคร่าว ๆ แต่น้อง ๆ ที่เพิ่งเข้ามาทำงานใหม่จะค่อนข้างมึนมาก พอต้องใช้เลขก็ต้องไล่เปิดแฟ้มหนา ๆ เพื่อหาข้อมูล แม้แต่พี่ ๆ ที่มีประสบการณ์มากแล้ว ถ้าถูกถามข้อมูลที่อาจจะไม่ค่อยคุ้นเคย ก็ต้องนั่งเปิดแฟ้มบ้างเหมือนกัน

Existing solution(s)วิธีแก้ปัญหาที่มีอยู่แล้ว

BOT Statisticsเว็บสถิติของแบงก์ชาติ

Indeed, the Bank of Thailand has a ginormous statistics portal with tens of thousands of series covering everything from total loans in the banking system to quantity of pineapples exported each month. So theoretically anybody could look up the numbers from there.

The problem? The statistics portal is ginormous. Unless you know exactly which table number to look at, you'll likely find yourself poking around different tables and end up unsure which one is the series you want.

แบงก์ชาติมีหน้าเว็บที่รวบรวมสถิติต่าง ๆ ที่รวบรวมข้อมูลทั้งหมดที่แบงก์ชาติเผยแพร่เป็นหมื่น ๆ รายการ ตั้งแต่ปริมาณสินเชื่อทั้งหมดในระบบธนาคารไปจนถึงปริมาณการส่งออกสับปะรดในแต่ละเดือน ดังนั้นเว็บนี้ก็เป็นที่ที่นึงที่จะหาข้อมูลที่ต้องการได้เกือบทั้งหมด

แล้วปัญหาคืออะไร ทำไมคนไม่ใช้กันล่ะ? ปัญหาก็คือหน้าเว็บนี้รวบรวมข้อมูลทั้งหมดเป็นหมื่น ๆ รายการนั่นเอง เวลาจะหาข้อมูลอะไร ถ้าไม่รู้ว่าต้องไปดูตารางเลขที่เท่าไหร่แต่แรก ก็อาจจะต้องใช้เวลาพอสมควรกว่าจะหาข้อมูลที่ต้องการเจอ ยิ่งไปกว่านั้น บางทีข้อมูลอาจจะดูคล้าย ๆ กัน ก็ไม่แน่ใจอีกว่าอันไหนคืออันที่เราต้องการจริง ๆ

Friendsเพื่อนสนิทมิตรสหาย

Next up are friends. You use your favorite instant messaging means (LINE, Facebook Messenger, etc.) and ask your veteran friends or people in the respective teams to help you look it up. Of course, the problem with this approach is that your friend might not always be there for you.

ขั้นต่อไปก็ต้องพึ่งพาเพื่อนแล้ว วิธีทำก็แค่หยิบโทรศัพท์มือถือขึ้นมา เปิดแอพส่งข้อความที่ชื่นชอบ ไม่ว่าจะเป็น LINE หรือ Facebook Messenger แล้วก็ส่งข้อความไปหาเพื่อน ๆ พี่ ๆ ที่อาจจะอยู่ในทีมที่เกี่ยวข้องกับข้อมูลนั้น ให้ช่วยหาให้หน่อยเถอะน้าาา วิธีนี้เป็นวิธีที่ใช้กันค่อนข้างเยอะ แต่ปัญหาของวิธีนี้ ก็คือเพื่อนอาจจะไม่อยู่ตอบให้ได้ตลอดเวลานั่นเอง

Comes along NongHedแล้วน้องเห็ดก็เข้ามา

NongHed was meant to be that friend who would always be there for you (to provide Help with Economic Data, of course). The idea is that the user could simply ask the chatbot with these questions you'd normally ask your friends, and NongHed will answer them for you, 24/7.

NongHed is available on both LINE and Facebook, and you can start chatting with him (her?) right away.

น้องเห็ดจะเป็นเพื่อนคนนั้นให้คุณเอง! มีน้องเห็ด ก็เหมือนมีเพื่อนอยู่คุยด้วยตลอด 24 ชั่วโมง (เรื่องข้อมูลเศรษฐกิจการเงินนะ) ถ้าอยากรู้ข้อมูลอะไร แทนที่จะถามเพื่อน ๆ พี่ ๆ ก็มาถามน้องเห็ดแทน ผ่านทาง LINE หรือ Facebook ก็ได้ แล้วแต่สะดวกเลย

Architectureรูปแบบการทำงาน

When you chat with NongHed, your request goes through respective platform's messaging API, which then forward your requests to Google's Dialogflow. From there, simpler requests like "Hi" or "What's your name" are handled directly by Dialogflow, while data-related requests are forwarded to an API hosted on Heroku.

This backend is written in Python and handles everything from updating data to parsing dates (Dialogflow doesn't do a particularly good job of handling quarterly dates) to doing requested calculations.

เมื่อมีคนคุยกับน้องเห็ด บทสนทนาก็จะถูกส่งผ่าน messaging API ของ platform นั้น ๆ ไปยังบริการ Dialogflow ของ Google จากจุดนั้น คำสนทนาแบบง่าย ๆ เช่น "Hi" หรือ "What's your name" จะถูกจัดการด้วย Dialogflow โดยตรง ขณะที่คำสนทนาที่ถามถึงข้อมูลจะถูกส่งต่อไปยัง API ที่อยู่บน Heroku

API บน Heroku นี้ใช้ Python เขียนขึ้นมา และทำหน้าที่ทุกอย่างตั้งแต่การ update ข้อมูลไปจนถึงการแปลงวันที่ (Dialogflow ทำได้บางส่วน แต่ยังจัดการกับวันที่แบบไตรมาสไม่เป็น) ไปจนถึงการทำการคำนวณแบบง่าย ๆ

Dataข้อมูล

The data NongHed has comes from several sources.

ข้อมูลที่น้องเห็ดใช้ถูกรวมขึ้นมาจากหลาย ๆ ที่

Bank of Thailand's APIAPI ของแบงก์ชาติ

The Bank of Thailand has made its statistics (yes, those tables) available through BOT API since 2017. This is a huge step forward in making public data accessible, and I sincerely thank the people who have made this possible.

BOT API itself is easy enough to use, but is intended for power users (read: people who can code.) So one can think of NongHed as a user-friendly frontend for BOT API.

Making more than 20,000 series in BOT API available to NongHed users could make things as confusing for users, so I chose only series that are queried frequently (currently there are around 40 series). Adding more series from BOT API is as simple as adding a row in a .csv file.

For faster results, data from BOT API are pulled automatically every day into a local copy.

ตั้งแต่ปี 2560 แบงก์ชาติได้จัดทำ BOT API ขึ้นมาสำหรับให้บริการข้อมูลต่าง ๆ ที่อยู่ในตารางสถิติ ทำให้ผู้ใช้งานสามารถเข้าถึงข้อมูลได้ง่ายขึ้นมาก และเป็นก้าวสำคัญในการเปิดเผยข้อมูลของภาครัฐ

BOT API จริง ๆ แล้วใช้งานค่อนข้างง่าย แต่ผู้ใช้อาจจะต้องมีพื้นฐานด้านการเขียนโปรแกรมอยู่ น้องเห็ดเลยเป็นเหมือน frontend ที่ใช้งานง่ายสำหรับ BOT API

ถ้าจะหยิบทั้งสองหมื่นกว่า series มาให้กับผู้ใช่้งานน้องเห็ดเลย ก็อาจจะทำให้น้องเห็ดใช้งานยากพอ ๆ กับเว็บสถิติของแบงก์ชาติ ตอนนี้ก็เลยหยิบมาแค่ 40 กว่า series ที่รู้สึกว่าถูกเรียกใช้งานบ่อย ๆ ถ้าจะเพิ่ม series เข้าไป ก็ทำได้ง่าย ๆ แค่เพิ่มแถวเข้าไปในไฟล์ .csv เท่านั้น

เพื่อให้ผู้ใช้งานเข้าถึงข้อมูลได้รวดเร็วขึ้น และเนื่องจากข้อมูลใน BOT API ไม่ได้เป็นข้อมูลสดขนาดนาทีต่อนาที ข้อมูลจาก BOT API เลยถูกดึงเข้ามาทุก ๆ คืนมาอยู่ใน local copy

Other government agenciesหน่วยงานรัฐอื่น ๆ

Huge as it is, BOT API only contains data compiled by the Bank of Thailand. Important economic series like GDP (compiled by NESDC) or inflation (compiled by MOC) are not included in the BOT API. As a result, these data have to be pulled separately via available means.

แม้ว่าข้อมูลใน BOT API จะมีเยอะมาก แต่ BOT API ก็รวมข้อมูลที่ถูกเผยแพร่โดยแบงก์ชาติเท่านั้น ข้อมูลเศรษฐกิจสำคัญอื่น ๆ เช่น GDP (จัดทำโดยสภาพัฒน์ฯ) หรืออัตราเงินเฟ้อ (จัดทำโดยกระทรวงพาณิชย์) ไม่ถูกรวมอยู่ด้วย ข้อมูลเหล่านี้เลยถูกเพิ่มเข้ามาด้วยวิธีต่าง ๆ กัน แล้วแต่ที่มาของข้อมูล

Other sourcesแหล่งข้อมูลอื่น ๆ

Other—mostly live—data are scraped through many sources. and I guess we'll have to be sneaky-sneaky about that ;)

ข้อมูลอื่น ๆ (ส่วนใหญ่เป็นข้อมูลรายนาที) ถูก scrape มาจากแหล่งข้อมูลต่าง ๆ ที่อาจจะเปิดเผยไม่ได้ ;)

Looking forwardแผนในอนาคต

I hope to add more useful features for NongHed in the future. Suggestions are more than welcome! If you have any suggestions or questions, please send them to nonghed.bot@gmail.com.

All of the cloud services I use for this project (LINE Official Account, Facebook Messenger, Dialogflow, Heroku) are on a free tier. This means there are certain limitations like number of messages that NongHed can handle in an hour, or an uptime that might not be guaranteed. If you find NongHed helpful and would like to support continued development, please feel free to support NongHed!

Sorry for a long post. Here's a potato! 🥔

ถ้าใครมีคำแนะนำหรือไอเดียเจ๋ง ๆ สำหรับพัฒนาน้องเห็ด สามารถส่งมาได้เลยที่ nonghed.bot@gmail.com

ณ​ ขณะนี้ บริการ cloud ทั้งหลายที่ใช้อยู่ ไม่ว่าจะเป็น Line Official Account, Facebook Messenger, Dialogflow หรือ Heroku เป็นการใช้บริการแบบฟรีทั้งนั้น ซึ่งก็แปลว่าบางทีอาจจะมีข้อจำกัดในการใช้งานน้องเห็ดอยู่บ้าง เช่น จำนวนข้อความที่สามารถตอบกลับได้ในหนึ่งชั่วโมง หรือ server อาจจะล่มได้บ้าง ถ้าลองใช้น้องเห็ดแล้วคิดว่า เออ มีประโยชน์ดี อยากช่วยทำให้น้องเห็ดเก่งขึ้น สามารถ support น้องเห็ด ได้นะครับ

Fun fact

September 20 is Global Magic Mushroom Day!

วันที่ 20 กันยายน เป็นวันเห็ดวิเศษสากล!

‹ previous
GDP Growth นั้นโคตรงง
next ›
ล่ารายชื่อด้วย Google Forms
NongHed
Backgroundความเดิม
Existing solution(s)วิธีแก้ปัญหาที่มีอยู่แล้ว
Comes along NongHedแล้วน้องเห็ดก็เข้ามา
Architectureรูปแบบการทำงาน
Dataข้อมูล
Looking forwardแผนในอนาคต

ART's Random Thoughts

Powered by Gatsby
Copyright © 2022 by Art Tosborvorn. All rights reserved.