On top of other good comments mentioning diplomacy and acting as a buffer state, Thai/Siamese rulers smartly “westernized” their rule, for example by abolishing slavery, centralizing their governance and “mapping” their country with clear claims as to what was considered Siam/Thailand proper, adopting Western clothes…
These snuffed out a lot of the usual justifications that existed for colonization (barbarians needing civilization, land being up for grab because of unclear sovereignty…), and made it harder for imperialists to justify outright conquering. Sure, none of these was a hard stop to colonization, but they were real hindrances that combined with other factors to prevent Thailand from being fully colonized.
Latest Answers